<local:MessagePageBase
    x:Class="Bili.App.Pages.Desktop.Overlay.MessagePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:app="using:Bili.App.Controls.App"
    xmlns:behaviors="using:Bili.App.Behaviors"
    xmlns:community="using:Bili.App.Controls.Community"
    xmlns:communityInterface="using:Bili.ViewModels.Interfaces.Community"
    xmlns:controls="using:Bili.App.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:local="using:Bili.App.Pages.Desktop.Overlay"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    mc:Ignorable="d">

    <interactivity:Interaction.Behaviors>
        <behaviors:InitializeBehavior />
    </interactivity:Interaction.Behaviors>

    <Grid RowSpacing="8">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="LayoutGroup">
                <VisualState x:Name="WideState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource MediumWindowThresholdWidth}" />
                    </VisualState.StateTriggers>
                </VisualState>
                <VisualState x:Name="NarrowState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="RepeaterView.ItemOrientation" Value="Horizontal" />
                        <Setter Target="RepeaterView.IsStaggered" Value="False" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <app:PageHeader Title="{loc:Locale Name=Message}" RefreshCommand="{x:Bind ViewModel.ReloadCommand}" />

        <muxc:NavigationView
            x:Name="Nav"
            Style="{StaticResource TopNavigationViewStyle}"
            Grid.Row="1"
            Margin="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            ItemInvoked="OnNavItemInvokedAsync"
            MenuItemsSource="{x:Bind ViewModel.MessageTypes}"
            SelectedItem="{x:Bind ViewModel.CurrentType, Mode=OneWay}">
            <muxc:NavigationView.MenuItemTemplate>
                <DataTemplate x:DataType="communityInterface:IMessageHeaderViewModel">
                    <muxc:NavigationViewItem Content="{x:Bind}">
                        <muxc:NavigationViewItem.ContentTemplate>
                            <DataTemplate x:DataType="communityInterface:IMessageHeaderViewModel">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{x:Bind Title, Mode=OneWay}" />
                                    <TextBlock
                                        Style="{StaticResource CaptionTextBlockStyle}"
                                        Margin="4,0,0,0"
                                        VerticalAlignment="Center"
                                        FontSize="10"
                                        Foreground="{ThemeResource AccentTextFillColorSecondaryBrush}"
                                        Text="{x:Bind Count, Mode=OneWay}"
                                        Visibility="{x:Bind IsShowBadge, Mode=OneWay}" />
                                </StackPanel>
                            </DataTemplate>
                        </muxc:NavigationViewItem.ContentTemplate>
                    </muxc:NavigationViewItem>
                </DataTemplate>
            </muxc:NavigationView.MenuItemTemplate>
        </muxc:NavigationView>

        <ScrollViewer
            x:Name="ContentScrollViewer"
            Grid.Row="2"
            Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <controls:VerticalRepeaterView
                x:Name="RepeaterView"
                Margin="0,0,0,12"
                HeaderVisibility="Collapsed"
                IsStaggered="True"
                ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                MinWideItemHeight="120"
                MinWideItemWidth="260">
                <interactivity:Interaction.Behaviors>
                    <behaviors:IncrementalBehavior />
                </interactivity:Interaction.Behaviors>
                <controls:VerticalRepeaterView.ItemTemplate>
                    <DataTemplate x:DataType="communityInterface:IMessageItemViewModel">
                        <community:MessageItem ViewModel="{x:Bind}" />
                    </DataTemplate>
                </controls:VerticalRepeaterView.ItemTemplate>
            </controls:VerticalRepeaterView>
        </ScrollViewer>

        <controls:OverlayLoadingPanel
            Grid.Row="2"
            IsBarActive="{x:Bind ViewModel.IsIncrementalLoading, Mode=OneWay}"
            IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />

        <controls:ErrorPanel
            Grid.Row="2"
            ActionContent="{loc:Locale Name=Refresh}"
            Text="{x:Bind ViewModel.ErrorText, Mode=OneWay}"
            Visibility="{x:Bind ViewModel.IsError, Mode=OneWay}">
            <interactivity:Interaction.Behaviors>
                <behaviors:ReloadBehavior />
            </interactivity:Interaction.Behaviors>
        </controls:ErrorPanel>

        <controls:ErrorPanel
            Grid.Row="2"
            Text="{loc:Locale Name=NoSpecificData}"
            Visibility="{x:Bind ViewModel.IsEmpty, Mode=OneWay}" />
    </Grid>
</local:MessagePageBase>
