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

    <Grid MaxHeight="600">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="320" />
        </Grid.ColumnDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <local:ChatProviderOptionPanel IsMaxRoundEnabled="{x:Bind ViewModel.IsMaxRoundEnabled, Mode=OneWay}" ViewModel="{x:Bind ViewModel.Data, Mode=OneWay}" />
            <StackPanel
                Grid.Row="1"
                Margin="0,-4,0,0"
                Padding="20,0"
                Spacing="8">
                <controls:TokenizingTextBox
                    x:Name="StopSequencesBox"
                    HorizontalAlignment="Stretch"
                    Header="{ext:Locale Name=StopSequences_Optional}"
                    HeaderTemplate="{StaticResource InputHeaderTemplate}"
                    ItemsSource="{x:Bind ViewModel.StopSequences, Mode=OneWay}"
                    MaximumTokens="10"
                    PlaceholderText="{ext:Locale Name=AddToken}"
                    SelectionMode="None"
                    ToolTipService.ToolTip="{ext:Locale Name=StopSequencesDescription}">
                    <controls:TokenizingTextBox.QueryIcon>
                        <ic:SymbolIconSource Symbol="ArrowEnterLeft" />
                    </controls:TokenizingTextBox.QueryIcon>
                    <controls:TokenizingTextBox.ItemTemplate>
                        <DataTemplate x:DataType="x:String">
                            <TextBlock
                                MaxWidth="120"
                                MaxLines="1"
                                Text="{x:Bind}"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap" />
                        </DataTemplate>
                    </controls:TokenizingTextBox.ItemTemplate>
                </controls:TokenizingTextBox>
                <controls:TokenizingTextBox
                    x:Name="FilterCharactersBox"
                    HorizontalAlignment="Stretch"
                    AutomationProperties.Name="{ext:Locale Name=FilterCharacters_Optional}"
                    Header="{ext:Locale Name=FilterCharacters_Optional}"
                    HeaderTemplate="{StaticResource InputHeaderTemplate}"
                    ItemsSource="{x:Bind ViewModel.FilterCharacters, Mode=OneWay}"
                    MaximumTokens="10"
                    PlaceholderText="{ext:Locale Name=AddText}"
                    SelectionMode="None"
                    ToolTipService.ToolTip="{ext:Locale Name=FilterCharactersDescription}">
                    <controls:TokenizingTextBox.QueryIcon>
                        <ic:SymbolIconSource Symbol="ArrowEnterLeft" />
                    </controls:TokenizingTextBox.QueryIcon>
                    <controls:TokenizingTextBox.ItemTemplate>
                        <DataTemplate x:DataType="x:String">
                            <TextBlock
                                MaxWidth="120"
                                MaxLines="1"
                                Text="{x:Bind}"
                                TextTrimming="CharacterEllipsis"
                                TextWrapping="NoWrap" />
                        </DataTemplate>
                    </controls:TokenizingTextBox.ItemTemplate>
                </controls:TokenizingTextBox>
            </StackPanel>

        </Grid>
        <Border
            Grid.Column="1"
            Width="1"
            Height="120"
            VerticalAlignment="Center"
            Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
        <Grid Grid.Column="2" RowSpacing="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock
                HorizontalAlignment="Left"
                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                Style="{StaticResource CaptionTextBlockStyle}"
                Text="{ext:Locale Name=PresetMessages}" />
            <Grid
                Grid.Row="1"
                Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
                BorderThickness="1"
                CornerRadius="{StaticResource ControlCornerRadius}">
                <TextBlock
                    Margin="12,0"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=NoMessage}"
                    TextAlignment="Center"
                    Visibility="{x:Bind ViewModel.IsMessageEmpty, Mode=OneWay}" />
                <ScrollViewer Style="{StaticResource PageScrollViewerStyle}" Visibility="{x:Bind ViewModel.IsMessageEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                    <Grid>
                        <ItemsControl Margin="0,0,0,20" ItemsSource="{x:Bind ViewModel.Messages, Mode=OneWay}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <ItemsStackPanel />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate x:DataType="items:ChatMessageItemViewModel">
                                    <local:ChatMessageItemControl Margin="0,4" ViewModel="{x:Bind}" />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Grid>
                </ScrollViewer>
            </Grid>
            <Grid Grid.Row="2" ColumnSpacing="8">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <ComboBox x:Name="RoleSelection" VerticalAlignment="Center">
                    <ComboBoxItem Content="{ext:Locale Name=User}" IsSelected="True" />
                    <ComboBoxItem Content="{ext:Locale Name=Assistant}" />
                </ComboBox>
                <TextBox
                    x:Name="MessageInput"
                    Grid.Column="1"
                    HorizontalAlignment="Stretch"
                    AcceptsReturn="True"
                    InputScope="Chat"
                    IsSpellCheckEnabled="False"
                    PlaceholderText="{ext:Locale Name=TypePresetMessagePlaceholder}"
                    PreviewKeyDown="OnInputBoxPreviewKeyDown"
                    TextWrapping="Wrap" />
            </Grid>
        </Grid>
    </Grid>
</local:ChatPresetControlBase>
