<?xml version="1.0" encoding="utf-8" ?>
<local:ChatServicePageControlBase
    x:Class="RodelAgent.UI.Controls.Chat.ChatPluginSection"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    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:items="using:RodelAgent.UI.ViewModels.Items"
    xmlns:itemscontrol="using:RodelAgent.UI.Controls.Items"
    xmlns:local="using:RodelAgent.UI.Controls.Chat"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid Visibility="{x:Bind ViewModel.IsPluginEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <StackPanel>
                <TextBlock
                    Margin="12,4"
                    VerticalAlignment="Center"
                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                    Style="{StaticResource CaptionTextBlockStyle}"
                    Text="{ext:Locale Name=Plugins}" />
                <ItemsRepeater ItemsSource="{x:Bind ViewModel.Plugins}">
                    <ItemsRepeater.ItemTemplate>
                        <DataTemplate x:DataType="items:ChatPluginItemViewModel">
                            <itemscontrol:ChatPluginItemControl Click="OnPluginItemClick" ViewModel="{x:Bind}">
                                <FlyoutBase.AttachedFlyout>
                                    <Flyout Placement="Bottom">
                                        <StackPanel Width="280" Spacing="8">
                                            <TextBlock
                                                HorizontalAlignment="Left"
                                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                Style="{StaticResource CaptionTextBlockStyle}"
                                                Text="{ext:Locale Name=FunctionList}" />
                                            <ItemsRepeater ItemsSource="{x:Bind Functions}">
                                                <ItemsRepeater.ItemTemplate>
                                                    <DataTemplate x:DataType="items:ChatPluginFunctionItemViewModel">
                                                        <Grid
                                                            Padding="0,8"
                                                            BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
                                                            BorderThickness="0,0,0,1"
                                                            RowSpacing="2">
                                                            <Grid.RowDefinitions>
                                                                <RowDefinition Height="Auto" />
                                                                <RowDefinition Height="Auto" />
                                                            </Grid.RowDefinitions>
                                                            <TextBlock
                                                                MaxLines="1"
                                                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                                                Text="{x:Bind Name}"
                                                                TextTrimming="CharacterEllipsis" />
                                                            <TextBlock
                                                                Grid.Row="1"
                                                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                                MaxLines="2"
                                                                Style="{StaticResource CaptionTextBlockStyle}"
                                                                Text="{x:Bind Description}"
                                                                TextTrimming="CharacterEllipsis"
                                                                TextWrapping="Wrap" />
                                                        </Grid>
                                                    </DataTemplate>
                                                </ItemsRepeater.ItemTemplate>
                                                <ItemsRepeater.Layout>
                                                    <StackLayout Spacing="0" />
                                                </ItemsRepeater.Layout>
                                            </ItemsRepeater>
                                        </StackPanel>
                                    </Flyout>
                                </FlyoutBase.AttachedFlyout>
                            </itemscontrol:ChatPluginItemControl>
                        </DataTemplate>
                    </ItemsRepeater.ItemTemplate>
                    <ItemsRepeater.Layout>
                        <StackLayout Spacing="4" />
                    </ItemsRepeater.Layout>
                </ItemsRepeater>
            </StackPanel>
            <ProgressRing
                Width="28"
                Height="28"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                IsActive="{x:Bind ViewModel.IsPluginLoading, Mode=OneWay}" />
        </Grid>

        <base:EmptyHolder
            Title="{ext:Locale Name=NoPlugins}"
            Description="{ext:Locale Name=NoPluginsDescription}"
            Emoji="&#x1F4CE;"
            Visibility="{x:Bind ViewModel.IsPluginEmpty, Mode=OneWay}">
            <base:EmptyHolder.ActionElement>
                <HyperlinkButton
                    Content="{ext:Locale Name=SeeDocument}"
                    FontSize="12"
                    NavigateUri="https://agent.richasy.net/chat-tools" />
            </base:EmptyHolder.ActionElement>
        </base:EmptyHolder>
    </Grid>
</local:ChatServicePageControlBase>
