<UserControl
    x:Class="AdvancedPaste.Controls.PromptBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animations="using:CommunityToolkit.WinUI.Animations"
    xmlns:converters="using:AdvancedPaste.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:AdvancedPaste.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:settings="using:Microsoft.PowerToys.Settings.UI.Library"
    xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
    xmlns:ui="using:CommunityToolkit.WinUI"
    x:Name="PromptBoxControl"
    mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>

            <LinearGradientBrush x:Name="IntelligentUnderlineGradient" StartPoint="0,0.5" EndPoint="1,0.5">
                <GradientStop Offset="0.0" Color="#FF0078D4" />
                <GradientStop Offset="0.42" Color="#FF464FEB" />
                <GradientStop Offset="0.87" Color="#FFD660FF" />
                <GradientStop Offset="1.0" Color="#FFFEA874" />
            </LinearGradientBrush>
            <x:Double x:Key="ModelSelectorButtonWidth">44</x:Double>
            <Style x:Key="CustomTextBoxStyle" TargetType="TextBox">
                <Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
                <Setter Property="Background" Value="{ThemeResource TextControlBackground}" />
                <Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}" />
                <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}" />
                <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
                <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
                <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
                <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" />
                <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
                <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
                <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
                <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
                <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}" />
                <Setter Property="UseSystemFocusVisuals" Value="{ThemeResource IsApplicationFocusVisualKindReveal}" />
                <Setter Property="ContextFlyout" Value="{StaticResource TextControlCommandBarContextFlyout}" />
                <Setter Property="SelectionFlyout" Value="{StaticResource TextControlCommandBarSelectionFlyout}" />
                <Setter Property="CornerRadius" Value="8" />
                <Setter Property="BackgroundSizing" Value="InnerBorderEdge" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="TextBox">
                            <Grid>
                                <Grid.Resources>
                                    <Style x:Name="DeleteButtonStyle" TargetType="Button">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="Button">
                                                    <Grid
                                                        x:Name="ButtonLayoutGrid"
                                                        Margin="{ThemeResource TextBoxInnerButtonMargin}"
                                                        Background="{ThemeResource TextControlButtonBackground}"
                                                        BackgroundSizing="{TemplateBinding BackgroundSizing}"
                                                        BorderBrush="{ThemeResource TextControlButtonBorderBrush}"
                                                        BorderThickness="{TemplateBinding BorderThickness}"
                                                        CornerRadius="{TemplateBinding CornerRadius}"
                                                        Visibility="Collapsed">
                                                        <TextBlock
                                                            x:Name="GlyphElement"
                                                            HorizontalAlignment="Center"
                                                            VerticalAlignment="Center"
                                                            AutomationProperties.AccessibilityView="Raw"
                                                            FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                                            FontSize="{ThemeResource TextBoxIconFontSize}"
                                                            FontStyle="Normal"
                                                            Foreground="{ThemeResource TextControlButtonForeground}"
                                                            Text="&#xE894;" />
                                                        <VisualStateManager.VisualStateGroups>
                                                            <VisualStateGroup x:Name="CommonStates">
                                                                <VisualState x:Name="Normal" />
                                                                <VisualState x:Name="PointerOver">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="Background">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonBackgroundPointerOver}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="BorderBrush">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonBorderBrushPointerOver}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonForegroundPointerOver}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Pressed">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="Background">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonBackgroundPressed}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="BorderBrush">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonBorderBrushPressed}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlButtonForegroundPressed}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Disabled">
                                                                    <Storyboard>
                                                                        <DoubleAnimation
                                                                            Storyboard.TargetName="ButtonLayoutGrid"
                                                                            Storyboard.TargetProperty="Opacity"
                                                                            To="0"
                                                                            Duration="0" />
                                                                    </Storyboard>
                                                                </VisualState>
                                                            </VisualStateGroup>
                                                        </VisualStateManager.VisualStateGroups>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </Grid.Resources>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="0" />
                                    <ColumnDefinition Width="32" />
                                </Grid.ColumnDefinitions>

                                <ContentPresenter
                                    x:Name="HeaderContentPresenter"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="3"
                                    Margin="{ThemeResource TextBoxTopHeaderMargin}"
                                    VerticalAlignment="Top"
                                    x:DeferLoadStrategy="Lazy"
                                    Content="{TemplateBinding Header}"
                                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                                    FontWeight="Normal"
                                    Foreground="{ThemeResource TextControlHeaderForeground}"
                                    TextWrapping="Wrap"
                                    Visibility="Collapsed" />

                                <Border
                                    x:Name="BorderElement"
                                    Grid.Row="1"
                                    Grid.RowSpan="1"
                                    Grid.Column="0"
                                    Grid.ColumnSpan="4"
                                    MinWidth="{TemplateBinding MinWidth}"
                                    MinHeight="{TemplateBinding MinHeight}"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Control.IsTemplateFocusTarget="True"
                                    CornerRadius="{TemplateBinding CornerRadius}" />
                                <Rectangle
                                    x:Name="FocusHighlighter"
                                    Grid.Row="1"
                                    Grid.RowSpan="1"
                                    Grid.ColumnSpan="4"
                                    Height="2"
                                    Margin="12,0,12,0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Bottom"
                                    Fill="{StaticResource IntelligentUnderlineGradient}"
                                    RadiusX="1"
                                    RadiusY="1"
                                    Visibility="Collapsed" />
                                <Grid Grid.Row="1" Width="{StaticResource ModelSelectorButtonWidth}">
                                    <ProgressRing
                                        Width="20"
                                        Height="20"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        IsActive="{Binding DataContext.IsBusy, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        IsIndeterminate="{Binding DataContext.HasIndeterminateTransformProgress, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                        Maximum="100"
                                        Minimum="0"
                                        Visibility="{Binding DataContext.IsBusy, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}"
                                        Value="{Binding DataContext.TransformProgress, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </Grid>
                                <ScrollViewer
                                    x:Name="ContentElement"
                                    Grid.Row="1"
                                    Grid.Column="1"
                                    Margin="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    VerticalAlignment="Center"
                                    AutomationProperties.AccessibilityView="Raw"
                                    Foreground="{TemplateBinding Foreground}"
                                    HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                    HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                    IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                    IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                    IsTabStop="False"
                                    IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                    VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                    VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                    ZoomMode="Disabled" />
                                <TextBlock
                                    x:Name="PlaceholderTextContentPresenter"
                                    Grid.Row="1"
                                    Grid.Column="1"
                                    Grid.ColumnSpan="2"
                                    Margin="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    VerticalAlignment="Center"
                                    Foreground="{Binding PlaceholderForeground, RelativeSource={RelativeSource TemplatedParent}, TargetNullValue={ThemeResource TextControlPlaceholderForeground}}"
                                    IsHitTestVisible="False"
                                    Text="{TemplateBinding PlaceholderText}"
                                    TextAlignment="{TemplateBinding TextAlignment}"
                                    TextWrapping="{TemplateBinding TextWrapping}" />
                                <Button
                                    x:Name="DeleteButton"
                                    Grid.Row="1"
                                    Grid.Column="2"
                                    Width="30"
                                    Padding="{ThemeResource HelperButtonThemePadding}"
                                    VerticalAlignment="Stretch"
                                    AutomationProperties.AccessibilityView="Raw"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="{TemplateBinding CornerRadius}"
                                    FontSize="{TemplateBinding FontSize}"
                                    IsTabStop="False"
                                    Style="{StaticResource DeleteButtonStyle}"
                                    Visibility="Collapsed" />
                                <ContentPresenter
                                    x:Name="DescriptionPresenter"
                                    Grid.Row="2"
                                    Grid.ColumnSpan="3"
                                    x:Load="False"
                                    AutomationProperties.AccessibilityView="Raw"
                                    Content="{TemplateBinding Description}" />
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlHeaderForegroundDisabled}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundDisabled}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushDisabled}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundDisabled}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForeground, RelativeSource={RelativeSource TemplatedParent}, TargetNullValue={ThemeResource TextControlPlaceholderForegroundDisabled}}" />
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="PointerOver">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushPointerOver}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundPointerOver}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForeground, RelativeSource={RelativeSource TemplatedParent}, TargetNullValue={ThemeResource TextControlPlaceholderForegroundPointerOver}}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundPointerOver}" />
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Focused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForeground, RelativeSource={RelativeSource TemplatedParent}, TargetNullValue={ThemeResource TextControlPlaceholderForegroundFocused}}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocused}" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusHighlighter" Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                                </ObjectAnimationUsingKeyFrames>
                                                <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <LinearGradientBrush MappingMode="Absolute" StartPoint="0,0" EndPoint="0,2">
                                                                <LinearGradientBrush.RelativeTransform>
                                                                    <ScaleTransform CenterY="0.5" ScaleY="-1" />
                                                                </LinearGradientBrush.RelativeTransform>
                                                                <LinearGradientBrush.GradientStops>
                                                                    <GradientStop Offset="1.0" Color="{ThemeResource AccentGradientColor}" />
                                                                    <GradientStop Offset="1.0" Color="{ThemeResource ControlStrokeColorDefault}" />
                                                                </LinearGradientBrush.GradientStops>
                                                            </LinearGradientBrush>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderThickness">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderThemeThicknessFocused}" />
                                                </ObjectAnimationUsingKeyFrames>-->
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundFocused}" />
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="ButtonStates">
                                        <VisualState x:Name="ButtonVisible">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="ButtonCollapsed" />
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <tkconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
            <tkconverters:BoolToVisibilityConverter
                x:Key="BoolToInvertedVisibilityConverter"
                FalseValue="Visible"
                TrueValue="Collapsed" />
            <converters:CountToVisibilityConverter x:Key="CountToVisibilityConverter" />
            <converters:CountToInvertedVisibilityConverter x:Key="CountToInvertedVisibilityConverter" />
            <converters:ServiceTypeToIconConverter x:Key="ServiceTypeToIconConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid x:Name="PromptBoxGrid" Loaded="Grid_Loaded">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="40" />
        </Grid.RowDefinitions>
        <local:AnimatedContentControl
            x:Name="Loader"
            MinHeight="48"
            CornerRadius="16">
            <Grid>
                <TextBox
                    x:Name="InputTxtBox"
                    HorizontalAlignment="Stretch"
                    x:FieldModifier="public"
                    CornerRadius="16"
                    DataContext="{x:Bind ViewModel}"
                    IsEnabled="{x:Bind ViewModel.ClipboardHasData, Mode=OneWay}"
                    KeyDown="InputTxtBox_KeyDown"
                    PlaceholderText="{x:Bind ViewModel.InputTxtBoxPlaceholderText, Mode=OneWay}"
                    Style="{StaticResource CustomTextBoxStyle}"
                    TabIndex="1"
                    Text="{x:Bind ViewModel.Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <ToolTipService.ToolTip>
                        <TextBlock x:Uid="InputTxtBoxTooltip" />
                    </ToolTipService.ToolTip>
                    <FlyoutBase.AttachedFlyout>
                        <Flyout
                            x:Name="PreviewFlyout"
                            AreOpenCloseAnimationsEnabled="False"
                            Opened="PreviewFlyout_Opened"
                            Placement="Bottom"
                            ShouldConstrainToRootBounds="False">
                            <Flyout.FlyoutPresenterStyle>
                                <Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
                                    <Style.Setters>
                                        <Setter Property="MaxWidth" Value="3000" />
                                        <Setter Property="Padding" Value="0" />
                                    </Style.Setters>
                                </Style>
                            </Flyout.FlyoutPresenterStyle>
                            <Grid x:Name="PreviewGrid" Background="{ThemeResource SolidBackgroundFillColorBaseBrush}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Grid
                                    Padding="12,8,12,8"
                                    Background="{ThemeResource LayerFillColorAltBrush}"
                                    CornerRadius="8,8,0,0"
                                    RowSpacing="4">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <TextBlock x:Uid="ResultTitleTxt" VerticalAlignment="Center" />
                                    <StackPanel
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Center"
                                        Orientation="Horizontal"
                                        Spacing="2">
                                        <Button
                                            Padding="4"
                                            AutomationProperties.LabeledBy="{x:Bind ThumbsUpFeedback}"
                                            Click="ThumbUpDown_Click"
                                            CommandParameter="True"
                                            Content="{ui:FontIcon Glyph=&#xE8E1;,
                                                                  FontSize=14}"
                                            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                            Style="{StaticResource SubtleButtonStyle}">
                                            <ToolTipService.ToolTip>
                                                <TextBlock x:Name="ThumbsUpFeedback" x:Uid="ThumbsUpFeedback" />
                                            </ToolTipService.ToolTip>
                                        </Button>
                                        <Button
                                            Padding="4"
                                            AutomationProperties.LabeledBy="{x:Bind ThumbsDownFeedback}"
                                            Click="ThumbUpDown_Click"
                                            CommandParameter="False"
                                            Content="{ui:FontIcon Glyph=&#xE8E0;,
                                                                  FontSize=14}"
                                            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                            Style="{StaticResource SubtleButtonStyle}">
                                            <ToolTipService.ToolTip>
                                                <TextBlock x:Name="ThumbsDownFeedback" x:Uid="ThumbsDownFeedback" />
                                            </ToolTipService.ToolTip>
                                        </Button>
                                    </StackPanel>
                                    <ScrollViewer
                                        Grid.Row="1"
                                        MinHeight="104"
                                        MaxHeight="320">
                                        <TextBlock
                                            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                            IsTextSelectionEnabled="True"
                                            Style="{StaticResource CaptionTextBlockStyle}"
                                            Text="{x:Bind ViewModel.CustomFormatResult, Mode=OneWay}"
                                            TextWrapping="Wrap" />
                                    </ScrollViewer>
                                </Grid>
                                <Rectangle
                                    Grid.Row="1"
                                    Height="1"
                                    Fill="{ThemeResource DividerStrokeColorDefaultBrush}" />

                                <Grid
                                    Grid.Row="2"
                                    Margin="12"
                                    ColumnSpacing="8">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <StackPanel
                                        Margin="-4,0,0,0"
                                        Orientation="Horizontal"
                                        Spacing="2"
                                        Visibility="{x:Bind ViewModel.HasMultipleResponses, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                                        <Button
                                            x:Uid="PreviousResultBtnAutomation"
                                            Padding="4"
                                            VerticalAlignment="Stretch"
                                            Command="{x:Bind ViewModel.PreviousCustomFormatCommand}"
                                            Content="{ui:FontIcon Glyph=&#xE76B;,
                                                                  FontSize=14}"
                                            Style="{StaticResource SubtleButtonStyle}">
                                            <ToolTipService.ToolTip>
                                                <TextBlock x:Uid="PreviousResultBtnToolTip" />
                                            </ToolTipService.ToolTip>
                                        </Button>
                                        <TextBlock
                                            Margin="0,-2,0,0"
                                            VerticalAlignment="Center"
                                            Text="{x:Bind ViewModel.CurrentIndexDisplay, Mode=OneWay}" />
                                        <Button
                                            x:Uid="NextResultBtnAutomation"
                                            Padding="4"
                                            VerticalAlignment="Stretch"
                                            Command="{x:Bind ViewModel.NextCustomFormatCommand}"
                                            Content="{ui:FontIcon Glyph=&#xE76C;,
                                                                  FontSize=14}"
                                            Style="{StaticResource SubtleButtonStyle}">
                                            <ToolTipService.ToolTip>
                                                <TextBlock x:Uid="NextResultBtnToolTip" />
                                            </ToolTipService.ToolTip>
                                        </Button>
                                    </StackPanel>

                                    <Button
                                        x:Uid="RegenerateBtnAutomation"
                                        Grid.Column="1"
                                        VerticalAlignment="Stretch"
                                        Command="{x:Bind GenerateCustomAICommand}"
                                        Content="{ui:FontIcon Glyph=&#xE72C;,
                                                              FontSize=16}"
                                        Style="{StaticResource SubtleButtonStyle}">
                                        <ToolTipService.ToolTip>
                                            <TextBlock x:Uid="RegenerateBtnToolTip" />
                                        </ToolTipService.ToolTip>
                                    </Button>
                                    <Button
                                        x:Name="PreviewPasteBtn"
                                        x:Uid="PasteButtonAutomation"
                                        Grid.Column="2"
                                        HorizontalAlignment="Right"
                                        Click="PreviewPasteBtn_Click"
                                        Style="{StaticResource AccentButtonStyle}">
                                        <StackPanel Orientation="Horizontal" Spacing="8">
                                            <FontIcon FontSize="16" Glyph="&#xE77F;" />
                                            <TextBlock x:Uid="PasteText" />
                                        </StackPanel>
                                    </Button>
                                </Grid>
                            </Grid>
                        </Flyout>
                    </FlyoutBase.AttachedFlyout>
                </TextBox>
                <DropDownButton
                    x:Name="AIProviderButton"
                    x:Uid="AIProviderButton"
                    MinWidth="{StaticResource ModelSelectorButtonWidth}"
                    Margin="1,1,0,2"
                    Padding="0,0,4,0"
                    VerticalAlignment="Stretch"
                    BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
                    BorderThickness="0,0,1,0"
                    CornerRadius="16,0,0,16"
                    Style="{StaticResource SubtleDropDownButtonStyle}"
                    TabIndex="0"
                    Visibility="{x:Bind ViewModel.IsBusy, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
                    <ToolTipService.ToolTip>
                        <TextBlock Text="{x:Bind ViewModel.ActiveAIProviderTooltip, Mode=OneWay}" TextWrapping="WrapWholeWords" />
                    </ToolTipService.ToolTip>
                    <DropDownButton.Content>
                        <Image
                            x:Name="AIProviderIcon"
                            Width="16"
                            Height="16"
                            AutomationProperties.AccessibilityView="Raw"
                            Source="{x:Bind ViewModel.ActiveAIProvider?.ServiceType, Mode=OneWay, Converter={StaticResource ServiceTypeToIconConverter}}" />
                    </DropDownButton.Content>
                    <DropDownButton.Flyout>
                        <Flyout
                            Opened="AIProviderFlyout_Opened"
                            Placement="Bottom"
                            ShouldConstrainToRootBounds="False">
                            <Grid
                                Width="386"
                                Margin="-4"
                                RowSpacing="12">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBlock
                                    x:Uid="AIProvidersFlyoutHeader"
                                    Grid.Row="0"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
                                <ListView
                                    x:Name="AIProviderListView"
                                    Grid.Row="1"
                                    MaxHeight="320"
                                    Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                    BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
                                    BorderThickness="1"
                                    CornerRadius="{StaticResource OverlayCornerRadius}"
                                    ItemsSource="{x:Bind ViewModel.AIProviders, Mode=OneWay}"
                                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    ScrollViewer.VerticalScrollMode="Auto"
                                    SelectedItem="{x:Bind ViewModel.ActiveAIProvider, Mode=OneWay}"
                                    SelectionChanged="AIProviderListView_SelectionChanged"
                                    SelectionMode="Single"
                                    Visibility="{x:Bind ViewModel.AIProviders.Count, Mode=OneWay, Converter={StaticResource CountToVisibilityConverter}}">
                                    <ListView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical" Spacing="2" />
                                        </ItemsPanelTemplate>
                                    </ListView.ItemsPanel>
                                    <ListView.ItemTemplate>
                                        <DataTemplate x:DataType="settings:PasteAIProviderDefinition">
                                            <Grid Padding="0,8,0,8" ColumnSpacing="12">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="Auto" />
                                                </Grid.ColumnDefinitions>
                                                <Image
                                                    Width="20"
                                                    Height="20"
                                                    AutomationProperties.AccessibilityView="Raw"
                                                    Source="{x:Bind ServiceType, Mode=OneWay, Converter={StaticResource ServiceTypeToIconConverter}}" />
                                                <StackPanel
                                                    Grid.Column="1"
                                                    VerticalAlignment="Center"
                                                    Spacing="2">
                                                    <TextBlock Text="{x:Bind DisplayName, Mode=OneWay}" TextTrimming="CharacterEllipsis" />
                                                    <TextBlock
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                        Style="{StaticResource CaptionTextBlockStyle}"
                                                        Text="{x:Bind ServiceType, Mode=OneWay}" />
                                                </StackPanel>
                                                <Border
                                                    Grid.Column="2"
                                                    Padding="2,0,2,0"
                                                    VerticalAlignment="Center"
                                                    BorderBrush="{ThemeResource ControlStrokeColorSecondary}"
                                                    BorderThickness="1"
                                                    CornerRadius="{StaticResource ControlCornerRadius}"
                                                    Visibility="{x:Bind IsLocalModel, Mode=OneWay}">
                                                    <TextBlock
                                                        x:Uid="LocalModelBadge"
                                                        AutomationProperties.AccessibilityView="Raw"
                                                        FontSize="10"
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
                                                </Border>
                                                <!--<Border
                                                    Grid.Column="2"
                                                    Padding="2,0,2,0"
                                                    VerticalAlignment="Center"
                                                    BorderBrush="{ThemeResource TertiaryButtonBorderBrush}"
                                                    BorderThickness="1"
                                                    CornerRadius="{StaticResource ControlCornerRadius}"
                                                    Visibility="{x:Bind EnableAdvanceAI}">
                                                    <TextBlock
                                                        AutomationProperties.AccessibilityView="Raw"
                                                        FontSize="10"
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                        Text="ADVANCED" />
                                                </Border>-->
                                            </Grid>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                                <TextBlock
                                    x:Uid="AIProvidersEmptyText"
                                    Grid.Row="1"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    TextWrapping="WrapWholeWords"
                                    Visibility="{x:Bind ViewModel.AIProviders.Count, Mode=OneWay, Converter={StaticResource CountToInvertedVisibilityConverter}}" />
                                <HyperlinkButton
                                    x:Uid="AIProvidersManageButtonContent"
                                    Grid.Row="2"
                                    HorizontalAlignment="Right"
                                    Command="{x:Bind ViewModel.OpenSettingsCommand, Mode=OneWay}" />
                            </Grid>
                        </Flyout>
                    </DropDownButton.Flyout>
                </DropDownButton>
                <Grid
                    Width="32"
                    Height="32"
                    Margin="0,0,4,0"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Stretch">
                    <Button
                        x:Name="SendBtn"
                        x:Uid="SendButtonAutomation"
                        Padding="0"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        ui:VisualExtensions.NormalizedCenterPoint="0.5,0.5"
                        AutomationProperties.HelpText="{x:Bind ViewModel.CustomAIUnavailableErrorText, Mode=OneWay}"
                        Command="{x:Bind GenerateCustomAICommand}"
                        Content="{ui:FontIcon Glyph=&#xE724;,
                                              FontSize=16}"
                        IsEnabled="{x:Bind ViewModel.IsCustomAIAvailable, Mode=OneWay}"
                        Style="{StaticResource SubtleButtonStyle}"
                        TabIndex="2"
                        Visibility="{x:Bind ViewModel.Query.Length, Mode=OneWay, Converter={StaticResource CountToVisibilityConverter}}">
                        <ToolTipService.ToolTip>
                            <TextBlock x:Uid="SendBtnToolTip" TextWrapping="WrapWholeWords" />
                        </ToolTipService.ToolTip>
                        <animations:Implicit.ShowAnimations>
                            <animations:ScaleAnimation
                                From="0.4"
                                To="1"
                                Duration="0:0:0.167" />
                            <animations:OpacityAnimation
                                From="0.0"
                                To="1.0"
                                Duration="0:0:0.167" />
                        </animations:Implicit.ShowAnimations>
                        <animations:Implicit.HideAnimations>
                            <animations:ScaleAnimation
                                From="1"
                                To="0.4"
                                Duration="0:0:0.167" />
                            <animations:OpacityAnimation
                                From="1.0"
                                To="0.0"
                                Duration="0:0:0.167" />
                        </animations:Implicit.HideAnimations>
                    </Button>
                    <Button
                        x:Name="CancelBtn"
                        x:Uid="CancelBtnAutomation"
                        Padding="0"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        ui:VisualExtensions.NormalizedCenterPoint="0.5,0.5"
                        Command="{x:Bind CancelPasteActionCommand}"
                        Content="{ui:FontIcon Glyph=&#xE711;,
                                              FontSize=16}"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        IsEnabled="False"
                        Style="{StaticResource SubtleButtonStyle}"
                        Visibility="Collapsed">
                        <ToolTipService.ToolTip>
                            <TextBlock x:Uid="CancelBtnToolTip" TextWrapping="WrapWholeWords" />
                        </ToolTipService.ToolTip>
                    </Button>
                    <!--  Transparent overlay to show tooltip  -->
                    <Grid
                        x:Name="SendBtnOverlay"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch"
                        Background="Transparent"
                        Visibility="{x:Bind ViewModel.IsCustomAIAvailable, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
                        <ToolTipService.ToolTip>
                            <ToolTip Content="{x:Bind ViewModel.CustomAIUnavailableErrorText, Mode=OneWay}" />
                        </ToolTipService.ToolTip>
                    </Grid>
                </Grid>
            </Grid>
        </local:AnimatedContentControl>
        <ContentPresenter
            x:Name="DisclaimerPresenter"
            Grid.Row="1"
            Margin="8,8,12,0"
            VerticalAlignment="Top"
            Content="{x:Bind Footer, Mode=OneWay}">
            <animations:Implicit.ShowAnimations>
                <animations:OpacityAnimation To="1.0" Duration="0:0:0.4" />
            </animations:Implicit.ShowAnimations>
            <animations:Implicit.HideAnimations>
                <animations:OpacityAnimation To="0.0" Duration="0:0:0.167" />
            </animations:Implicit.HideAnimations>
        </ContentPresenter>
        <TextBlock
            x:Name="LoadingText"
            x:Uid="LoadingText"
            Grid.Row="1"
            Margin="4,4,0,0"
            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
            Style="{StaticResource CaptionTextBlockStyle}"
            Visibility="Collapsed">
            <animations:Implicit.ShowAnimations>
                <animations:OpacityAnimation To="1.0" Duration="0:0:0.6" />
            </animations:Implicit.ShowAnimations>
            <animations:Implicit.HideAnimations>
                <animations:OpacityAnimation To="0.0" Duration="0:0:0.167" />
            </animations:Implicit.HideAnimations>
        </TextBlock>
        <Grid
            x:Name="ErrorMessageGrid"
            x:Uid="ErrorMessageGrid"
            Grid.Row="1"
            Margin="8,8,0,0"
            ColumnSpacing="8"
            Visibility="Collapsed">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" Orientation="Horizontal">
                <ToolTipService.ToolTip>
                    <ToolTip VerticalOffset="-105" Visibility="{x:Bind ViewModel.PasteActionError.HasDetails, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                        <StackPanel
                            MinWidth="300"
                            HorizontalAlignment="Stretch"
                            Orientation="Vertical">
                            <TextBox
                                x:Name="AIErrorMessage"
                                x:Uid="AIErrorMessage"
                                FontSize="12"
                                IsReadOnly="True"
                                Text="{x:Bind ViewModel.PasteActionError.Details, Mode=OneWay}"
                                TextWrapping="Wrap" />
                        </StackPanel>
                    </ToolTip>
                </ToolTipService.ToolTip>
                <FontIcon
                    Margin="0,3,3,0"
                    VerticalAlignment="Top"
                    FontSize="12"
                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                    Glyph="&#xE946;"
                    Visibility="{x:Bind ViewModel.PasteActionError.HasDetails, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
                <TextBlock
                    FontWeight="SemiBold"
                    Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{x:Bind ViewModel.PasteActionError.Text, Mode=OneWay}" />
            </StackPanel>
            <HyperlinkButton
                x:Uid="SettingsBtn"
                Grid.Column="1"
                Margin="0,-1,0,0"
                Padding="0"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Command="{x:Bind ViewModel.OpenSettingsCommand}"
                FontSize="12" />
            <animations:Implicit.ShowAnimations>
                <animations:OpacityAnimation To="1.0" Duration="0:0:0.6" />
            </animations:Implicit.ShowAnimations>
            <animations:Implicit.HideAnimations>
                <animations:OpacityAnimation To="0.0" Duration="0:0:0.167" />
            </animations:Implicit.HideAnimations>
        </Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="DefaultState" />
                <VisualState x:Name="LoadingState">
                    <VisualState.Setters>
                        <Setter Target="Loader.IsLoading" Value="True" />
                        <Setter Target="InputTxtBox.IsEnabled" Value="False" />
                        <Setter Target="SendBtn.IsEnabled" Value="False" />
                        <Setter Target="SendBtn.Visibility" Value="Collapsed" />
                        <Setter Target="SendBtnOverlay.Visibility" Value="Collapsed" />
                        <Setter Target="CancelBtn.IsEnabled" Value="True" />
                        <Setter Target="CancelBtn.Visibility" Value="Visible" />
                        <Setter Target="DisclaimerPresenter.Visibility" Value="Collapsed" />
                        <Setter Target="LoadingText.Visibility" Value="Visible" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="ErrorState">
                    <VisualState.Setters>
                        <Setter Target="InputTxtBox.BorderBrush" Value="{ThemeResource SystemFillColorCriticalBrush}" />
                        <Setter Target="DisclaimerPresenter.Visibility" Value="Collapsed" />
                        <Setter Target="ErrorMessageGrid.Visibility" Value="Visible" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</UserControl>
