<?xml version="1.0" encoding="utf-8" ?>
<local:SettingsPageControlBase
    x:Class="BiliCopilot.UI.Controls.Settings.WebDavSettingControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:BiliCopilot.UI.Controls.Settings"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="using:BiliCopilot.UI.Models"
    mc:Ignorable="d">

    <base:SettingsExpander Description="{ext:Locale Name=WebDavSettingsDescription}" Header="{ext:Locale Name=WebDavSettings}">
        <base:SettingsExpander.HeaderIcon>
            <ic:SymbolIcon Symbol="CloudDatabase" />
        </base:SettingsExpander.HeaderIcon>
        <ToggleSwitch IsOn="{x:Bind ViewModel.IsWebDavEnabled, Mode=TwoWay}" />
        <base:SettingsExpander.Items>
            <base:SettingsCard
                Description="{ext:Locale Name=CurrentWebDavServiceDescription}"
                Header="{ext:Locale Name=CurrentWebDavService}"
                IsEnabled="{x:Bind ViewModel.IsWebDavEnabled, Mode=OneWay}"
                Visibility="{x:Bind ViewModel.IsWebDavEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <Button
                        MinWidth="120"
                        VerticalAlignment="Center"
                        Click="OnAddButtonClickAsync"
                        Content="{ext:Locale Name=AddService}" />
                    <ComboBox
                        MinWidth="120"
                        VerticalAlignment="Center"
                        ItemsSource="{x:Bind ViewModel.WebDavConfigs}"
                        SelectedItem="{x:Bind ViewModel.SelectedWebDav, Mode=TwoWay}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate x:DataType="models:WebDavConfig">
                                <TextBlock Text="{x:Bind Name}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>
            </base:SettingsCard>
        </base:SettingsExpander.Items>
        <base:SettingsExpander.ItemsFooter>
            <Grid>
                <StackPanel
                    Margin="0,12"
                    Spacing="4"
                    Visibility="{x:Bind ViewModel.IsWebDavEmpty, Mode=OneWay}">
                    <TextBlock
                        HorizontalAlignment="Center"
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Text="{ext:Locale Name=NoWebDavService}"
                        TextAlignment="Center" />
                    <HyperlinkButton
                        HorizontalAlignment="Center"
                        Click="OnAddButtonClickAsync"
                        Content="{ext:Locale Name=AddService}"
                        FontSize="12"
                        IsEnabled="{x:Bind ViewModel.IsWebDavEnabled, Mode=OneWay}" />
                </StackPanel>
                <ItemsRepeater
                    x:Name="ConfigRepeater"
                    ItemsSource="{x:Bind ViewModel.WebDavConfigs}"
                    Visibility="{x:Bind ViewModel.IsWebDavEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
                    <ItemsRepeater.ItemTemplate>
                        <DataTemplate x:DataType="models:WebDavConfig">
                            <base:SettingsCard
                                MinHeight="52"
                                Padding="58,8,44,8"
                                BorderThickness="0,1,0,0"
                                CornerRadius="0"
                                Description="{x:Bind}"
                                Header="{x:Bind Name}">
                                <StackPanel Orientation="Horizontal" Spacing="8">
                                    <Button
                                        VerticalAlignment="Center"
                                        Click="OnEditButtonClickAsync"
                                        DataContext="{x:Bind}"
                                        Style="{StaticResource SmallIconButtonStyle}"
                                        ToolTipService.ToolTip="{ext:Locale Name=Edit}">
                                        <ic:SymbolIcon FontSize="14" Symbol="Edit" />
                                    </Button>
                                    <Button
                                        VerticalAlignment="Center"
                                        Click="OnDeleteButtonClickAsync"
                                        DataContext="{x:Bind}"
                                        Style="{StaticResource SmallIconButtonStyle}"
                                        ToolTipService.ToolTip="{ext:Locale Name=Delete}">
                                        <ic:SymbolIcon
                                            FontSize="14"
                                            Foreground="{ThemeResource SystemFillColorCriticalBrush}"
                                            Symbol="Delete" />
                                    </Button>
                                </StackPanel>
                            </base:SettingsCard>
                        </DataTemplate>
                    </ItemsRepeater.ItemTemplate>
                </ItemsRepeater>
            </Grid>
        </base:SettingsExpander.ItemsFooter>
    </base:SettingsExpander>
</local:SettingsPageControlBase>
