<?xml version="1.0" encoding="utf-8" ?>
<local:PromptTestPageControlBase
    x:Class="RodelAgent.UI.Controls.Internal.PromptTestMainBody"
    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:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:RodelAgent.UI.Extensions"
    xmlns:items="using:RodelAgent.UI.ViewModels.Items"
    xmlns:local="using:RodelAgent.UI.Controls.Internal"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBox
            Padding="18,12"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            AcceptsReturn="True"
            FontSize="18"
            IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
            Style="{StaticResource TransparentTextBoxStyle}"
            Text="{x:Bind ViewModel.CurrentSystemPrompt.Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            TextWrapping="Wrap" />
        <Border
            Grid.Row="1"
            Height="1"
            HorizontalAlignment="Stretch"
            Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
        <TextBox
            Grid.Row="2"
            Padding="18,12"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            AcceptsReturn="True"
            FontSize="18"
            IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
            LostFocus="OnTextBoxLostFocus"
            Style="{StaticResource TransparentTextBoxStyle}"
            Text="{x:Bind ViewModel.UserPromptTemplate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            TextWrapping="Wrap" />
        <Border
            Grid.Row="3"
            Height="1"
            HorizontalAlignment="Stretch"
            Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
        <Grid Grid.Row="4" Padding="16,8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Button
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                Content="{ext:Locale Name=Variables}"
                IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
                Visibility="{x:Bind ViewModel.IsVariableEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <Button.Flyout>
                    <Flyout
                        Opened="OnVariableFlyoutOpened"
                        Placement="Top"
                        ShouldConstrainToRootBounds="False">
                        <Grid Width="380">
                            <ItemsRepeater ItemsSource="{x:Bind ViewModel.Variables}">
                                <ItemsRepeater.ItemTemplate>
                                    <DataTemplate x:DataType="items:VariableItemViewModel">
                                        <Grid>
                                            <ComboBox
                                                x:Name="ValuesComboBox"
                                                HorizontalAlignment="Stretch"
                                                x:Load="{x:Bind Values, Mode=OneWay, Converter={StaticResource ObjectToBoolConverter}}"
                                                Header="{x:Bind Name}"
                                                ItemsSource="{x:Bind Values}"
                                                SelectedItem="{x:Bind Value, Mode=TwoWay}"
                                                Visibility="{x:Bind Values, Converter={StaticResource ObjectToVisibilityConverter}}">
                                                <ComboBox.ItemTemplate>
                                                    <DataTemplate x:DataType="x:String">
                                                        <base:TrimTextBlock MaxLines="1" Text="{x:Bind}" />
                                                    </DataTemplate>
                                                </ComboBox.ItemTemplate>
                                            </ComboBox>
                                            <TextBox
                                                x:Name="ValueBox"
                                                HorizontalAlignment="Stretch"
                                                x:Load="{x:Bind Values, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
                                                AcceptsReturn="True"
                                                AllowFocusOnInteraction="True"
                                                Header="{x:Bind Name}"
                                                IsEnabled="{x:Bind IsEnabled, Mode=OneWay}"
                                                PlaceholderText="{x:Bind Name}"
                                                Text="{x:Bind Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                TextWrapping="Wrap"
                                                Visibility="{x:Bind Values, Converter={StaticResource ObjectToVisibilityReverseConverter}}" />
                                        </Grid>
                                    </DataTemplate>
                                </ItemsRepeater.ItemTemplate>
                                <ItemsRepeater.Layout>
                                    <StackLayout Spacing="8" />
                                </ItemsRepeater.Layout>
                            </ItemsRepeater>
                        </Grid>
                    </Flyout>
                </Button.Flyout>
            </Button>
            <Button
                Grid.Column="1"
                MinWidth="120"
                VerticalAlignment="Center"
                Command="{x:Bind ViewModel.GenerateCommand}"
                Content="{ext:Locale Name=Generate}"
                Style="{StaticResource AccentButtonStyle}"
                Visibility="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
            <Button
                Grid.Column="1"
                MinWidth="120"
                VerticalAlignment="Center"
                Command="{x:Bind ViewModel.CancelGeneratingCommand, Mode=OneWay}"
                Style="{StaticResource AccentButtonStyle}"
                Visibility="{x:Bind ViewModel.IsGenerating, Mode=OneWay}">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <ProgressRing
                        Width="16"
                        Height="16"
                        VerticalAlignment="Center"
                        Foreground="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Cancel}" />
                </StackPanel>
            </Button>
        </Grid>
    </Grid>
</local:PromptTestPageControlBase>
