<?xml version="1.0" encoding="utf-8" ?>
<local:ChatServicePageBase
    x:Class="RodelAgent.UI.Pages.ChatServicePage"
    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:chat="using:RodelAgent.UI.Controls.Chat"
    xmlns:community="using:CommunityToolkit.WinUI.Controls"
    xmlns:controls="using:RodelAgent.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:RodelAgent.UI.Extensions"
    xmlns:local="using:RodelAgent.UI.Pages"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <base:EmptyHolder
            Title="{ext:Locale Name=NoAvailableService}"
            Description="{ext:Locale Name=NoAvailableServiceDescription}"
            Emoji="&#x1FAE3;"
            Visibility="{x:Bind ViewModel.IsAvailableServicesEmpty, Mode=OneWay}" />
        <Grid Visibility="{x:Bind ViewModel.IsAvailableServicesEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="{x:Bind ViewModel.NavColumnWidth, Mode=OneWay, Converter={StaticResource GridLengthConverter}}" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="{x:Bind ViewModel.ExtraColumnWidth, Mode=OneWay, Converter={StaticResource GridLengthConverter}}" />
            </Grid.ColumnDefinitions>

            <Grid.ChildrenTransitions>
                <RepositionThemeTransition IsStaggeringEnabled="False" />
            </Grid.ChildrenTransitions>

            <Grid Margin="0,0,-6,0" Visibility="{x:Bind ViewModel.IsNavColumnManualHide, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <chat:ChatServiceHeader Margin="0,0,0,8" />
                <ScrollViewer
                    Grid.Row="1"
                    Padding="8,0"
                    Style="{StaticResource PageScrollViewerStyle}">
                    <Grid Margin="0,0,0,12">
                        <StackPanel Visibility="{x:Bind ViewModel.IsServiceSectionVisible, Mode=OneWay}">
                            <chat:AvailableChatServiceSection Margin="0,0,0,12" />
                            <chat:AgentsSection Margin="0,0,0,12" Visibility="{x:Bind ViewModel.IsAgentsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                            <chat:SessionPresetsSection Visibility="{x:Bind ViewModel.IsSessionPresetsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                            <chat:GroupsSection Visibility="{x:Bind ViewModel.IsGroupsEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                        </StackPanel>
                        <chat:ChatPluginSection Visibility="{x:Bind ViewModel.IsPluginSectionVisible, Mode=OneWay}" />
                    </Grid>
                </ScrollViewer>
                <Grid
                    Grid.Row="2"
                    Padding="8,4"
                    ColumnSpacing="8"
                    Visibility="{x:Bind ViewModel.IsDeletingPluginsNotEmpty, Mode=OneWay}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <base:StatusTip
                        VerticalAlignment="Center"
                        Status="Information"
                        Text="{ext:Locale Name=RestartAppToEffectTip}" />
                    <Button
                        Grid.Column="1"
                        Click="OnRestartButtonClick"
                        Content="{ext:Locale Name=Restart}"
                        FontSize="12" />
                </Grid>
            </Grid>

            <Grid
                Grid.Column="2"
                Grid.ColumnSpan="3"
                Visibility="{x:Bind ViewModel.IsGroupChat, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <base:EmptyHolder
                    Title="{ext:Locale Name=ChooseServiceOrAgent}"
                    Description="{ext:Locale Name=ChooseServiceOrAgentDescription}"
                    Emoji="&#x1F60E;"
                    Visibility="{x:Bind ViewModel.CurrentSession, Mode=OneWay, Converter={StaticResource ObjectToVisibilityReverseConverter}}" />
            </Grid>

            <!--  对话界面  -->
            <Grid Grid.Column="2" Margin="-6,0">
                <chat:ChatGroupPanel ViewModel="{x:Bind ViewModel.CurrentGroup, Mode=OneWay}" Visibility="{x:Bind ViewModel.CurrentGroup, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
                <chat:ChatSessionPanel ViewModel="{x:Bind ViewModel.CurrentSession, Mode=OneWay}" Visibility="{x:Bind ViewModel.CurrentSession, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
            </Grid>

            <Grid
                Grid.Column="4"
                Margin="-6,0,0,0"
                Visibility="{x:Bind ViewModel.IsExtraColumnManualHide, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <!--  聊天附加面板  -->
                <Grid Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Visibility="{x:Bind ViewModel.CurrentSession, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid Height="{x:Bind ViewModel.ExtraRowHeight, Mode=OneWay}" Visibility="{x:Bind ViewModel.IsGroupChat, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="55" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <SelectorBar
                            x:Name="SessionPanelTypeSelector"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            SelectionChanged="OnSessionPanelTypeChanged" />
                        <Border
                            Grid.Row="1"
                            Height="1"
                            HorizontalAlignment="Stretch"
                            Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
                        <chat:ChatProviderOptionPanel
                            Grid.Row="2"
                            PropertyChanged="OnSessionParameterChanged"
                            ViewModel="{x:Bind ViewModel.CurrentSession.PresetViewModel, Mode=OneWay}"
                            Visibility="{x:Bind ViewModel.IsSessionOptionsVisible, Mode=OneWay}" />
                        <chat:SystemInstructionPanel
                            Grid.Row="2"
                            ViewModel="{x:Bind ViewModel.CurrentSession, Mode=OneWay}"
                            Visibility="{x:Bind ViewModel.IsSystemInstructionVisible, Mode=OneWay}" />
                    </Grid>
                    <chat:ChatSessionListPanel
                        Grid.Row="2"
                        ViewModel="{x:Bind ViewModel}"
                        Visibility="{x:Bind ViewModel.IsGroupChat, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />
                    <!--  分栏大小控制器  -->
                    <Border
                        Grid.Row="1"
                        Height="1"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
                    <community:PropertySizer
                        x:Name="ExtraSizer"
                        Grid.Row="1"
                        HorizontalAlignment="Stretch"
                        Binding="{x:Bind ViewModel.ExtraRowHeight, Mode=TwoWay}"
                        Minimum="200"
                        Orientation="Horizontal" />
                </Grid>

                <!--  群组附加面板  -->
                <Grid Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" Visibility="{x:Bind ViewModel.CurrentGroup, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid Height="{x:Bind ViewModel.ExtraRowHeight, Mode=OneWay}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="55" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <SelectorBar
                            x:Name="GroupPanelTypeSelector"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            SelectionChanged="OnGroupPanelTypeChanged" />
                        <Border
                            Grid.Row="1"
                            Height="1"
                            HorizontalAlignment="Stretch"
                            Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
                        <chat:GroupOptionsPanel
                            Grid.Row="2"
                            ViewModel="{x:Bind ViewModel.CurrentGroup, Mode=OneWay}"
                            Visibility="{x:Bind ViewModel.IsGroupOptionsVisible, Mode=OneWay}" />
                        <chat:GroupAgentsPanel
                            Grid.Row="2"
                            ViewModel="{x:Bind ViewModel.CurrentGroup, Mode=OneWay}"
                            Visibility="{x:Bind ViewModel.IsAgentsSectionVisible, Mode=OneWay}" />
                    </Grid>
                    <chat:ChatGroupListPanel
                        Grid.Row="2"
                        ViewModel="{x:Bind ViewModel}"
                        Visibility="{x:Bind ViewModel.IsGroupChat, Mode=OneWay}" />
                    <!--  分栏大小控制器  -->
                    <Border
                        Grid.Row="1"
                        Height="1"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
                    <community:PropertySizer
                        x:Name="ExtraSizer2"
                        Grid.Row="1"
                        HorizontalAlignment="Stretch"
                        Binding="{x:Bind ViewModel.ExtraRowHeight, Mode=TwoWay}"
                        Minimum="200"
                        Orientation="Horizontal" />
                </Grid>
            </Grid>


            <!--  左侧分栏大小控制器  -->
            <controls:ColumnSplitter
                Grid.Column="1"
                ColumnWidth="{x:Bind ViewModel.NavColumnWidth, Mode=TwoWay}"
                IsHide="{x:Bind ViewModel.IsNavColumnManualHide, Mode=TwoWay}" />

            <!--  右侧分栏大小控制器  -->
            <Grid Grid.Column="3" Visibility="{x:Bind ViewModel.CurrentSession, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                <controls:ColumnSplitter
                    ColumnWidth="{x:Bind ViewModel.ExtraColumnWidth, Mode=TwoWay}"
                    IsHide="{x:Bind ViewModel.IsExtraColumnManualHide, Mode=TwoWay}"
                    IsInvertDirection="True" />
            </Grid>

            <!--  右侧分栏大小控制器  -->
            <Grid Grid.Column="3" Visibility="{x:Bind ViewModel.CurrentGroup, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                <controls:ColumnSplitter
                    ColumnWidth="{x:Bind ViewModel.ExtraColumnWidth, Mode=TwoWay}"
                    IsHide="{x:Bind ViewModel.IsExtraColumnManualHide, Mode=TwoWay}"
                    IsInvertDirection="True" />
            </Grid>
        </Grid>

        <ProgressRing x:Name="InitialRing" Style="{StaticResource PageProgressRingStyle}" />
    </Grid>
</local:ChatServicePageBase>
