<base:PopularPageBase
    x:Class="Bili.App.Pages.Desktop.PopularPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:app="using:Bili.App.Controls.App"
    xmlns:base="using:Bili.App.Pages.Base"
    xmlns:behaviors="using:Bili.App.Behaviors"
    xmlns:controls="using:Bili.App.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    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>
        <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>
        <Grid RowSpacing="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <app:PageHeader Title="{loc:Locale Name=Popular}" RefreshCommand="{x:Bind ViewModel.ReloadCommand}" />
            <ScrollViewer
                x:Name="ContentScrollViewer"
                Grid.Row="1"
                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="VideoView"
                    Margin="0,0,0,12"
                    HeaderVisibility="Collapsed"
                    ItemsSource="{x:Bind ViewModel.Items}">
                    <Interactivity:Interaction.Behaviors>
                        <behaviors:IncrementalBehavior />
                    </Interactivity:Interaction.Behaviors>
                    <controls:VerticalRepeaterView.ItemTemplate>
                        <DataTemplate x:DataType="video:IVideoItemViewModel">
                            <videos:VideoItem ViewModel="{x:Bind}" />
                        </DataTemplate>
                    </controls:VerticalRepeaterView.ItemTemplate>
                </controls:VerticalRepeaterView>
            </ScrollViewer>
        </Grid>

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

        <controls:ErrorPanel
            x:Name="ErrorPanel"
            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>
    </Grid>
</base:PopularPageBase>
