<?xml version="1.0" encoding="utf-8" ?>
<local:AIControlBase
    x:Class="BiliCopilot.UI.Controls.AI.AIHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ai="using:Richasy.WinUIKernel.AI"
    xmlns:aiVM="using:Richasy.WinUIKernel.AI.ViewModels"
    xmlns:components="using:BiliCopilot.UI.Controls.Components"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:items="using:BiliCopilot.UI.ViewModels.Items"
    xmlns:local="using:BiliCopilot.UI.Controls.AI"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <UserControl.Resources>
        <DataTemplate x:Key="ServiceItemTemplate" x:DataType="aiVM:ChatServiceItemViewModel">
            <Button
                Padding="12,8"
                HorizontalAlignment="Stretch"
                HorizontalContentAlignment="Left"
                Click="OnServiceItemClick"
                DataContext="{x:Bind}">
                <Grid ColumnSpacing="12">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <ai:AILogo
                        Width="28"
                        Height="28"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"
                        IsAvatar="True"
                        Provider="{x:Bind ProviderType}" />
                    <TextBlock
                        Grid.Column="1"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"
                        MaxLines="1"
                        Text="{x:Bind Name}"
                        TextTrimming="CharacterEllipsis" />
                </Grid>
            </Button>
        </DataTemplate>
    </UserControl.Resources>

    <Grid Padding="12,0" ColumnSpacing="4">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal">
            <ai:AILogo
                Width="28"
                Height="28"
                VerticalAlignment="Center"
                IsAvatar="True"
                Provider="{x:Bind ViewModel.SelectedService.ProviderType, Mode=OneWay}" />
            <TextBlock
                Margin="12,0,0,0"
                VerticalAlignment="Center"
                Style="{StaticResource BodyStrongTextBlockStyle}"
                Text="{x:Bind ViewModel.SelectedService.Name, Mode=OneWay}" />
            <Button
                Margin="8,0,0,0"
                VerticalAlignment="Center"
                Style="{StaticResource SmallIconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=ShowMore}">
                <ic:SymbolIcon
                    FontSize="14"
                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                    IconVariant="Filled"
                    Symbol="ChevronCircleDown" />
                <Button.Flyout>
                    <Flyout
                        x:Name="ServiceFlyout"
                        Placement="Bottom"
                        ShouldConstrainToRootBounds="False">
                        <Flyout.FlyoutPresenterStyle>
                            <Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
                                <Setter Property="Padding" Value="8" />
                            </Style>
                        </Flyout.FlyoutPresenterStyle>
                        <ItemsRepeater
                            x:Name="ServiceRepeater"
                            Width="240"
                            ItemTemplate="{StaticResource ServiceItemTemplate}"
                            ItemsSource="{x:Bind ViewModel.Services, Mode=OneWay}">
                            <ItemsRepeater.Layout>
                                <StackLayout Spacing="6" />
                            </ItemsRepeater.Layout>
                        </ItemsRepeater>
                    </Flyout>
                </Button.Flyout>
            </Button>
        </StackPanel>
        <ComboBox
            Grid.Column="2"
            VerticalAlignment="Center"
            ItemsSource="{x:Bind ViewModel.Models, Mode=OneWay}"
            SelectedItem="{x:Bind ViewModel.SelectedModel, Mode=TwoWay}"
            Visibility="{x:Bind ViewModel.IsNoModel, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <ComboBox.ItemTemplate>
                <DataTemplate x:DataType="aiVM:ChatModelItemViewModel">
                    <TextBlock Text="{x:Bind Name}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </Grid>
</local:AIControlBase>
