<?xml version="1.0" encoding="utf-8" ?>
<base:LayoutUserControlBase
    x:Class="BiliCopilot.UI.Controls.Components.EmoteTextBlock"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:appearance="using:Richasy.BiliKernel.Models.Appearance"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:BiliCopilot.UI.Controls.Components"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <RichTextBlock
            x:Name="RichBlock"
            FontFamily="{x:Bind FontFamily, Mode=OneWay}"
            FontSize="{x:Bind FontSize, Mode=OneWay}"
            FontWeight="{x:Bind FontWeight, Mode=OneWay}"
            Foreground="{x:Bind Foreground, Mode=OneWay}"
            IsTextSelectionEnabled="True"
            IsTextTrimmedChanged="OnTextTrimChanged"
            LineHeight="24"
            MaxLines="{x:Bind MaxLines, Mode=OneWay}"
            TextTrimming="CharacterEllipsis"
            TextWrapping="Wrap" />

        <ItemsRepeater
            x:Name="Gallery"
            Grid.Row="1"
            x:Load="False"
            Visibility="Collapsed">
            <ItemsRepeater.ItemTemplate>
                <DataTemplate x:DataType="appearance:BiliImage">
                    <Grid
                        Width="120"
                        Height="120"
                        CornerRadius="{StaticResource ControlCornerRadius}">
                        <Image
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            DataContext="{x:Bind}"
                            Source="{x:Bind Uri, Converter={StaticResource BitmapConverter}}"
                            Stretch="UniformToFill"
                            Tapped="OnImageTapped" />
                    </Grid>
                </DataTemplate>
            </ItemsRepeater.ItemTemplate>
            <ItemsRepeater.Layout>
                <ColumnMajorUniformToLargestGridLayout
                    ColumnSpacing="4"
                    MaxColumns="3"
                    RowSpacing="4" />
            </ItemsRepeater.Layout>
        </ItemsRepeater>

        <Button
            x:Name="OverflowButton"
            Grid.Row="2"
            Margin="0,4,0,0"
            Padding="6,4"
            BorderThickness="0"
            Visibility="Collapsed">
            <ic:SymbolIcon FontSize="12" Symbol="MoreHorizontal" />
            <Button.Flyout>
                <Flyout Opened="OnOverflowFlyoutOpened" ShouldConstrainToRootBounds="False">
                    <RichTextBlock
                        x:Name="FlyoutRichBlock"
                        MaxWidth="360"
                        IsTextSelectionEnabled="True"
                        LineHeight="24"
                        TextWrapping="Wrap" />
                </Flyout>
            </Button.Flyout>
        </Button>
    </Grid>
</base:LayoutUserControlBase>
