<controls:EnhancedPage
    x:Class="Pixeval.Pages.Misc.ExtensionsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Pixeval.Controls"
    xmlns:controls1="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:extensions="using:Pixeval.Extensions"
    xmlns:fluent="using:FluentIcons.WinUI"
    xmlns:local="using:Pixeval.Pages.Misc"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pixeval="using:Pixeval"
    Loaded="ExtensionsPage_OnLoaded"
    mc:Ignorable="d">
    <controls1:DockPanel VerticalSpacing="10">
        <TextBlock
            x:Uid="/ExtensionsPage/TitleTextBlock"
            Margin="20,40,20,20"
            controls1:DockPanel.Dock="Top"
            Style="{StaticResource TitleTextBlockStyle}" />
        <CommandBar controls1:DockPanel.Dock="Top" DefaultLabelPosition="Right">
            <AppBarButton
                x:Uid="/ExtensionsPage/AddExtensionsButton"
                Click="AddExtensionsOnClick"
                Icon="{fluent:SymbolIcon Symbol=PlugConnectedAdd}" />
            <AppBarButton
                x:Uid="/ExtensionsPage/OpenExtensionsButton"
                Click="OpenExtensionsOnClick"
                Icon="{fluent:SymbolIcon Symbol=FolderAdd}" />
        </CommandBar>
        <!--  TODO 通过网络获取或删除  -->
        <controls1:SettingsExpander
            Margin="20,0"
            controls1:DockPanel.Dock="Top"
            Header="可获取的扩展"
            HeaderIcon="{fluent:SymbolIcon Symbol=Rocket}"
            IsExpanded="{x:Bind pixeval:App.AppViewModel.VersionContext.NeverUsedExtensions}">
            <controls1:SettingsExpander.Items>
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="AI 提升画质扩展"
                    Header="Real-ESRGAN 提升画质"
                    HeaderIcon="{fluent:SymbolIcon Symbol=ImageSparkle}"
                    IsClickEnabled="True" />
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="Aria2 下载转发扩展"
                    Header="Aria2 下载"
                    HeaderIcon="{fluent:SymbolIcon Symbol=ArrowDownload}"
                    IsClickEnabled="True" />
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="DeepLX 翻译扩展，无需API Key"
                    Header="DeepLX 翻译"
                    HeaderIcon="{fluent:SymbolIcon Symbol=Translate}"
                    IsClickEnabled="True" />
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="通过 Ollama 调用本地运行的大模型翻译服务，需要预先安装 Ollama"
                    Header="Ollama 翻译"
                    HeaderIcon="{fluent:SymbolIcon Symbol=Translate}"
                    IsClickEnabled="True" />
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="百度翻译扩展，需要手动输入API Key"
                    Header="百度翻译"
                    HeaderIcon="{fluent:SymbolIcon Symbol=Translate}"
                    IsClickEnabled="True" />
                <controls1:SettingsCard
                    ActionIcon="{fluent:SymbolIcon Symbol=Open}"
                    Click="ExtensionCard_OnClick"
                    Description="DeepL 翻译扩展，需要手动输入API Key"
                    Header="DeepL 翻译"
                    HeaderIcon="{fluent:SymbolIcon Symbol=Translate}"
                    IsClickEnabled="True" />
            </controls1:SettingsExpander.Items>
        </controls1:SettingsExpander>
        <ListView
            Margin="20,0,20,20"
            AllowDrop="True"
            CanDragItems="True"
            CanReorderItems="True"
            DragItemsCompleted="ListViewBase_OnDragItemsCompleted"
            ItemsSource="{x:Bind Models}"
            SelectionMode="None">
            <ListView.ItemContainerStyle>
                <Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
                    <Setter Property="Padding" Value="0" />
                    <Setter Property="Background" Value="Transparent" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="extensions:ExtensionsHostModel">
                    <controls1:SettingsCard Description="{x:Bind Description}" HeaderIcon="{x:Bind Icon}">
                        <controls1:SettingsCard.Header>
                            <Grid ColumnSpacing="10">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <HyperlinkButton
                                    Grid.Column="0"
                                    Padding="0"
                                    HorizontalContentAlignment="Left"
                                    Content="{x:Bind Name}"
                                    FontWeight="Bold"
                                    NavigateUri="{x:Bind Link}" />
                                <TextBlock
                                    Grid.Column="1"
                                    Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
                                    Text="{x:Bind Author}" />
                            </Grid>
                        </controls1:SettingsCard.Header>
                        <controls1:SettingsCard.Content>
                            <CommandBar>
                                <AppBarElementContainer
                                    Padding="10,5"
                                    HorizontalContentAlignment="Center"
                                    VerticalContentAlignment="Center">
                                    <ToggleSwitch IsOn="{x:Bind IsActive, Mode=TwoWay}" />
                                </AppBarElementContainer>
                                <CommandBar.SecondaryCommands>
                                    <AppBarButton
                                        x:Uid="/ExtensionsPage/ExtensionsHelpButton"
                                        Click="ExtensionsHelpOnClick"
                                        Icon="{fluent:SymbolIcon Symbol=BookQuestionMark}"
                                        Tag="{x:Bind HelpLink}"
                                        Visibility="{x:Bind controls:C.IsNotNullToVisibility(HelpLink)}" />
                                    <AppBarButton
                                        x:Uid="/ExtensionsPage/UnloadExtensionsButton"
                                        Click="UnloadHostOnClick"
                                        Icon="{fluent:SymbolIcon Symbol=PlugDisconnected}"
                                        Tag="{x:Bind}" />
                                </CommandBar.SecondaryCommands>
                            </CommandBar>
                        </controls1:SettingsCard.Content>
                    </controls1:SettingsCard>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </controls1:DockPanel>
</controls:EnhancedPage>
