<base:RankPageBase
    x:Class="Bili.App.Pages.Desktop.RankPage"
    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:base="using:Bili.App.Pages.Base"
    xmlns:behaviors="using:Bili.App.Behaviors"
    xmlns:community="using:Bili.Models.Data.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    xmlns:video="using:Bili.ViewModels.Interfaces.Video"
    xmlns:videos="using:Bili.App.Controls.Videos"
    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="Common">
                <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="VideoView.ItemOrientation" Value="Horizontal" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <app:PageHeader Title="{loc:Locale Name=Rank}" RefreshCommand="{x:Bind ViewModel.ReloadCommand}" />
        <muxc:NavigationView
            x:Name="RankNavigationView"
            Style="{StaticResource TopNavigationViewStyle}"
            Grid.Row="1"
            Margin="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            ItemInvoked="OnDetailNavigationViewItemInvoked"
            MenuItemsSource="{x:Bind ViewModel.Partitions}"
            SelectedItem="{x:Bind ViewModel.CurrentPartition, Mode=OneWay}">
            <muxc:NavigationView.MenuItemTemplate>
                <DataTemplate x:DataType="community:Partition">
                    <muxc:NavigationViewItem Content="{x:Bind}">
                        <muxc:NavigationViewItem.ContentTemplate>
                            <DataTemplate x:DataType="community:Partition">
                                <StackPanel Orientation="Horizontal" Spacing="8">
                                    <Image
                                        Width="20"
                                        Height="20"
                                        VerticalAlignment="Center"
                                        Source="{x:Bind Image.Uri}" />
                                    <TextBlock
                                        Style="{StaticResource BodyTextBlockStyle}"
                                        VerticalAlignment="Center"
                                        Text="{x:Bind Name}" />
                                </StackPanel>
                            </DataTemplate>
                        </muxc:NavigationViewItem.ContentTemplate>
                    </muxc:NavigationViewItem>
                </DataTemplate>
            </muxc:NavigationView.MenuItemTemplate>
        </muxc:NavigationView>

        <ScrollViewer
            x:Name="ContentScrollViewer"
            Grid.Row="2"
            Margin="0,-4,0,0"
            Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.IsError, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <controls:VerticalRepeaterView
                x:Name="VideoView"
                Margin="0,0,0,12"
                HeaderVisibility="Collapsed"
                ItemsSource="{x:Bind ViewModel.Videos}"
                MinWideItemHeight="252"
                Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <controls:VerticalRepeaterView.ItemTemplate>
                    <DataTemplate x:DataType="video:IVideoItemViewModel">
                        <videos:VideoItem ViewModel="{x:Bind}" />
                    </DataTemplate>
                </controls:VerticalRepeaterView.ItemTemplate>
            </controls:VerticalRepeaterView>
        </ScrollViewer>

        <controls:ErrorPanel
            x:Name="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>

        <muxc:ProgressRing
            x:Name="InitializeRing"
            Style="{StaticResource PageProgressRingStyle}"
            Grid.Row="2"
            IsActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
    </Grid>
</base:RankPageBase>
