<?xml version="1.0" encoding="utf-8" ?>
<local:AudioServicePageControlBase
    x:Class="RodelAgent.UI.Controls.Audio.AudioHistorySection"
    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:RodelAgent.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:items="using:RodelAgent.UI.ViewModels.Items"
    xmlns:local="using:RodelAgent.UI.Controls.Audio"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="56" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid
            Padding="16,0"
            VerticalAlignment="Stretch"
            BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
            BorderThickness="0,0,0,1"
            ColumnSpacing="8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" Spacing="8">
                <TextBlock
                    VerticalAlignment="Center"
                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                    Text="{ext:Locale Name=AudioHistory}" />
                <Border
                    Padding="4,2"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                    CornerRadius="2"
                    ToolTipService.ToolTip="{ext:Locale Name=AudioCount}"
                    Visibility="{x:Bind ViewModel.IsHistoryEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                    <TextBlock
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Text="{x:Bind ViewModel.HistoryCount, Mode=OneWay}" />
                </Border>
            </StackPanel>

            <Button
                Grid.Column="1"
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=OpenDirectory}"
                Command="{x:Bind ViewModel.OpenAudioFolderCommand}"
                Style="{StaticResource MiniIconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=OpenDirectory}">
                <ic:SymbolIcon FontSize="12" Symbol="FolderOpen" />
            </Button>
        </Grid>
        <ScrollViewer
            Grid.Row="1"
            Style="{StaticResource PageScrollViewerStyle}"
            Visibility="{x:Bind ViewModel.IsHistoryEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <Grid Margin="0,12,0,20">
                <ItemsRepeater ItemsSource="{x:Bind ViewModel.History}">
                    <ItemsRepeater.ItemTemplate>
                        <DataTemplate x:DataType="items:AudioSessionItemViewModel">
                            <local:AudioSessionItemControl ViewModel="{x:Bind}" />
                        </DataTemplate>
                    </ItemsRepeater.ItemTemplate>
                    <ItemsRepeater.Layout>
                        <StackLayout Spacing="4" />
                    </ItemsRepeater.Layout>
                </ItemsRepeater>
            </Grid>
        </ScrollViewer>
        <Border
            Grid.Row="1"
            Margin="12,8"
            Padding="12,8"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
            CornerRadius="{StaticResource ControlCornerRadius}"
            Visibility="{x:Bind ViewModel.IsHistoryEmpty, Mode=OneWay}">
            <TextBlock
                MaxWidth="200"
                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                Style="{StaticResource CaptionTextBlockStyle}"
                Text="{ext:Locale Name=NoAudioHistory}"
                TextWrapping="Wrap" />
        </Border>
    </Grid>
</local:AudioServicePageControlBase>
