<UserControl x:Class="ScreenToGif.UserControls.KeyStrokesPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:n="clr-namespace:ScreenToGif.Controls"
             xmlns:u="clr-namespace:ScreenToGif.Util"
             xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:c="clr-namespace:ScreenToGif.Util.Converters"
             xmlns:t="clr-namespace:ScreenToGif.Settings"
             mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="300"
             SnapsToDevicePixels="True">
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.Resources>
            <c:FontToSupportedGliph x:Key="FontToSupportedGliphConverter"/>
            
            <CollectionViewSource x:Key="MyFonts" x:Shared="False" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}, Converter={StaticResource FontToSupportedGliphConverter}}">
                <CollectionViewSource.SortDescriptions>
                    <cm:SortDescription PropertyName="Source"/>
                </CollectionViewSource.SortDescriptions>
            </CollectionViewSource>

            <DataTemplate x:Key="FontTemplate">
                <VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True">
                    <TextBlock FontFamily="{Binding .}" FontSize="16" Text="{Binding .}" ToolTip="{Binding Path=.Source}"/>
                </VirtualizingStackPanel>
            </DataTemplate>
        </Grid.Resources>
        
        <Expander Grid.Row="0" Header="{DynamicResource S.KeyStrokes.Keys}" IsExpanded="{Binding IsKeyStrokesKeysExpanded, Source={x:Static t:UserSettings.All}}">
            <Grid Margin="10,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <n:ExtendedCheckBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Text="{DynamicResource S.KeyStrokes.IgnoreModifiers}" Margin="0,5"
                                    IsChecked="{Binding KeyStrokesIgnoreNonModifiers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    ToolTip="{DynamicResource S.KeyStrokes.IgnoreModifiers.Info}"/>

                <n:ExtendedCheckBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Text="{DynamicResource S.KeyStrokes.IgnoreInjected}" Margin="0,5"
                                    IsChecked="{Binding KeyStrokesIgnoreInjected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    ToolTip="{DynamicResource S.KeyStrokes.IgnoreInjected.Info}"/>

                <n:ExtendedCheckBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Text="{DynamicResource S.KeyStrokes.Extend}" Margin="0,5"
                                    IsChecked="{Binding KeyStrokesExtended, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <StackPanel Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal" Margin="10,0,0,0" 
                            Visibility="{Binding KeyStrokesExtended, Converter={StaticResource Bool2Visibility}}">
                    <TextBlock Text="{DynamicResource S.KeyStrokes.By}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                    <n:IntegerUpDown Minimum="10" Maximum="1000" Margin="5" MinWidth="70" Value="{Binding KeyStrokesDelay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </StackPanel>

                <n:ExtendedCheckBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Text="{DynamicResource S.KeyStrokes.Earlier}" Margin="0,5"
                                    IsChecked="{Binding KeyStrokesEarlier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal" Margin="10,0,0,0" 
                            Visibility="{Binding KeyStrokesEarlier, Converter={StaticResource Bool2Visibility}}">
                    <TextBlock Text="{DynamicResource S.KeyStrokes.By}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                    <n:IntegerUpDown Minimum="10" Maximum="1000" Margin="5" MinWidth="70" Value="{Binding KeyStrokesEarlierBy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </StackPanel>

                <TextBlock Grid.Row="7" Grid.Column="0" Text="{DynamicResource S.KeyStrokes.Separator}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:ExtendedTextBox Grid.Row="7" Grid.Column="1" Margin="5,3" MinWidth="70" Text="{Binding KeyStrokesSeparator, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </Grid>
        </Expander>

        <Expander Grid.Row="1" Header="{DynamicResource S.Caption.Font}" IsExpanded="{Binding IsKeyStrokesFontExpanded, Source={x:Static t:UserSettings.All}}">
            <Grid Margin="10,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="{DynamicResource S.Caption.Family}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <ComboBox Grid.Row="0" Grid.Column="1" Margin="10,5" MinWidth="100" MaxWidth="150" IsEditable="True"
                          ItemTemplate="{DynamicResource FontTemplate}" SelectedItem="{Binding KeyStrokesFontFamily, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <ComboBox.ItemsSource>
                        <Binding Source="{StaticResource MyFonts}"/>
                    </ComboBox.ItemsSource>

                    <ComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"/>
                        </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>
                </ComboBox>

                <TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource S.Caption.Style}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <ComboBox Grid.Row="1" Grid.Column="1" Margin="10,5" MinWidth="100" SelectedValuePath="FontStyle" 
                          SelectedValue="{Binding KeyStrokesFontStyle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True">
                                <TextBlock FontStyle="{Binding FontStyle}" FontSize="14" Text="{Binding Text}"/>
                            </VirtualizingStackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>

                    <TextBlock FontStyle="Normal" Text="{DynamicResource S.FontStyles.Normal}"/>
                    <TextBlock FontStyle="Italic" Text="{DynamicResource S.FontStyles.Italic}"/>
                    <TextBlock FontStyle="Oblique" Text="{DynamicResource S.FontStyles.Oblique}"/>
                </ComboBox>

                <TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource S.Caption.Weight}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <ComboBox Grid.Row="2" Grid.Column="1" Margin="10,5" MinWidth="100" SelectedValuePath="FontWeight" 
                          SelectedValue="{Binding KeyStrokesFontWeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True">
                                <TextBlock FontWeight="{Binding FontWeight}" FontSize="14" Text="{Binding Text}" />
                            </VirtualizingStackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>

                    <TextBlock FontWeight="UltraLight" Text="{DynamicResource S.FontWeights.UltraLight}"/>
                    <TextBlock FontWeight="ExtraLight" Text="{DynamicResource S.FontWeights.ExtraLight}"/>
                    <TextBlock FontWeight="Light" Text="{DynamicResource S.FontWeights.Light}"/>
                    <TextBlock FontWeight="Thin" Text="{DynamicResource S.FontWeights.Thin}"/>
                    <TextBlock FontWeight="Normal" Text="{DynamicResource S.FontWeights.Normal}"/>
                    <TextBlock FontWeight="Regular" Text="{DynamicResource S.FontWeights.Regular}"/>
                    <TextBlock FontWeight="Medium" Text="{DynamicResource S.FontWeights.Medium}"/>
                    <TextBlock FontWeight="SemiBold" Text="{DynamicResource S.FontWeights.SemiBold}"/>
                    <TextBlock FontWeight="DemiBold" Text="{DynamicResource S.FontWeights.DemiBold}"/>
                    <TextBlock FontWeight="Bold" Text="{DynamicResource S.FontWeights.Bold}"/>
                    <TextBlock FontWeight="Black" Text="{DynamicResource S.FontWeights.Black}"/>
                    <TextBlock FontWeight="Heavy" Text="{DynamicResource S.FontWeights.Heavy}"/>
                    <TextBlock FontWeight="ExtraBold" Text="{DynamicResource S.FontWeights.ExtraBold}"/>
                    <TextBlock FontWeight="ExtraBlack" Text="{DynamicResource S.FontWeights.ExtraBlack}"/>
                    <TextBlock FontWeight="UltraBold" Text="{DynamicResource S.FontWeights.UltraBold}"/>
                    <TextBlock FontWeight="UltraBlack" Text="{DynamicResource S.FontWeights.UltraBlack}"/>
                </ComboBox>

                <TextBlock Grid.Row="3" Grid.Column="0" Text="{DynamicResource S.Caption.Size}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:IntegerUpDown Grid.Row="3" Grid.Column="1" Minimum="10" Maximum="1000" Margin="10,5" MinWidth="70" 
                                 Value="{Binding KeyStrokesFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <TextBlock Grid.Row="4" Grid.Column="0" Text="{DynamicResource S.Caption.Color}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:ColorBox Grid.Row="4" Grid.Column="1" SelectedColor="{Binding KeyStrokesFontColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,5"/>
            </Grid>
        </Expander>

        <Expander Grid.Row="2" Header="{DynamicResource S.Caption.Outline}" IsExpanded="{Binding IsKeyStrokesOutlineExpanded, Source={x:Static t:UserSettings.All}}">
            <Grid Margin="10,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="{DynamicResource S.Caption.Thickness}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:IntegerUpDown Grid.Row="0" Grid.Column="1" Minimum="0" Maximum="20" Margin="10,5" MinWidth="70" 
                                 Value="{Binding KeyStrokesOutlineThickness, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource S.Caption.Color}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:ColorBox Grid.Row="1" Grid.Column="1" SelectedColor="{Binding KeyStrokesOutlineColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,5"/>

                <TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource S.Background}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:ColorBox Grid.Row="2" Grid.Column="1" SelectedColor="{Binding KeyStrokesBackgroundColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,5"/>
            </Grid>
        </Expander>

        <Expander Grid.Row="3" Header="{DynamicResource S.Caption.Layout}" IsExpanded="{Binding IsKeyStrokesLayoutExpanded, Source={x:Static t:UserSettings.All}}">
            <Grid Margin="10,0,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="{DynamicResource S.Caption.Vertical}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <ComboBox Grid.Row="0" Grid.Column="1" Margin="10,5" MinWidth="100" MaxWidth="150" SelectedValuePath="VerticalAlignment" 
                          SelectedValue="{Binding KeyStrokesVerticalAlignment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

                    <TextBlock VerticalAlignment="Top" Text="{DynamicResource S.VerticalAlignment.Top}"/>
                    <TextBlock VerticalAlignment="Center" Text="{DynamicResource S.VerticalAlignment.Center}"/>
                    <TextBlock VerticalAlignment="Bottom" Text="{DynamicResource S.VerticalAlignment.Bottom}"/>
                    <TextBlock VerticalAlignment="Stretch" Text="{DynamicResource S.Alignment.Stretch}"/>
                </ComboBox>

                <TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource S.Caption.Horizontal}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <ComboBox Grid.Row="1" Grid.Column="1" Margin="10,5" MinWidth="100" MaxWidth="150" SelectedValuePath="HorizontalAlignment" 
                          SelectedValue="{Binding KeyStrokesHorizontalAlignment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

                    <TextBlock HorizontalAlignment="Left" Text="{DynamicResource S.HorizontalAlignment.Left}"/>
                    <TextBlock HorizontalAlignment="Center" Text="{DynamicResource S.HorizontalAlignment.Center}"/>
                    <TextBlock HorizontalAlignment="Right" Text="{DynamicResource S.HorizontalAlignment.Right}"/>
                    <TextBlock HorizontalAlignment="Stretch" Text="{DynamicResource S.Alignment.Stretch}"/>
                </ComboBox>

                <TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource S.Margin}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:IntegerUpDown Grid.Row="2" Grid.Column="1" Minimum="-100" Maximum="100" Margin="10,5" MinWidth="70" 
                                 Value="{Binding KeyStrokesMargin, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <TextBlock Grid.Row="3" Grid.Column="0" Text="{DynamicResource S.Padding}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:IntegerUpDown Grid.Row="3" Grid.Column="1" Minimum="0" Maximum="100" Margin="10,5" MinWidth="70" 
                                 Value="{Binding KeyStrokesPadding, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

                <TextBlock Grid.Row="4" Grid.Column="0" Text="{DynamicResource S.MinHeight}" VerticalAlignment="Center" Foreground="{DynamicResource Element.Foreground.Medium}"/>
                <n:IntegerUpDown Grid.Row="4" Grid.Column="1" Minimum="0" Maximum="100" Margin="10,5" MinWidth="70" 
                                 Value="{Binding KeyStrokesMinHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </Grid>
        </Expander>
    </Grid>
</UserControl>