<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
    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:ext="using:RodelAgent.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:RodelAgent.UI.Controls.Items">

    <Style BasedOn="{StaticResource DefaultChatPluginItemControlStyle}" TargetType="local:ChatPluginItemControl" />

    <Style x:Key="DefaultChatPluginItemControlStyle" TargetType="local:ChatPluginItemControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ChatPluginItemControl">
                    <controls:CardPanel
                        x:Name="RootCard"
                        AutomationProperties.Name="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Name}"
                        Background="Transparent">

                        <controls:CardPanel.ContextFlyout>
                            <MenuFlyout>
                                <MenuFlyoutItem Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.OpenFolderCommand}" Text="{ext:Locale Name=OpenDirectory}">
                                    <MenuFlyoutItem.Icon>
                                        <ic:SymbolIcon Symbol="FolderOpen" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.DeletePluginCommand}"
                                    Text="{ext:Locale Name=Delete}"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsDeleting, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                                    <MenuFlyoutItem.Icon>
                                        <ic:SymbolIcon Foreground="{ThemeResource SystemFillColorCriticalBrush}" Symbol="Delete" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                                <MenuFlyoutItem
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.CancelDeletePluginCommand}"
                                    Text="{ext:Locale Name=CancelDeletePlugin}"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsDeleting}">
                                    <MenuFlyoutItem.Icon>
                                        <ic:SymbolIcon Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Symbol="DeleteOff" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </controls:CardPanel.ContextFlyout>

                        <Grid Margin="12,8" ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid>
                                <controls:PluginAvatar
                                    Width="32"
                                    Height="32"
                                    CornerRadius="16"
                                    FontSize="14"
                                    Id="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Id}"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsDeleting, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                                <Border
                                    Width="32"
                                    Height="32"
                                    Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                    CornerRadius="16"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsDeleting}">
                                    <ic:SymbolIcon
                                        FontSize="14"
                                        Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                                        Symbol="Delete" />
                                </Border>
                            </Grid>

                            <StackPanel Grid.Column="1">
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    FontWeight="Bold"
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Name}"
                                    TextTrimming="CharacterEllipsis" />
                                <TextBlock
                                    HorizontalAlignment="Left"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                    MaxLines="1"
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Description}"
                                    TextTrimming="CharacterEllipsis" />
                            </StackPanel>
                            <Border
                                Grid.Column="2"
                                Padding="4,2"
                                VerticalAlignment="Center"
                                Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                CornerRadius="2"
                                ToolTipService.ToolTip="{ext:Locale Name=FunctionCount}">
                                <TextBlock
                                    FontSize="10"
                                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.FunctionCount}"
                                    TextAlignment="Center" />
                            </Border>
                        </Grid>

                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="SessionChatPluginItemControlStyle" TargetType="local:ChatPluginItemControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ChatPluginItemControl">
                    <controls:CardPanel
                        x:Name="RootCard"
                        MinWidth="200"
                        AutomationProperties.Name="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Name}"
                        Background="Transparent"
                        IsChecked="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsSelected, Mode=TwoWay}"
                        IsEnableCheck="True">

                        <Grid Margin="12,8" ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Grid VerticalAlignment="Center">
                                <ic:SymbolIcon
                                    FontSize="14"
                                    Foreground="{ThemeResource SystemFillColorSuccessBrush}"
                                    Symbol="CheckmarkCircle"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsSelected}" />
                                <ic:SymbolIcon
                                    FontSize="14"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                    Symbol="Circle"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsSelected, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                            </Grid>

                            <TextBlock
                                Grid.Column="1"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Style="{StaticResource CaptionTextBlockStyle}"
                                Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Name}"
                                TextTrimming="CharacterEllipsis" />
                        </Grid>
                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
