<UserControl
    x:Class="Bili.App.Controls.Favorite.PgcFavoritePanel"
    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:converter="using:Bili.App.Resources.Converter"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:icons="using:Richasy.FluentIcon.Uwp"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pgc="using:Bili.App.Controls.Pgc"
    xmlns:pgc1="using:Bili.ViewModels.Interfaces.Pgc"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">

    <UserControl.Resources>
        <converter:PgcFavoriteStatusConverter x:Key="StatusConverter" />
    </UserControl.Resources>

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

    <Grid Padding="2,2,0,0" RowSpacing="8">
        <Grid.RowDefinitions>
            <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="PgcView.ItemOrientation" Value="Horizontal" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <ComboBox
            x:Name="StatusComboBox"
            MinWidth="120"
            Margin="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalAlignment="Left"
            ItemsSource="{x:Bind ViewModel.StatusCollection}"
            SelectedItem="{x:Bind ViewModel.Status, Mode=OneWay}"
            SelectionChanged="OnStatusSelectionChanged"
            TabIndex="1">
            <ComboBox.ItemTemplate>
                <DataTemplate x:DataType="x:Int32">
                    <TextBlock Text="{x:Bind Converter={StaticResource StatusConverter}}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <ScrollViewer
            x:Name="ContentScrollViewer"
            Grid.Row="1"
            Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            IsTabStop="False"
            VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <controls:VerticalRepeaterView
                x:Name="PgcView"
                Margin="0,0,0,12"
                HeaderVisibility="Collapsed"
                IsTabStop="False"
                ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                MinWideItemHeight="180"
                MinWideItemWidth="300">
                <interactivity:Interaction.Behaviors>
                    <behaviors:IncrementalBehavior />
                </interactivity:Interaction.Behaviors>
                <controls:VerticalRepeaterView.ItemTemplate>
                    <DataTemplate x:DataType="pgc1:ISeasonItemViewModel">
                        <pgc:SeasonItem ViewModel="{x:Bind}">
                            <pgc:SeasonItem.ContextFlyout>
                                <MenuFlyout Opened="OnItemFlyoutOpened">
                                    <MenuFlyoutItem
                                        x:Name="MarkWantWatchButton"
                                        Click="OnMarkStatusButtonClick"
                                        Tag="1"
                                        Text="{loc:Locale Name=MarkWantWatch}">
                                        <MenuFlyoutItem.Icon>
                                            <icons:RegularFluentIcon Symbol="Thinking20" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem
                                        x:Name="MarkWatchingButton"
                                        Click="OnMarkStatusButtonClick"
                                        Tag="2"
                                        Text="{loc:Locale Name=MarkWatching}">
                                        <MenuFlyoutItem.Icon>
                                            <icons:RegularFluentIcon Symbol="EyeTrackingOn20" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem
                                        x:Name="MarkWatchedButton"
                                        Click="OnMarkStatusButtonClick"
                                        Tag="3"
                                        Text="{loc:Locale Name=MarkWatched}">
                                        <MenuFlyoutItem.Icon>
                                            <icons:RegularFluentIcon Symbol="Folder16" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem Command="{x:Bind UnfollowCommand}" Text="{loc:Locale Name=UnFavorite}">
                                        <MenuFlyoutItem.Icon>
                                            <icons:RegularFluentIcon Symbol="StarOff16" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </pgc:SeasonItem.ContextFlyout>
                        </pgc:SeasonItem>
                    </DataTemplate>
                </controls:VerticalRepeaterView.ItemTemplate>
            </controls:VerticalRepeaterView>
        </ScrollViewer>

        <controls:OverlayLoadingPanel
            Grid.Row="1"
            IsBarActive="{x:Bind ViewModel.IsIncrementalLoading, Mode=OneWay}"
            IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
        <controls:ErrorPanel
            Grid.Row="1"
            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="1"
            Text="{loc:Locale Name=NoSpecificData}"
            Visibility="{x:Bind ViewModel.IsEmpty, Mode=OneWay}" />
    </Grid>
</UserControl>
