<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
             xmlns:local="clr-namespace:MauiApp6"
             x:Class="MauiApp6.MainPage">
    
    <ContentPage.Resources>
        <telerik:BoolToValueConverter x:Key="BoolToValueConverter" TrueValue="-1" FalseValue="0" />
        <local:SimpleChatItemConverter x:Key="SimpleChatItemConverter" />
        
        <ControlTemplate x:Key="MyRadChatControlTemplate">
            <Grid IsClippedToBounds="True">
                <Grid IsClippedToBounds="True"
                      RowSpacing="2"
                       RowDefinitions="*, Auto">
                    <Grid Margin="{OnPlatform Default='10, 10, 10, 0', WinUI='0, 10, 0, 0', MacCatalyst='0, 10, 0, 0'}">
                        <telerik:RadChatListView x:Name="ChatListView"
                                             AutoScrollMode="{TemplateBinding AutoScrollMode}"
                                             ScrollMediator="{TemplateBinding ActualScrollMediator}"
                                             ItemTemplate="{TemplateBinding ItemTemplateSelector}"
                                             ItemsSource="{TemplateBinding Items}"
                                             AutomationId="RadChatListView" />
                        <telerik:RadContentView VerticalOptions="End"
                                                 Content="{TemplateBinding TypingIndicator}"
                                                 HeightRequest="{TemplateBinding TypingIndicator.IsVisible, Converter={StaticResource BoolToValueConverter}}"
                                                 Padding="{OnPlatform Default=0, WinUI='10, 0', MacCatalyst='12, 0'}" />
                        <telerik:RadContentView x:Name="PickerContainer"
                                                 VerticalOptions="End"
                                                 Content="{TemplateBinding Picker}"
                                                 HeightRequest="{TemplateBinding Picker.IsVisible, Converter={StaticResource BoolToValueConverter}}"
                                                 MaximumHeightRequest="{Binding Height, Source={x:Reference ChatListView}}"
                                                 Padding="{OnPlatform Default=0, WinUI='10, 0', MacCatalyst='12, 0'}" />
                    </Grid>
                    <!--<Grid x:Name="PART_InputAreaGrid"
                         Grid.Row="1"
                         ColumnDefinitions="*, Auto"
                         Padding="10">
                        <telerik:ChatEntry x:Name="PART_ChatEntry"
                                     ReserveSpaceForErrorView="False"
                                     Keyboard="Chat"
                                     Text="{TemplateBinding Message, Mode=TwoWay}"
                                     HeightRequest="{OnPlatform Default=36, WinUI=32, MacCatalyst=28, Android=44}"
                                     ReturnCommand="{TemplateBinding ActualSendMessageCommand}"
                                     BackgroundColor="Transparent"
                                     VerticalOptions="Center"
                                     AutomationId="RadChatEntry"/>
                        <ImageButton x:Name="PART_SendMessageButton"
                             Grid.Column="1"
                             Opacity="0.6"
                             Padding="0"
                             Margin="10, 0, 0, 0"
                             Command="{TemplateBinding ActualSendMessageCommand}"
                             Source="{Binding SendMessageButtonImage, Source={RelativeSource Mode=TemplatedParent}}"
                             BackgroundColor="Transparent"
                             BorderColor="Transparent"
                             WidthRequest="{OnPlatform Default=24, WinUI=22}"
                             Aspect="AspectFit"
                             VerticalOptions="Center" 
                             AutomationId="RadChatSendMessageButton"/>
                    </Grid>-->
                </Grid>
            </Grid>
        </ControlTemplate>

        <DataTemplate x:Key="ImportantMessageTemplate">
            <StackLayout>
                    <Grid HorizontalOptions="StartAndExpand" 
                          RowDefinitions="Auto"
                          ColumnDefinitions="Auto,Auto">

                        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" HorizontalTextAlignment="Start"                         
                        FontAttributes="Bold"
                        Text="TAG" 
                        BackgroundColor="Gray"/>

                        <Label Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="End" Margin="5,10,0,0" 
                        Text="Condition" />

                        <Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalTextAlignment="Start" 
                        Margin="5,10,0,0" 
                        Text="{Binding Text}" />

                    </Grid>
            </StackLayout>
        </DataTemplate>
    </ContentPage.Resources>

    <Grid>
        <telerik:RadChat 
            x:Name="chat"
            Author="{Binding AuthorMe}"
            ItemsSource="{Binding Items}"
            ControlTemplate="{StaticResource MyRadChatControlTemplate}"
            ItemConverter="{StaticResource SimpleChatItemConverter}"
            ItemTemplateSelector="{StaticResource CustomChatItemTemplateSelector}"/>
    </Grid>

</ContentPage>
