<UserControl
    x:Class="ImageResizer.Views.InputPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:m="clr-namespace:ImageResizer.Models"
    xmlns:p="clr-namespace:ImageResizer.Properties"
    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <!--  ComboBox  -->
            <RowDefinition Height="*" />
            <!--  other controls  -->
        </Grid.RowDefinitions>

        <ComboBox
            Name="SizeComboBox"
            Grid.Row="0"
            Height="64"
            Margin="16"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            VerticalContentAlignment="Stretch"
            AutomationProperties.Name="{x:Static p:Resources.Image_Sizes}"
            ItemsSource="{Binding Settings.AllSizes}"
            SelectedIndex="{Binding Settings.SelectedSizeIndex}">
            <ComboBox.Resources>
                <DataTemplate DataType="{x:Type m:ResizeSize}">
                    <Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Style="{StaticResource BodyStrongTextBlockStyle}" Text="{Binding Name}" />
                        <StackPanel Grid.Row="1" Orientation="Horizontal">
                            <TextBlock Foreground="{DynamicResource TextFillColorSecondaryBrush}" Text="{Binding Fit, Converter={StaticResource EnumValueConverter}, ConverterParameter=ThirdPersonSingular}" />
                            <TextBlock
                                Margin="4,0,0,0"
                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                Text="{Binding Width, Converter={StaticResource AutoDoubleConverter}, ConverterParameter=Auto}" />
                            <TextBlock
                                Margin="4,0,0,0"
                                Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                                Text="×"
                                Visibility="{Binding ShowHeight, Converter={StaticResource BoolValueConverter}}" />
                            <TextBlock
                                Margin="4,0,0,0"
                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                Text="{Binding Height, Converter={StaticResource AutoDoubleConverter}, ConverterParameter=Auto}"
                                Visibility="{Binding ShowHeight, Converter={StaticResource BoolValueConverter}}" />
                            <TextBlock
                                Margin="4,0,0,0"
                                Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                                Text="{Binding Unit, Converter={StaticResource EnumValueConverter}, ConverterParameter=ToLower}" />
                        </StackPanel>
                    </Grid>
                </DataTemplate>

                <DataTemplate DataType="{x:Type m:CustomSize}">
                    <Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
                        <TextBlock FontWeight="SemiBold" Text="{Binding Name}" />
                    </Grid>
                </DataTemplate>
            </ComboBox.Resources>
        </ComboBox>

        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Border
                Grid.RowSpan="5"
                Background="{DynamicResource LayerFillColorDefaultBrush}"
                BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
                BorderThickness="0,1,0,0" />

            <!--  "Custom" input matrix  -->
            <Grid Margin="16" Visibility="{Binding ElementName=SizeComboBox, Path=SelectedValue, Converter={StaticResource SizeTypeToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="24" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="24" />
                    <ColumnDefinition Width="24" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="8" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <ui:SymbolIcon
                    VerticalAlignment="Center"
                    AutomationProperties.Name="{x:Static p:Resources.Width}"
                    FontSize="20"
                    Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                    Symbol="AutoFitWidth20"
                    ToolTipService.ToolTip="{x:Static p:Resources.Width}" />
                <ui:NumberBox
                    Name="WidthNumberBox"
                    Grid.Column="1"
                    Margin="8,0,0,0"
                    HorizontalAlignment="Stretch"
                    AutomationProperties.Name="{x:Static p:Resources.Width}"
                    KeyDown="Button_KeyDown"
                    Minimum="0"
                    SpinButtonPlacementMode="Inline">
                    <ui:NumberBox.Value>
                        <Binding
                            ElementName="SizeComboBox"
                            Mode="TwoWay"
                            Path="SelectedValue.Width"
                            UpdateSourceTrigger="PropertyChanged" />
                    </ui:NumberBox.Value>
                </ui:NumberBox>

                <ui:SymbolIcon
                    Grid.Column="3"
                    VerticalAlignment="Center"
                    AutomationProperties.Name="{x:Static p:Resources.Height}"
                    FontSize="20"
                    Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                    Symbol="AutoFitHeight20"
                    ToolTipService.ToolTip="{x:Static p:Resources.Height}"
                    Visibility="{Binding ElementName=SizeComboBox, Path=SelectedValue.ShowHeight, Converter={StaticResource BoolValueConverter}}" />
                <ui:NumberBox
                    Name="HeightNumberBox"
                    Grid.Column="4"
                    Margin="8,0,0,0"
                    HorizontalAlignment="Stretch"
                    AutomationProperties.Name="{x:Static p:Resources.Height}"
                    DataContext="{Binding ElementName=SizeComboBox, Path=SelectedItem}"
                    KeyDown="Button_KeyDown"
                    Minimum="0"
                    SpinButtonPlacementMode="Inline"
                    Visibility="{Binding ElementName=SizeComboBox, Path=SelectedValue.ShowHeight, Converter={StaticResource BoolValueConverter}}">
                    <ui:NumberBox.Value>
                        <Binding
                            ElementName="SizeComboBox"
                            Mode="TwoWay"
                            Path="SelectedValue.Height"
                            UpdateSourceTrigger="PropertyChanged" />
                    </ui:NumberBox.Value>
                </ui:NumberBox>

                <ui:SymbolIcon
                    Grid.Row="2"
                    VerticalAlignment="Center"
                    FontSize="20"
                    Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                    Symbol="Crop20"
                    ToolTipService.ToolTip="{x:Static p:Resources.Resize_Type}" />
                <ComboBox
                    Grid.Row="2"
                    Grid.Column="1"
                    Margin="8,0,0,0"
                    HorizontalAlignment="Stretch"
                    AutomationProperties.Name="{x:Static p:Resources.Resize_Type}"
                    ItemsSource="{Binding ResizeFitValues, Mode=OneWay}"
                    SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Fit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate DataType="{x:Type m:ResizeFit}">
                            <TextBlock Padding="2,0" Text="{Binding {}, Converter={StaticResource EnumValueConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <ui:SymbolIcon
                    Grid.Row="2"
                    Grid.Column="3"
                    VerticalAlignment="Center"
                    FontSize="20"
                    Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                    Symbol="Ruler20"
                    ToolTipService.ToolTip="{x:Static p:Resources.Unit}" />
                <ComboBox
                    Grid.Row="2"
                    Grid.Column="4"
                    Margin="8,0,0,0"
                    AutomationProperties.Name="{x:Static p:Resources.Unit}"
                    ItemsSource="{Binding ResizeUnitValues, Mode=OneWay}"
                    SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Unit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate DataType="{x:Type m:ResizeUnit}">
                            <TextBlock Padding="2,0" Text="{Binding {}, Converter={StaticResource EnumValueConverter}}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
            </Grid>

            <!--  CheckBoxes  -->
            <StackPanel
                Grid.Row="1"
                Margin="16"
                Orientation="Vertical">
                <CheckBox AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text), Converter={StaticResource AccessTextToTextConverter}}" IsChecked="{Binding Settings.ShrinkOnly}">
                    <CheckBox.Content>
                        <AccessText Text="{x:Static p:Resources.Input_ShrinkOnly}" TextWrapping="Wrap" />
                    </CheckBox.Content>
                </CheckBox>

                <CheckBox AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text), Converter={StaticResource AccessTextToTextConverter}}" IsChecked="{Binding Settings.IgnoreOrientation}">
                    <CheckBox.Content>
                        <AccessText Text="{x:Static p:Resources.Input_IgnoreOrientation}" TextWrapping="Wrap" />
                    </CheckBox.Content>
                </CheckBox>

                <CheckBox AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text), Converter={StaticResource AccessTextToTextConverter}}" IsChecked="{Binding Settings.Replace}">
                    <CheckBox.Content>
                        <AccessText Text="{x:Static p:Resources.Input_Replace}" TextWrapping="Wrap" />
                    </CheckBox.Content>
                </CheckBox>

                <CheckBox AutomationProperties.Name="{Binding RelativeSource={RelativeSource Self}, Path=Content.(AccessText.Text), Converter={StaticResource AccessTextToTextConverter}}" IsChecked="{Binding Settings.RemoveMetadata}">
                    <CheckBox.Content>
                        <AccessText Text="{x:Static p:Resources.Input_RemoveMetadata}" TextWrapping="Wrap" />
                    </CheckBox.Content>
                </CheckBox>
            </StackPanel>


            <!--  Separator line  -->
            <Border
                Grid.Row="2"
                Height="1"
                Margin="0,8"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Top"
                Background="{DynamicResource DividerStrokeColorDefaultBrush}" />

            <ui:InfoBar
                Grid.Row="3"
                Margin="16,0"
                IsClosable="False"
                IsOpen="{Binding TryingToResizeGifFiles}"
                Message="{x:Static p:Resources.Input_GifWarning}"
                Severity="Warning" />

            <!--  Buttons  -->
            <Grid Grid.Row="4" Margin="16,8,16,16">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <ui:Button
                    Padding="0"
                    AutomationProperties.Name="{x:Static p:Resources.Open_settings}"
                    Background="Transparent"
                    BorderBrush="Transparent"
                    Command="{Binding OpenSettingsCommand}"
                    ToolTipService.ToolTip="{x:Static p:Resources.Open_settings}">
                    <ui:Button.Content>
                        <ui:SymbolIcon FontSize="20" Symbol="Settings20" />
                    </ui:Button.Content>
                </ui:Button>

                <ui:Button
                    Grid.Column="1"
                    MinWidth="76"
                    Appearance="Primary"
                    AutomationProperties.Name="{x:Static p:Resources.Resize_Tooltip}"
                    Command="{Binding ResizeCommand}"
                    IsDefault="True">
                    <StackPanel Orientation="Horizontal">
                        <ui:SymbolIcon FontSize="16" Symbol="ResizeLarge16" />
                        <TextBlock Margin="8,0,0,0" Text="{x:Static p:Resources.Input_Resize}" />
                    </StackPanel>
                </ui:Button>

                <ui:Button
                    Grid.Column="2"
                    MinWidth="76"
                    Margin="8,0,0,0"
                    Command="{Binding CancelCommand}"
                    Content="{x:Static p:Resources.Cancel}"
                    IsCancel="True" />
            </Grid>
        </Grid>
    </Grid>
</UserControl>
