<Window x:Class="PixiEditor.Views.Dialogs.SettingsWindow"
        x:ClassModifier="internal"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs" 
        xmlns:sys="clr-namespace:System;assembly=System.Runtime"
        xmlns:vm="clr-namespace:PixiEditor.ViewModels" 
        xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters" 
        xmlns:views="clr-namespace:PixiEditor.Views" 
        xmlns:i="http://schemas.microsoft.com/xaml/behaviors" 
        xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" 
        xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
        xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
        xmlns:commands="clr-namespace:PixiEditor.Models.Commands"
        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML"
        xmlns:settingGroups="clr-namespace:PixiEditor.Views.Dialogs.SettingGroups"
        xmlns:helpers="clr-namespace:PixiEditor.Helpers"
        xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
        xmlns:enums="clr-namespace:PixiEditor.Models.Enums"
        mc:Ignorable="d"
        Name="window" 
        Height="688" Width="780"
        MinHeight="500" MinWidth="665"
        WindowStyle="None" DataContext="{DynamicResource SettingsWindowViewModel}"
        WindowStartupLocation="CenterScreen"
        BorderBrush="Black" BorderThickness="1"
        Background="{StaticResource AccentColor}"
        FlowDirection="{helpers:Localization FlowDirection}"
        ui:Translator.Key="SETTINGS">
    <Window.Resources>
        <vm:SettingsWindowViewModel x:Key="SettingsWindowViewModel"/>
        <BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    </Window.Resources>

    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="32"  GlassFrameThickness="0.1"
                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
    </WindowChrome.WindowChrome>

    <Window.CommandBindings>
        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
                        Executed="CommandBinding_Executed_Close" />
    </Window.CommandBindings>

    <DockPanel Background="{StaticResource MainColor}" Focusable="True">
        <i:Interaction.Behaviors>
            <behaviours:ClearFocusOnClickBehavior/>
        </i:Interaction.Behaviors>

        <dial:DialogTitleBar DockPanel.Dock="Top"
            TitleKey="SETTINGS" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}"/>

        <ListBox DockPanel.Dock="Left" x:Name="pages" ItemsSource="{Binding Pages}"
                 Background="Transparent" BorderThickness="0" MinWidth="165" Width="Auto" ItemContainerStyle="{StaticResource PixiListBoxItemStyle}"
                 SelectedIndex="{Binding CurrentPage}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Margin="10 5 10 5" FontSize="15" Foreground="White" Text="{Binding Path=Name.Value}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <StackPanel Orientation="Vertical" Background="{StaticResource AccentColor}">
            <StackPanel Orientation="Vertical" Margin="15,10" Tag="27">
                <StackPanel.Visibility>
                    <Binding Path="CurrentPage" Converter="{converters:EqualityBoolToVisibilityConverter}">
                        <Binding.ConverterParameter><sys:Int32>0</sys:Int32></Binding.ConverterParameter>
                    </Binding>
                </StackPanel.Visibility>
                <Label Style="{StaticResource SettingsHeader}" ui:Translator.Key="LANGUAGE"/>
                <ComboBox Margin="27 5" Width="200" Height="25" FontSize="12" HorizontalAlignment="Left"
                          ItemsSource="{Binding SettingsSubViewModel.General.AvailableLanguages}"
                          SelectedItem="{Binding SettingsSubViewModel.General.SelectedLanguage, Mode=TwoWay}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image VerticalAlignment="Center" Margin="5 0" Source="{Binding IconFullPath}"/>
                                <TextBlock VerticalAlignment="Center" Text="{Binding Name}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                    <ComboBox.ItemContainerStyle>
                        <Style TargetType="{x:Type ComboBoxItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                                        <Border Height="25" Margin="0" Padding="5,0" BorderThickness="0,1">
                                            <ContentPresenter/>
                                            <Border.Style>
                                                <Style TargetType="{x:Type Border}">
                                                    <Style.Triggers>
                                                        <Trigger Property="IsMouseOver" Value="False">
                                                            <Setter Property="Background" Value="Transparent"/>
                                                            <Setter Property="BorderBrush" Value="Transparent"/>
                                                        </Trigger>
                                                        <Trigger Property="IsMouseOver" Value="True">
                                                            <Setter Property="Background" Value="{StaticResource MainColor}"/>
                                                            <Setter Property="BorderBrush" Value="{StaticResource AlmostLightModeAccentColor}"/>
                                                        </Trigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Border.Style>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ComboBox.ItemContainerStyle>
                </ComboBox>

                <Label Style="{StaticResource SettingsHeader}" ui:Translator.Key="MISC" d:Content="Misc"/>

                <CheckBox Margin="27 0"
                          VerticalAlignment="Center" ui:Translator.Key="SHOW_STARTUP_WINDOW" d:Content="Show startup window"
                          IsChecked="{Binding SettingsSubViewModel.File.ShowStartupWindow}"/>

                <CheckBox Margin="27 10"
                          VerticalAlignment="Center" ui:Translator.Key="DISABLE_NEWS_PANEL" d:Content="Hide news in startup window"
                          IsChecked="{Binding SettingsSubViewModel.File.DisableNewsPanel}"/>

                <CheckBox Margin="27 0"
                          VerticalAlignment="Center" d:Content="Show image preview in taskbar" ui:Translator.Key="SHOW_IMAGE_PREVIEW_TASKBAR"
                          IsChecked="{Binding SettingsSubViewModel.General.ImagePreviewInTaskbar}"/>

                <StackPanel Margin="27 10 27 0" Orientation="Horizontal">
                <Label Style="{StaticResource SettingsText}"
                       ui:Translator.Key="RECENT_FILE_LENGTH"
                       ui:Translator.TooltipKey="RECENT_FILE_LENGTH_TOOLTIP"/>
                    <usercontrols:NumberInput Margin="10 0 0 0" 
                                              Min="0" FontSize="12" HorizontalAlignment="Left"
                                   Value="{Binding SettingsSubViewModel.File.MaxOpenedRecently, Mode=TwoWay}" Height="19" Width="40"/>
                </StackPanel>

                <Label Style="{StaticResource SettingsHeader}" d:Content="Default new file size" ui:Translator.Key="DEFAULT_NEW_SIZE"/>

                <StackPanel Orientation="Horizontal" Margin="27 5">
                    <Label Style="{StaticResource SettingsText}" d:Content="Width" ui:Translator.Key="WIDTH"/>
                    <usercontrols:SizeInput Margin="10 0 0 0" 
                                 Size="{Binding SettingsSubViewModel.File.DefaultNewFileWidth, Mode=TwoWay}" 
                                 Height="21" MaxSize="9999" HorizontalAlignment="Left"/>
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="27 5">
                    <Label Style="{StaticResource SettingsText}" d:Content="Height" ui:Translator.Key="HEIGHT"/> 
                    <usercontrols:SizeInput Margin="7 0 0 0"
                                 Size="{Binding SettingsSubViewModel.File.DefaultNewFileHeight, Mode=TwoWay}" 
                                 Height="21" MaxSize="9999" HorizontalAlignment="Left"/>
                </StackPanel>

                <Label Style="{StaticResource SettingsHeader}" d:Content="Tools" ui:Translator.Key="TOOLS"/>
                
                <StackPanel Margin="27 0" Orientation="Horizontal">
                    <Label Style="{StaticResource SettingsText}" Margin="0,0,7,0"
                           ui:Translator.Key="RIGHT_CLICK_MODE"/>
                    <ComboBox SelectedItem="{Binding RightClickMode, Source={vm:MainVM ToolsSVM}, Mode=TwoWay}"
                              ItemsSource="{helpers:Enum enums:RightClickMode}"
                              Width="160" Style="{StaticResource TranslatedEnum}"/>
                </StackPanel>

                <CheckBox VerticalAlignment="Center" Margin="27 5"
                    IsChecked="{Binding SettingsSubViewModel.Tools.EnableSharedToolbar}" d:Content="Enable shared toolbar" ui:Translator.Key="ENABLE_SHARED_TOOLBAR"/>

                <Label Style="{StaticResource SettingsHeader}" d:Content="Automatic updates" ui:Translator.Key="AUTOMATIC_UPDATES"/>

                <CheckBox Margin="27 5" VerticalAlignment="Center" IsEnabled="{Binding Path=ShowUpdateTab}"
                    IsChecked="{Binding SettingsSubViewModel.Update.CheckUpdatesOnStartup}" ui:Translator.Key="CHECK_FOR_UPDATES" d:Content="Check updates on startup"/>

                <StackPanel Orientation="Horizontal" Margin="27 5">
                    <Label Grid.Row="11" Grid.Column="1" Style="{StaticResource SettingsText}" d:Content="Update stream" ui:Translator.Key="UPDATE_STREAM"/>
                    <StackPanel Margin="5 0" Orientation="Horizontal" VerticalAlignment="Center"
                            Height="21.96" HorizontalAlignment="Left">
                <ComboBox Width="110" IsEnabled="{Binding Path=ShowUpdateTab}"
                    ItemsSource="{Binding SettingsSubViewModel.Update.UpdateChannels}"
                    SelectedValue="{Binding SettingsSubViewModel.Update.UpdateChannelName}"/>
                <Image Cursor="Help" Margin="10 0 0 0" Source="/Images/Commands/PixiEditor/Links/OpenDocumentation.png"
                       ToolTipService.InitialShowDelay="0"
                       Visibility="{Binding Path=ShowUpdateTab, Converter={converters:InverseBoolToVisibilityConverter}}"
                       ui:Translator.TooltipKey="UPDATE_CHANNEL_HELP_TOOLTIP"/>
                </StackPanel>
                </StackPanel>

                <Label Style="{StaticResource SettingsHeader}" d:Content="Debug" ui:Translator.Key="DEBUG"/>
                <CheckBox Margin="27 5" VerticalAlignment="Center"
                    IsChecked="{Binding SettingsSubViewModel.General.IsDebugModeEnabled}" ui:Translator.Key="ENABLE_DEBUG_MODE" d:Content="Enable Debug Mode"/>
                <Label Margin="0 5" Style="{StaticResource SettingsText}" VerticalAlignment="Center">
                    <Hyperlink Command="{cmds:Command PixiEditor.Debug.OpenCrashReportsDirectory}" Style="{StaticResource SettingsLink}">
                        <Run ui:Translator.Key="OPEN_CRASH_REPORTS_DIR" d:Text="Open crash reports directory"/>
                        <Run Text="" FontFamily="{StaticResource Feather}"/>
                    </Hyperlink>
                </Label>
            </StackPanel>

            <StackPanel Margin="15,10">
                <StackPanel.Visibility>
                    <Binding Path="CurrentPage" Converter="{converters:EqualityBoolToVisibilityConverter}">
                        <Binding.ConverterParameter>
                            <sys:Int32>1</sys:Int32>
                        </Binding.ConverterParameter>
                    </Binding>
                </StackPanel.Visibility>
                <StackPanel Orientation="Vertical">
                    <Label Style="{StaticResource SettingsHeader}" d:Content="Rich Presence" ui:Translator.Key="DISCORD_RICH_PRESENCE"/>

                    <CheckBox Margin="27 5" VerticalAlignment="Center"
                              IsChecked="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" d:Content="Enabled" ui:Translator.Key="ENABLED"/>
                    <CheckBox Margin="27 5" VerticalAlignment="Center"
                              IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" 
                              IsChecked="{Binding SettingsSubViewModel.Discord.ShowDocumentName}" d:Content="Show image name" ui:Translator.Key="SHOW_IMAGE_NAME"/>
                    <CheckBox Margin="27 5" VerticalAlignment="Center"
                              IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" d:Content="Show image size" ui:Translator.Key="SHOW_IMAGE_SIZE"
                              IsChecked="{Binding SettingsSubViewModel.Discord.ShowDocumentSize}"/>
                    <CheckBox Margin="27 5" VerticalAlignment="Center"
                              IsEnabled="{Binding SettingsSubViewModel.Discord.EnableRichPresence}" ui:Translator.Key="SHOW_LAYER_COUNT" d:Content="Show layer count"
                              IsChecked="{Binding SettingsSubViewModel.Discord.ShowLayerCount}"/>
                </StackPanel>
                <usercontrols:DiscordRPPreview 
                    Margin="15"
                    Width="280"
                    State="{Binding SettingsSubViewModel.Discord.StatePreview}" 
                    Detail="{Binding SettingsSubViewModel.Discord.DetailPreview}" 
                    IsPlaying="{Binding SettingsSubViewModel.Discord.EnableRichPresence}"/>
            </StackPanel>

            <Grid Height="{Binding ElementName=window, Path=Height, Converter={converters:SubtractConverter}, ConverterParameter=50}"
                  Margin="10,10,10,50">
                <Grid.Visibility>
                    <Binding Path="CurrentPage" Converter="{converters:EqualityBoolToVisibilityConverter}">
                        <Binding.ConverterParameter>
                            <sys:Int32>2</sys:Int32>
                        </Binding.ConverterParameter>
                    </Binding>
                </Grid.Visibility>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                    <StackPanel.Resources>
                        <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}">
                            <Setter Property="HorizontalAlignment" Value="Stretch"/>
                            <Setter Property="MinWidth" Value="115"/>
                            <Setter Property="Height" Value="Auto"/>
                            <Setter Property="Margin" Value="5,0"/>
                            <Setter Property="FontSize" Value="12"/>
                            <Setter Property="Padding" Value="5"/>
                        </Style>
                    </StackPanel.Resources>
                    <Button Command="{cmds:Command PixiEditor.Shortcuts.Export}"
                            d:Content="Export" ui:Translator.Key="EXPORT"/>
                    <Button Command="{cmds:Command PixiEditor.Shortcuts.Import}"
                            d:Content="Import" ui:Translator.Key="IMPORT"/>
                    <Button Command="{cmds:Command PixiEditor.Shortcuts.OpenTemplatePopup}"
                            d:Content="Shortcut Templates" ui:Translator.Key="SHORTCUT_TEMPLATES"/>
                    <Button Command="{cmds:Command PixiEditor.Shortcuts.Reset}"
                            d:Content="Reset all" ui:Translator.Key="RESET_ALL"/>
                </StackPanel>
                <TextBox Grid.Row="1" Style="{StaticResource DarkTextBoxStyle}" Margin="0,10"
                         Text="{Binding SearchTerm, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Behaviors>
                        <behaviours:GlobalShortcutFocusBehavior/>
                    </i:Interaction.Behaviors>
                </TextBox>

                <settingGroups:ShortcutsBinder Grid.Row="2"/>
            </Grid>
        </StackPanel>
    </DockPanel>
</Window>
