<UserControl
    x:Class="Bili.App.Controls.Player.DownloadOptionsPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:common="using:Bili.ViewModels.Interfaces.Common"
    xmlns:controls="using:Bili.App.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:icon="using:Richasy.FluentIcon.Uwp"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:local="using:Bili.App.Controls.Player"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">

    <StackPanel MaxWidth="320" Spacing="8">
        <TextBlock
            Style="{StaticResource CaptionTextBlockStyle}"
            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
            Text="{loc:Locale Name=DownloadTip}"
            TextWrapping="Wrap" />
        <HyperlinkButton Content="BBDown" NavigateUri="https://github.com/nilaoda/BBDown" />
        <ComboBox
            x:Name="InterfaceComboBox"
            HorizontalAlignment="Stretch"
            Header="{loc:Locale Name=InterfaceType}"
            SelectionChanged="OnInterfaceComboBoxSelectionChanged">
            <ComboBoxItem Content="{loc:Locale Name=None}" Tag="None" />
            <ComboBoxItem Content="{loc:Locale Name=MobileApp}" Tag="App" />
            <ComboBoxItem Content="{loc:Locale Name=TVApp}" Tag="TV" />
            <ComboBoxItem Content="{loc:Locale Name=InternationalApp}" Tag="International" />
        </ComboBox>
        <ComboBox
            x:Name="CodecComboBox"
            HorizontalAlignment="Stretch"
            Header="{loc:Locale Name=PreferCodec}"
            SelectionChanged="OnCodecComboBoxSelectionChanged">
            <ComboBoxItem Content="{loc:Locale Name=Any}" Tag="Any" />
            <ComboBoxItem Content="{loc:Locale Name=H264}" Tag="H264" />
            <ComboBoxItem Content="{loc:Locale Name=H265}" Tag="H265" />
            <ComboBoxItem Content="{loc:Locale Name=Av1}" Tag="AV1" />
        </ComboBox>
        <ComboBox
            x:Name="DownloadTypeComboBox"
            HorizontalAlignment="Stretch"
            Header="{loc:Locale Name=DownloadType}"
            SelectionChanged="OnDownloadTypeComboBoxSelectionChanged">
            <ComboBoxItem Content="{loc:Locale Name=Full}" Tag="Any" />
            <ComboBoxItem Content="{loc:Locale Name=OnlyVideo}" Tag="Video" />
            <ComboBoxItem Content="{loc:Locale Name=OnlyAudio}" Tag="Audio" />
            <ComboBoxItem Content="{loc:Locale Name=OnlySubtitle}" Tag="Subtitle" />
        </ComboBox>
        <StackPanel Spacing="8">
            <TextBlock HorizontalAlignment="Left" Text="{loc:Locale Name=DownloadFolder}" />
            <Grid ColumnSpacing="8">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Center"
                    IsReadOnly="True"
                    PlaceholderText="{loc:Locale Name=NoSpecifiedDownloadPath}"
                    Text="{x:Bind ViewModel.DownloadFolder, Mode=OneWay}" />
                <Button
                    x:Name="OpenFolderButton"
                    AutomationProperties.Name="{loc:Locale Name=ChooseDownloadFolder}"
                    Grid.Column="1"
                    Width="40"
                    VerticalAlignment="Center"
                    Command="{x:Bind ViewModel.ChangeSaveLocationCommand}"
                    ToolTipService.ToolTip="{loc:Locale Name=ChooseDownloadFolder}">
                    <icon:RegularFluentIcon Symbol="Folder16" />
                </Button>
            </Grid>
        </StackPanel>
        <StackPanel Spacing="8" Visibility="{x:Bind ViewModel.IsShowPart, Mode=OneWay}">
            <TextBlock Text="{loc:Locale Name=Parts}" />
            <muxc:ItemsRepeater ItemsSource="{x:Bind ViewModel.TotalPartCollection, Mode=OneWay}">
                <muxc:ItemsRepeater.ItemTemplate>
                    <DataTemplate x:DataType="common:INumberPartViewModel">
                        <controls:CardPanel
                            IsChecked="{x:Bind IsSelected, Mode=TwoWay}"
                            IsEnableCheck="True"
                            IsEnableHoverAnimation="False">
                            <TextBlock
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                FontWeight="Bold"
                                Text="{x:Bind Data, Mode=OneWay}" />
                        </controls:CardPanel>
                    </DataTemplate>
                </muxc:ItemsRepeater.ItemTemplate>
                <muxc:ItemsRepeater.Layout>
                    <muxc:UniformGridLayout
                        MinColumnSpacing="4"
                        MinItemHeight="40"
                        MinItemWidth="40"
                        MinRowSpacing="4" />
                </muxc:ItemsRepeater.Layout>
            </muxc:ItemsRepeater>
        </StackPanel>
        <muxc:Expander
            HorizontalAlignment="Stretch"
            HorizontalContentAlignment="Stretch"
            Header="{loc:Locale Name=AdvancedOptions}">
            <StackPanel
                Padding="12,4"
                HorizontalAlignment="Stretch"
                Spacing="8">
                <ToggleSwitch
                    x:Name="InteractionQualitySwitch"
                    HorizontalAlignment="Left"
                    Header="{loc:Locale Name=InteractionQuality}"
                    IsOn="{x:Bind ViewModel.UseInteractionQuality, Mode=TwoWay}" />
                <ToggleSwitch
                    x:Name="DownloadDanmakuSwitch"
                    HorizontalAlignment="Left"
                    Header="{loc:Locale Name=DownloadDanmaku}"
                    IsOn="{x:Bind ViewModel.DownloadDanmaku, Mode=TwoWay}" />
                <ToggleSwitch
                    x:Name="UseMp4BoxSwitch"
                    HorizontalAlignment="Left"
                    Header="{loc:Locale Name=UseMp4Box}"
                    IsOn="{x:Bind ViewModel.UseMp4Box, Mode=TwoWay}" />
                <ToggleSwitch
                    x:Name="UseMultiThreadSwitch"
                    HorizontalAlignment="Left"
                    Header="{loc:Locale Name=UseMultiThread}"
                    IsOn="{x:Bind ViewModel.UseMultiThread, Mode=TwoWay}" />
            </StackPanel>
        </muxc:Expander>
        <Button
            Style="{StaticResource AccentButtonStyle}"
            Margin="0,4,0,0"
            HorizontalAlignment="Stretch"
            Command="{x:Bind ViewModel.SaveDownloadTextCommand}"
            Content="{loc:Locale Name=GenerateCommand}" />
    </StackPanel>
</UserControl>
