<?xml version="1.0" encoding="utf-8" ?>
<local:PromptTestPageControlBase
    x:Class="RodelAgent.UI.Controls.Internal.PromptTestSideBody"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Richasy.WinUI.Share.Base"
    xmlns:chat="using:RodelAgent.UI.Controls.Chat"
    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:items1="using:RodelAgent.UI.Controls.Items"
    xmlns:local="using:RodelAgent.UI.Controls.Internal"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <UserControl.Resources>
        <Thickness x:Key="SettingsExpanderItemPadding">16,4,16,4</Thickness>
        <x:Double x:Key="SettingsCardWrapThreshold">126</x:Double>
        <x:Double x:Key="SettingsCardWrapNoIconThreshold">126</x:Double>
    </UserControl.Resources>

    <Grid>
        <ScrollView IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" Style="{StaticResource PageScrollViewStyle}">
            <StackPanel Margin="12,8" Spacing="8">
                <StackPanel.ChildrenTransitions>
                    <RepositionThemeTransition IsStaggeringEnabled="False" />
                </StackPanel.ChildrenTransitions>
                <TextBlock
                    HorizontalAlignment="Left"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=Model}" />
                <ComboBox
                    HorizontalAlignment="Stretch"
                    ItemsSource="{x:Bind ViewModel.AvailableServices, Mode=OneWay}"
                    SelectedItem="{x:Bind ViewModel.SelectedService, Mode=OneWay}"
                    SelectionChanged="OnServiceSelectionChanged">
                    <ComboBox.ItemTemplate>
                        <DataTemplate x:DataType="items:ChatServiceItemViewModel">
                            <items1:ChatServiceItemControl Style="{StaticResource SelectionServiceStyle}" ViewModel="{x:Bind}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <ComboBox
                    HorizontalAlignment="Stretch"
                    ItemsSource="{x:Bind ViewModel.AvailableModels, Mode=OneWay}"
                    SelectedItem="{x:Bind ViewModel.SelectedModel, Mode=OneWay}"
                    SelectionChanged="OnModelSelectionChanged">
                    <ComboBox.ItemTemplate>
                        <DataTemplate x:DataType="items:ChatModelItemViewModel">
                            <items1:ChatModelCard Style="{StaticResource SelectionChatModelCardStyle}" ViewModel="{x:Bind}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock
                    Margin="0,8,0,0"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=Dataset}" />
                <base:SettingsExpander Header="{ext:Locale Name=ImportInputs}">
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <InfoBadge
                            VerticalAlignment="Center"
                            Style="{StaticResource InformationalValueInfoBadgeStyle}"
                            Value="{x:Bind ViewModel.InputsCount, Mode=OneWay}" />
                        <Button Command="{x:Bind ViewModel.ImportInputsCommand}" Content="{ext:Locale Name=Import}" />
                    </StackPanel>

                    <base:SettingsExpander.ItemsFooter>
                        <Grid
                            Padding="16,12"
                            HorizontalAlignment="Stretch"
                            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                            ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                IsTextSelectionEnabled="True"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{x:Bind ViewModel.InputFilePath, Mode=OneWay}" />
                            <Button
                                Grid.Column="1"
                                VerticalAlignment="Center"
                                Command="{x:Bind ViewModel.OpenInputFileCommand}"
                                Style="{StaticResource SmallIconButtonStyle}"
                                ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
                                Visibility="{x:Bind ViewModel.InputFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <ic:SymbolIcon FontSize="14" Symbol="Open" />
                            </Button>
                            <Button
                                Grid.Column="2"
                                VerticalAlignment="Center"
                                Command="{x:Bind ViewModel.RemoveInputCommand}"
                                Style="{StaticResource SmallIconButtonStyle}"
                                ToolTipService.ToolTip="{ext:Locale Name=Delete}"
                                Visibility="{x:Bind ViewModel.InputFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <ic:SymbolIcon
                                    FontSize="14"
                                    Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                                    Symbol="Delete" />
                            </Button>
                        </Grid>
                    </base:SettingsExpander.ItemsFooter>
                </base:SettingsExpander>
                <base:SettingsExpander Header="{ext:Locale Name=ImportHistory}">
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <InfoBadge
                            VerticalAlignment="Center"
                            Style="{StaticResource InformationalValueInfoBadgeStyle}"
                            Value="{x:Bind ViewModel.MessageCount, Mode=OneWay}" />
                        <Button Command="{x:Bind ViewModel.ImportHistoryCommand}" Content="{ext:Locale Name=Import}" />
                    </StackPanel>

                    <base:SettingsExpander.ItemsFooter>
                        <Grid
                            Padding="16,12"
                            HorizontalAlignment="Stretch"
                            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                            ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                IsTextSelectionEnabled="True"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{x:Bind ViewModel.MessageJsonFilePath, Mode=OneWay}" />
                            <Button
                                Grid.Column="1"
                                VerticalAlignment="Center"
                                Command="{x:Bind ViewModel.OpenHistoryFileCommand}"
                                Style="{StaticResource SmallIconButtonStyle}"
                                ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
                                Visibility="{x:Bind ViewModel.MessageJsonFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <ic:SymbolIcon FontSize="14" Symbol="Open" />
                            </Button>
                        </Grid>
                    </base:SettingsExpander.ItemsFooter>
                </base:SettingsExpander>
                <base:SettingsExpander Header="{ext:Locale Name=ImportVariables}">
                    <StackPanel Orientation="Horizontal" Spacing="8">
                        <InfoBadge
                            VerticalAlignment="Center"
                            Style="{StaticResource InformationalValueInfoBadgeStyle}"
                            Value="{x:Bind ViewModel.PresetVariablesCount, Mode=OneWay}" />
                        <Button Command="{x:Bind ViewModel.ImportVariablesCommand}" Content="{ext:Locale Name=Import}" />
                    </StackPanel>

                    <base:SettingsExpander.ItemsFooter>
                        <Grid
                            Padding="16,12"
                            HorizontalAlignment="Stretch"
                            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                            ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                IsTextSelectionEnabled="True"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{x:Bind ViewModel.PresetVariablesFilePath, Mode=OneWay}" />
                            <Button
                                Grid.Column="1"
                                VerticalAlignment="Center"
                                Command="{x:Bind ViewModel.OpenVariablesFileCommand}"
                                Style="{StaticResource SmallIconButtonStyle}"
                                ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
                                Visibility="{x:Bind ViewModel.PresetVariablesFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <ic:SymbolIcon FontSize="14" Symbol="Open" />
                            </Button>
                        </Grid>
                    </base:SettingsExpander.ItemsFooter>
                </base:SettingsExpander>
                <TextBlock
                    Margin="0,8,0,0"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=SessionOptions}" />
                <chat:ChatProviderOptionPanel
                    Margin="-16,0"
                    BasicPanelVisibility="Collapsed"
                    ViewModel="{x:Bind ViewModel.Preset, Mode=OneWay}" />
            </StackPanel>
        </ScrollView>
    </Grid>
</local:PromptTestPageControlBase>
