<?xml version="1.0" encoding="utf-8" ?>
<local:ChatServicePageControlBase
    x:Class="RodelAgent.UI.Controls.Chat.ChatSessionListPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:components="using:RodelAgent.UI.ViewModels.Components"
    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.Controls.Items"
    xmlns:local="using:RodelAgent.UI.Controls.Chat"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid RowSpacing="8">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Padding="12,4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock
                VerticalAlignment="Center"
                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                Style="{StaticResource CaptionTextBlockStyle}"
                Text="{ext:Locale Name=SessionList}" />
            <Button
                Grid.Column="1"
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=MoreOptions}"
                Style="{StaticResource MiniIconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=MoreOptions}">
                <ic:SymbolIcon FontSize="12" Symbol="MoreHorizontal" />
                <Button.Flyout>
                    <MenuFlyout Placement="Bottom">
                        <MenuFlyoutItem
                            MinWidth="160"
                            Command="{x:Bind ViewModel.RemoveAllSessionsCommand}"
                            Text="{ext:Locale Name=RemoveAllSessions}">
                            <MenuFlyoutItem.Icon>
                                <ic:SymbolIcon
                                    FontSize="14"
                                    Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                                    Symbol="Delete" />
                            </MenuFlyoutItem.Icon>
                        </MenuFlyoutItem>
                    </MenuFlyout>
                </Button.Flyout>
            </Button>
        </Grid>
        <ScrollViewer
            Grid.Row="1"
            Padding="8,0"
            Style="{StaticResource PageScrollViewerStyle}"
            Visibility="{x:Bind ViewModel.IsChatHistorySessionsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <ItemsRepeater Margin="0,0,0,12" ItemsSource="{x:Bind ViewModel.HistoryChatSessions}">
                <ItemsRepeater.ItemTemplate>
                    <DataTemplate x:DataType="components:ChatSessionViewModel">
                        <items:ChatSessionItemControl
                            Click="OnItemClick"
                            DataContext="{x:Bind}"
                            ViewModel="{x:Bind}">
                            <items:ChatSessionItemControl.ContextFlyout>
                                <MenuFlyout>
                                    <MenuFlyoutItem
                                        x:Name="RenameItem"
                                        MinWidth="140"
                                        Click="OnRenameItemClickAsync"
                                        Text="{ext:Locale Name=Rename}">
                                        <MenuFlyoutItem.Icon>
                                            <ic:SymbolIcon Symbol="Rename" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem
                                        x:Name="SmartRenameItem"
                                        MinWidth="140"
                                        Command="{x:Bind GenerateTitleCommand}"
                                        Text="{ext:Locale Name=SmartRename}">
                                        <MenuFlyoutItem.Icon>
                                            <ic:SymbolIcon Symbol="PenSparkle" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem
                                        x:Name="DeleteItem"
                                        MinWidth="140"
                                        Click="OnDeleteItemClick"
                                        Text="{ext:Locale Name=Delete}">
                                        <MenuFlyoutItem.Icon>
                                            <ic:SymbolIcon Foreground="{ThemeResource SystemFillColorCriticalBrush}" Symbol="Delete" />
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </items:ChatSessionItemControl.ContextFlyout>
                        </items:ChatSessionItemControl>
                    </DataTemplate>
                </ItemsRepeater.ItemTemplate>
                <ItemsRepeater.Layout>
                    <StackLayout Spacing="2" />
                </ItemsRepeater.Layout>
            </ItemsRepeater>
        </ScrollViewer>
        <Border
            Grid.Row="1"
            Margin="12"
            Padding="12,8"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
            CornerRadius="{StaticResource ControlCornerRadius}"
            Visibility="{x:Bind ViewModel.IsChatHistorySessionsEmpty, Mode=OneWay}">
            <TextBlock
                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                Style="{StaticResource CaptionTextBlockStyle}"
                Text="{ext:Locale Name=NoSessionHistory}"
                TextAlignment="Center"
                TextWrapping="Wrap" />
        </Border>
    </Grid>
</local:ChatServicePageControlBase>
