<local:TimelinePageBase
    x:Class="Bili.App.Pages.Desktop.Overlay.TimelinePage"
    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:controls="using:Bili.App.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:icons="using:Richasy.FluentIcon.Uwp"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:labs="using:CommunityToolkit.Labs.WinUI"
    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"
    xmlns:pgc="using:Bili.Models.Data.Pgc"
    xmlns:pgc1="using:Bili.App.Controls.Pgc"
    mc:Ignorable="d">
    <Page.Resources>
        <DataTemplate x:Key="TimlineTemplate" x:DataType="pgc:TimelineInformation">
            <labs:SettingsExpander
                Description="{x:Bind Date}"
                Header="{x:Bind DayOfWeek}"
                IsExpanded="{x:Bind IsToday}">
                <labs:SettingsExpander.HeaderIcon>
                    <icons:RegularFluentIcon Symbol="CalendarDay16" />
                </labs:SettingsExpander.HeaderIcon>
                <labs:SettingsExpander.Items>
                    <labs:SettingsCard>
                        <labs:SettingsCard.Header>
                            <Grid>
                                <muxc:ItemsRepeater x:Name="Repeater" ItemsSource="{x:Bind Seasons}">
                                    <muxc:ItemsRepeater.Layout>
                                        <muxc:UniformGridLayout
                                            ItemsStretch="Fill"
                                            MinColumnSpacing="12"
                                            MinItemHeight="160"
                                            MinItemWidth="300"
                                            MinRowSpacing="12" />
                                    </muxc:ItemsRepeater.Layout>
                                    <muxc:ItemsRepeater.ItemTemplate>
                                        <DataTemplate x:DataType="pgc:SeasonInformation">
                                            <pgc1:SeasonItem Style="{StaticResource SlimSeasonItemStyle}" Information="{x:Bind}" />
                                        </DataTemplate>
                                    </muxc:ItemsRepeater.ItemTemplate>
                                </muxc:ItemsRepeater>
                                <TextBlock
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Text="{loc:Locale Name=TimelineHasNoVideo}"
                                    Visibility="{x:Bind Seasons, Converter={StaticResource ObjectToVisibilityReverseConverter}}" />
                            </Grid>
                        </labs:SettingsCard.Header>
                    </labs:SettingsCard>
                </labs:SettingsExpander.Items>
            </labs:SettingsExpander>
        </DataTemplate>
    </Page.Resources>

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

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

        <app:PageHeader>
            <app:PageHeader.Title>
                <StackPanel Spacing="4">
                    <TextBlock
                        Style="{StaticResource TitleTextBlockStyle}"
                        HorizontalAlignment="Left"
                        Text="{x:Bind ViewModel.Title, Mode=OneWay}"
                        TextTrimming="CharacterEllipsis" />
                    <TextBlock
                        Style="{StaticResource BodyTextBlockStyle}"
                        HorizontalAlignment="Left"
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        Text="{x:Bind ViewModel.Description, Mode=OneWay}"
                        TextTrimming="CharacterEllipsis" />
                </StackPanel>
            </app:PageHeader.Title>
        </app:PageHeader>

        <Grid Grid.Row="1">
            <ScrollViewer
                x:Name="ContentScrollViewer"
                Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
                HorizontalScrollMode="Auto"
                VerticalScrollBarVisibility="Auto"
                VerticalScrollMode="Auto">
                <muxc:ItemsRepeater
                    x:Name="TimeLineView"
                    Margin="0,0,0,12"
                    ItemTemplate="{StaticResource TimlineTemplate}"
                    ItemsSource="{x:Bind ViewModel.Timelines, Mode=OneWay}">
                    <muxc:ItemsRepeater.Layout>
                        <muxc:StackLayout Spacing="8" />
                    </muxc:ItemsRepeater.Layout>
                </muxc:ItemsRepeater>
            </ScrollViewer>

            <controls:OverlayLoadingPanel IsBarActive="False" IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
            <controls: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>
    </Grid>
</local:TimelinePageBase>
