<?xml version="1.0" encoding="utf-8" ?>
<local:HistoryPageControlBase
    x:Class="BiliCopilot.UI.Controls.History.HistoryHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:BiliCopilot.UI.Controls.History"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Padding="16,0" ColumnSpacing="12">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.ChildrenTransitions>
            <RepositionThemeTransition IsStaggeringEnabled="False" />
        </Grid.ChildrenTransitions>
        <TextBlock
            VerticalAlignment="Center"
            Style="{StaticResource BodyStrongTextBlockStyle}"
            Text="{ext:Locale Name=ViewHistory}" />
        <ScrollViewer
            Grid.Column="1"
            Margin="0,5,0,0"
            Padding="8,0"
            HorizontalAlignment="Center"
            VerticalAlignment="Stretch"
            HorizontalScrollBarVisibility="Hidden"
            HorizontalScrollMode="Enabled"
            VerticalScrollBarVisibility="Hidden"
            VerticalScrollMode="Disabled"
            Visibility="{x:Bind ViewModel.IsSearchMode, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <SelectorBar x:Name="Selector" />
        </ScrollViewer>
        <StackPanel
            Grid.Column="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Orientation="Horizontal"
            Spacing="8"
            Visibility="{x:Bind ViewModel.IsSearchMode, Mode=OneWay}">
            <TextBlock VerticalAlignment="Center">
                <Run Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{ext:Locale Name=Search}" />
                <Run
                    FontWeight="Bold"
                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                    Text="{x:Bind ViewModel.SearchKeyword, Mode=OneWay}" />
            </TextBlock>
            <Button
                VerticalAlignment="Center"
                Command="{x:Bind ViewModel.ExitSearchCommand}"
                Style="{StaticResource IconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=ExitSearch}">
                <ic:SymbolIcon FontSize="14" Symbol="Dismiss" />
            </Button>
        </StackPanel>
        <StackPanel
            Grid.Column="2"
            VerticalAlignment="Center"
            Orientation="Horizontal"
            Spacing="8">
            <Button
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=Refresh}"
                Command="{x:Bind ViewModel.RefreshCommand}"
                IsEnabled="{x:Bind ViewModel.SelectedSection.IsLoading, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}">
                <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>
            </Button>
            <Button
                x:Name="CleanButton"
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=ClearHistory}"
                Click="OnCleanButtonClick"
                IsEnabled="{x:Bind ViewModel.SelectedSection.IsEmpty, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
                Visibility="{x:Bind ViewModel.IsSearchMode, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <ic:SymbolIcon
                        VerticalAlignment="Center"
                        FontSize="12"
                        Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                        Symbol="DeleteLines" />
                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=ClearHistory}" />
                </StackPanel>
            </Button>
        </StackPanel>

        <TeachingTip
            x:Name="CleanTip"
            ActionButtonCommand="{x:Bind ViewModel.CleanCommand}"
            ActionButtonContent="{ext:Locale Name=Clean}"
            IsLightDismissEnabled="True"
            PreferredPlacement="BottomLeft"
            ShouldConstrainToRootBounds="False"
            Subtitle="{ext:Locale Name=ClearHistoryWarning}"
            Target="{x:Bind CleanButton}" />
    </Grid>
</local:HistoryPageControlBase>
