<?xml version="1.0" encoding="utf-8" ?>
<local:ChatMessageItemControlBase
    x:Class="RodelAgent.UI.Controls.Chat.ChatMessageItemControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:RodelAgent.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:RodelAgent.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:RodelAgent.UI.Controls.Chat"
    xmlns:markdown="using:RodelAgent.UI.Controls.Markdown"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid ColumnSpacing="8">
        <controls:CardPanel
            x:Name="RootCard"
            HorizontalAlignment="Stretch"
            HorizontalContentAlignment="Stretch"
            Background="Transparent"
            DisabledBackground="Transparent"
            PointerOverBackground="Transparent"
            PressedBackground="Transparent">
            <Grid
                Background="{ThemeResource ControlFillColorTransparentBrush}"
                PointerEntered="OnCardPointerEntered"
                PointerExited="OnCardPointerExited"
                PointerMoved="OnCardPointerMoved">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="LeftColumn" Width="*" />
                    <ColumnDefinition x:Name="RightColumn" Width="0.2*" />
                </Grid.ColumnDefinitions>

                <Grid
                    x:Name="MessageContainer"
                    HorizontalAlignment="Left"
                    RowSpacing="4">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <controls:PresetAvatar
                        x:Name="Avatar"
                        Width="32"
                        Height="32"
                        Margin="0,0,8,0"
                        VerticalAlignment="Top"
                        CornerRadius="18"
                        DefaultSymbol="Person"
                        FontSize="16"
                        PresetId="{x:Bind ViewModel.AgentId, Mode=OneWay}"
                        Visibility="{x:Bind ViewModel.AgentId, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
                    <Rectangle
                        x:Name="MessageBackground"
                        Grid.Column="1"
                        Fill="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                        RadiusX="4"
                        RadiusY="4"
                        Stroke="{ThemeResource ControlStrokeColorDefaultBrush}"
                        StrokeThickness="1" />
                    <Grid
                        x:Name="TextContainer"
                        Grid.Column="1"
                        Padding="12,8"
                        Visibility="{x:Bind ViewModel.IsEditing, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                        <markdown:MarkdownTextBlock
                            x:Name="MarkdownMessageBlock"
                            Background="Transparent"
                            Foreground="{ThemeResource TextFillColorPrimaryBrush}"
                            Text="{x:Bind ViewModel.Content, Mode=OneWay}" />
                    </Grid>

                    <Grid
                        x:Name="EditContainer"
                        Grid.Column="1"
                        Padding="12"
                        Background="{ThemeResource ControlSolidFillColorDefaultBrush}"
                        CornerRadius="{StaticResource ControlCornerRadius}"
                        RowSpacing="12"
                        Visibility="{x:Bind ViewModel.IsEditing, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBox
                            x:Name="Editor"
                            MaxHeight="500"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            AcceptsReturn="True"
                            TextWrapping="Wrap" />
                        <Grid Grid.Row="1" ColumnSpacing="12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Button
                                HorizontalAlignment="Stretch"
                                Click="OnEditorConfirmButtonClick"
                                Style="{StaticResource AccentButtonStyle}">
                                <StackPanel Orientation="Horizontal" Spacing="8">
                                    <ic:SymbolIcon
                                        Margin="0,2,0,0"
                                        VerticalAlignment="Center"
                                        FontSize="14"
                                        Symbol="Checkmark" />
                                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Confirm}" />
                                </StackPanel>
                            </Button>
                            <Button
                                Grid.Column="1"
                                HorizontalAlignment="Stretch"
                                Click="OnEditorCancelButtonClick">
                                <StackPanel Orientation="Horizontal" Spacing="8">
                                    <ic:SymbolIcon
                                        Margin="0,2,0,0"
                                        VerticalAlignment="Center"
                                        FontSize="14"
                                        Symbol="Dismiss" />
                                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Cancel}" />
                                </StackPanel>
                            </Button>
                        </Grid>
                    </Grid>

                    <StackPanel
                        Grid.Row="1"
                        Grid.Column="1"
                        Margin="0,0,0,8"
                        HorizontalAlignment="Left"
                        Orientation="Horizontal">
                        <TextBlock
                            x:Name="SenderBlock"
                            Margin="0,0,8,0"
                            FontSize="12"
                            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                            Style="{StaticResource CaptionTextBlockStyle}"
                            Visibility="{x:Bind ViewModel.Author, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                            <Run Text="{x:Bind ViewModel.Author, Mode=OneWay}" />
                        </TextBlock>
                        <TextBlock
                            x:Name="TimeBlock"
                            FontSize="12"
                            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                            Style="{StaticResource CaptionTextBlockStyle}"
                            Text="{x:Bind ViewModel.Time, Mode=OneWay}"
                            Visibility="{x:Bind ViewModel.Time, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
                    </StackPanel>

                </Grid>

                <StackPanel
                    x:Name="OptionsContainer"
                    Grid.ColumnSpan="2"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Bottom"
                    Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}"
                    BorderBrush="{ThemeResource ControlStrokeColorDefaultBrush}"
                    BorderThickness="1"
                    CornerRadius="{StaticResource ControlCornerRadius}"
                    Orientation="Horizontal"
                    Visibility="Collapsed">
                    <Button
                        x:Name="CopyButton"
                        AutomationProperties.Name="{ext:Locale Name=Copy}"
                        Command="{x:Bind ViewModel.CopyCommand, Mode=OneWay}"
                        Style="{StaticResource MiniIconButtonStyle}"
                        ToolTipService.ToolTip="{ext:Locale Name=Copy}">
                        <ic:SymbolIcon FontSize="12" Symbol="Copy" />
                    </Button>
                    <Button
                        x:Name="EditButton"
                        AutomationProperties.Name="{ext:Locale Name=Modify}"
                        Click="OnEditButtonClick"
                        Style="{StaticResource MiniIconButtonStyle}"
                        ToolTipService.ToolTip="{ext:Locale Name=Modify}">
                        <ic:SymbolIcon FontSize="12" Symbol="Edit" />
                    </Button>
                    <Button
                        x:Name="DeleteButton"
                        AutomationProperties.Name="{ext:Locale Name=Delete}"
                        Command="{x:Bind ViewModel.DeleteCommand, Mode=OneWay}"
                        Style="{StaticResource MiniIconButtonStyle}"
                        ToolTipService.ToolTip="{ext:Locale Name=Delete}">
                        <ic:SymbolIcon
                            FontSize="12"
                            Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                            Symbol="Delete" />
                    </Button>
                </StackPanel>
            </Grid>

        </controls:CardPanel>


        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="LayoutGroup">
                <VisualStateGroup.States>
                    <VisualState x:Name="AssistantState" />
                    <VisualState x:Name="MyState">
                        <VisualState.Setters>
                            <Setter Target="MessageBackground.Fill" Value="{ThemeResource AccentFillColorDefaultBrush}" />
                            <Setter Target="MessageBackground.Stroke" Value="{ThemeResource ControlStrokeColorOnAccentDefaultBrush}" />
                            <Setter Target="MarkdownMessageBlock.Foreground" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
                            <Setter Target="LeftColumn.Width" Value="0.2*" />
                            <Setter Target="RightColumn.Width" Value="*" />
                            <Setter Target="LeftColumn.MinWidth" Value="20" />
                            <Setter Target="RightColumn.MinWidth" Value="0" />
                            <Setter Target="MessageContainer.(Grid.Column)" Value="1" />
                            <Setter Target="MessageContainer.HorizontalAlignment" Value="Right" />
                            <Setter Target="TimeBlock.HorizontalAlignment" Value="Right" />
                            <Setter Target="OptionsContainer.HorizontalAlignment" Value="Right" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup.States>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</local:ChatMessageItemControlBase>
