<local:VideoFavoritePanelBase
    x:Class="Bili.App.Controls.Favorite.VideoFavoritePanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    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.Controls.Favorite"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    xmlns:video="using:Bili.ViewModels.Interfaces.Video"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">

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

    <Grid>
        <ScrollViewer
            x:Name="ContentScrollViewer"
            Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <Grid
                Margin="0,0,0,12"
                RowSpacing="12"
                XYFocusKeyboardNavigation="Enabled">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <labs:SettingsCard
                    x:Name="DefaultVideoExpander"
                    Click="OnDefaultExpanderClick"
                    Header="{loc:Locale Name=DefaultFavorite}"
                    IsClickEnabled="True"
                    IsEnabled="{x:Bind ViewModel.IsDefaultFolderEmpty, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}">
                    <labs:SettingsCard.HeaderIcon>
                        <icons:RegularFluentIcon Symbol="VideoClip16" />
                    </labs:SettingsCard.HeaderIcon>
                </labs:SettingsCard>
                <muxc:ItemsRepeater Grid.Row="1" ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}">
                    <muxc:ItemsRepeater.Layout>
                        <muxc:StackLayout Spacing="12" />
                    </muxc:ItemsRepeater.Layout>
                    <muxc:ItemsRepeater.ItemTemplate>
                        <DataTemplate x:DataType="video:IVideoFavoriteFolderGroupViewModel">
                            <muxc:Expander Style="{StaticResource NoAnimationExpanderStyle}">
                                <muxc:Expander.Header>
                                    <labs:SettingsCard
                                        Background="Transparent"
                                        BorderThickness="0"
                                        Header="{x:Bind Data.Title, Mode=OneWay}"
                                        IsClickEnabled="False">
                                        <labs:SettingsCard.HeaderIcon>
                                            <icons:RegularFluentIcon Symbol="Folder20" />
                                        </labs:SettingsCard.HeaderIcon>
                                    </labs:SettingsCard>
                                </muxc:Expander.Header>

                                <StackPanel>
                                    <muxc:ItemsRepeater ItemsSource="{x:Bind Items}">
                                        <muxc:ItemsRepeater.Layout>
                                            <muxc:StackLayout />
                                        </muxc:ItemsRepeater.Layout>
                                        <muxc:ItemsRepeater.ItemTemplate>
                                            <DataTemplate x:DataType="video:IVideoFavoriteFolderViewModel">
                                                <labs:SettingsCard Background="Transparent" BorderThickness="0">
                                                    <labs:SettingsCard.Header>
                                                        <Grid Margin="-12,0,0,0" ColumnSpacing="12">
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="Auto" />
                                                                <ColumnDefinition Width="*" />
                                                            </Grid.ColumnDefinitions>
                                                            <Grid CornerRadius="{StaticResource ControlCornerRadius}">
                                                                <controls:CommonImageEx
                                                                    Width="84"
                                                                    Height="56"
                                                                    ImageUrl="{x:Bind Folder.Cover.Uri, Mode=OneWay}" />
                                                            </Grid>
                                                            <StackPanel
                                                                Grid.Column="1"
                                                                HorizontalAlignment="Left"
                                                                VerticalAlignment="Center">
                                                                <TextBlock
                                                                    FontWeight="Bold"
                                                                    MaxLines="2"
                                                                    Text="{x:Bind Folder.Title, Mode=OneWay}"
                                                                    TextTrimming="CharacterEllipsis"
                                                                    TextWrapping="Wrap" />
                                                                <TextBlock
                                                                    Style="{StaticResource CaptionTextBlockStyle}"
                                                                    Margin="0,4,0,0"
                                                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                                    MaxLines="2"
                                                                    Text="{x:Bind Folder.Description, Mode=OneWay}"
                                                                    TextTrimming="CharacterEllipsis"
                                                                    TextWrapping="Wrap"
                                                                    Visibility="{x:Bind Folder.Description, Converter={StaticResource ObjectToVisibilityConverter}}" />
                                                            </StackPanel>
                                                        </Grid>
                                                    </labs:SettingsCard.Header>
                                                    <StackPanel
                                                        Margin="0,0,-12,0"
                                                        VerticalAlignment="Center"
                                                        Orientation="Horizontal">
                                                        <Button
                                                            Margin="0,0,8,0"
                                                            Command="{x:Bind ShowDetailCommand}"
                                                            Content="{loc:Locale Name=SeeDetail}" />
                                                        <Button
                                                            Click="OnRemoveFavoriteButtonClickAsync"
                                                            Content="{loc:Locale Name=DeleteFavorite}"
                                                            DataContext="{x:Bind}"
                                                            Visibility="{x:Bind IsMine, Mode=OneWay}" />
                                                        <Button
                                                            Click="OnRemoveFavoriteButtonClickAsync"
                                                            Content="{loc:Locale Name=UnFavorite}"
                                                            DataContext="{x:Bind}"
                                                            Visibility="{x:Bind IsMine, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                                                    </StackPanel>
                                                </labs:SettingsCard>
                                            </DataTemplate>
                                        </muxc:ItemsRepeater.ItemTemplate>
                                    </muxc:ItemsRepeater>
                                    <Grid>
                                        <Grid ColumnSpacing="12" Visibility="{x:Bind HasMore, Mode=OneWay}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <HyperlinkButton
                                                x:Name="LoadMoreButton"
                                                HorizontalAlignment="Left"
                                                Command="{x:Bind IncrementalCommand}"
                                                Content="{loc:Locale Name=ShowMore}" />
                                            <muxc:ProgressBar
                                                Grid.Column="1"
                                                HorizontalAlignment="Stretch"
                                                VerticalAlignment="Center"
                                                IsIndeterminate="True"
                                                Visibility="{x:Bind IsIncrementalLoading, Mode=OneWay}" />
                                        </Grid>
                                        <TextBlock
                                            HorizontalAlignment="Left"
                                            Text="{loc:Locale Name=NoSpecificData}"
                                            Visibility="{x:Bind IsEmpty, Mode=OneWay}" />
                                    </Grid>
                                </StackPanel>
                            </muxc:Expander>
                        </DataTemplate>
                    </muxc:ItemsRepeater.ItemTemplate>
                </muxc:ItemsRepeater>
            </Grid>
        </ScrollViewer>

        <controls:OverlayLoadingPanel 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>

</local:VideoFavoritePanelBase>
