<?xml version="1.0" encoding="utf-8" ?>
<local:VideoPartitionDetailControlBase
    x:Class="BiliCopilot.UI.Controls.VideoPartition.VideoPartitionMainHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animations="using:CommunityToolkit.WinUI.Animations"
    xmlns:community="using:CommunityToolkit.WinUI.Controls"
    xmlns:components="using:BiliCopilot.UI.Controls.Components"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:items="using:BiliCopilot.UI.ViewModels.Items"
    xmlns:local="using:BiliCopilot.UI.Controls.VideoPartition"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="using:Richasy.BiliKernel.Models"
    mc:Ignorable="d">

    <Grid
        Padding="16,0"
        ColumnSpacing="8"
        Visibility="{x:Bind ViewModel, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
        <Grid.ChildrenTransitions>
            <RepositionThemeTransition IsStaggeringEnabled="False" />
        </Grid.ChildrenTransitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <components:PartitionItemControl
            VerticalAlignment="Center"
            FontWeight="Bold"
            ViewModel="{x:Bind ViewModel.Data, Mode=OneWay}" />

        <ScrollViewer
            Grid.Column="1"
            Margin="0,5,0,0"
            Padding="8,0"
            HorizontalAlignment="Center"
            VerticalAlignment="Stretch"
            HorizontalScrollBarVisibility="Hidden"
            HorizontalScrollMode="Enabled"
            VerticalScrollBarVisibility="Hidden"
            VerticalScrollMode="Disabled">
            <SelectorBar x:Name="Selector" />
        </ScrollViewer>

        <Grid Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ComboBox
                MinWidth="120"
                Margin="0,0,8,0"
                VerticalAlignment="Center"
                ItemsSource="{x:Bind ViewModel.SortTypes, Mode=OneWay}"
                SelectedItem="{x:Bind ViewModel.SelectedSortType, Mode=OneWay}"
                SelectionChanged="OnSortTypeSelectionChanged"
                Visibility="{x:Bind ViewModel.IsRecommend, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <ComboBox.ItemTemplate>
                    <DataTemplate x:DataType="models:PartitionVideoSortType">
                        <TextBlock Text="{x:Bind Converter={StaticResource SortTypeTextConverter}}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                <animations:Implicit.ShowAnimations>
                    <animations:OpacityAnimation
                        From="0"
                        To="1"
                        Duration="0:0:0.2" />
                </animations:Implicit.ShowAnimations>
                <animations:Implicit.HideAnimations>
                    <animations:OpacityAnimation
                        From="1"
                        To="0"
                        Duration="0:0:0.2" />
                </animations:Implicit.HideAnimations>
            </ComboBox>
            <Button
                Grid.Column="1"
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=Refresh}"
                Command="{x:Bind ViewModel.RefreshCommand, Mode=OneWay}"
                Visibility="{x:Bind ViewModel.IsRecommend, Mode=OneWay}">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <ic:SymbolIcon
                        VerticalAlignment="Center"
                        FontSize="12"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        Symbol="ArrowSync" />
                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Refresh}" />
                </StackPanel>
                <animations:Implicit.ShowAnimations>
                    <animations:OpacityAnimation
                        From="0"
                        To="1"
                        Duration="0:0:0.2" />
                </animations:Implicit.ShowAnimations>
                <animations:Implicit.HideAnimations>
                    <animations:OpacityAnimation
                        From="1"
                        To="0"
                        Duration="0:0:0.2" />
                </animations:Implicit.HideAnimations>
            </Button>
            <Button
                Grid.Column="1"
                Width="32"
                Height="32"
                Padding="0"
                VerticalAlignment="Center"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=Refresh}"
                Command="{x:Bind ViewModel.RefreshCommand, Mode=OneWay}"
                ToolTipService.ToolTip="{ext:Locale Name=Refresh}"
                Visibility="{x:Bind ViewModel.IsRecommend, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <ic:SymbolIcon
                    VerticalAlignment="Center"
                    FontSize="12"
                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                    Symbol="ArrowSync" />
                <animations:Implicit.ShowAnimations>
                    <animations:OpacityAnimation
                        From="0"
                        To="1"
                        Duration="0:0:0.2" />
                </animations:Implicit.ShowAnimations>
                <animations:Implicit.HideAnimations>
                    <animations:OpacityAnimation
                        From="1"
                        To="0"
                        Duration="0:0:0.2" />
                </animations:Implicit.HideAnimations>
            </Button>
        </Grid>
    </Grid>
</local:VideoPartitionDetailControlBase>
