<?xml version="1.0" encoding="utf-8" ?>
<local:ChatGroupControlBase
    x:Class="RodelAgent.UI.Controls.Chat.ChatGroupHistory"
    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:base="using:Richasy.WinUI.Share.Base"
    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: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>
        <base:EmptyHolder
            Title="{ext:Locale Name=NoMessage}"
            Description="{ext:Locale Name=NoMessageDescription}"
            Emoji="&#x1F37B;"
            Visibility="{x:Bind ViewModel.IsChatEmpty, Mode=OneWay}" />
        <ScrollViewer
            x:Name="MessageViewer"
            Style="{StaticResource PageScrollViewerStyle}"
            UseLayoutRounding="False">
            <Grid Margin="0,12,0,0">
                <StackPanel>
                    <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>

                    <StackPanel
                        Margin="0,0,0,12"
                        Padding="20,12"
                        HorizontalAlignment="Center"
                        Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                        BorderBrush="{ThemeResource SystemFillColorCriticalBrush}"
                        BorderThickness="1"
                        CornerRadius="{ThemeResource ControlCornerRadius}"
                        Spacing="8"
                        Visibility="{x:Bind ViewModel.ErrorText, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                        <TextBlock
                            x:Name="ErrorBlock"
                            MaxWidth="240"
                            HorizontalAlignment="Center"
                            MaxLines="3"
                            Style="{StaticResource CaptionTextBlockStyle}"
                            Text="{x:Bind ViewModel.ErrorText, Mode=OneWay}"
                            TextAlignment="Center"
                            TextWrapping="Wrap">
                            <ToolTipService.ToolTip>
                                <ToolTip Content="{x:Bind ViewModel.ErrorText, Mode=OneWay}" IsEnabled="{x:Bind ErrorBlock.IsTextTrimmed, Mode=OneWay}" />
                            </ToolTipService.ToolTip>
                        </TextBlock>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </ScrollViewer>
    </Grid>
</local:ChatGroupControlBase>
