<Window x:Class="PixiEditor.Views.Dialogs.ShortcutPopup"
        x:ClassModifier="internal"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        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:converters="clr-namespace:PixiEditor.Helpers.Converters"
        xmlns:commands="clr-namespace:PixiEditor.Models.Commands"
        xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML"
        xmlns:commands1="clr-namespace:PixiEditor.Models.Commands.Commands"
        xmlns:views="clr-namespace:PixiEditor.Views"
        xmlns:helpers="clr-namespace:PixiEditor.Helpers"
        xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        SizeToContent="Height"
        WindowStyle="None"
        ui:Translator.Key="SHORTCUTS_TITLE"
        MinHeight="780" MinWidth="620" Topmost="{Binding IsTopmost}"
        Width="950" MaxHeight="1000"
        FlowDirection="{helpers:Localization FlowDirection}"
        KeyDown="ShortcutPopup_OnKeyDown">
    <Window.Resources>
        <BoolToVisibilityConverter x:Key="BoolToVisibility"/>

        <Style TargetType="Border" x:Key="KeyBorder">
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="{StaticResource BrighterAccentColor}"/>
            <Setter Property="Background" Value="{StaticResource BrighterAccentColor}"/>
            <Setter Property="CornerRadius" Value="5"/>
            <Setter Property="Margin" Value="0,3,5,3"/>
        </Style>
        <Style TargetType="Border" x:Key="KeyBorderLast" BasedOn="{StaticResource KeyBorder}">
            <Setter Property="Margin" Value="0,3,0,3"/>
        </Style>

        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="16"/>
        </Style>
        <Style TargetType="TextBlock" x:Key="KeyBorderText" BasedOn="{StaticResource {x:Type TextBlock}}">
            <Setter Property="FontWeight" Value="Medium"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Margin" Value="4,0,4,0"/>
        </Style>

        <Style TargetType="ListView">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="0"/>
        </Style>
    </Window.Resources>

    <WindowChrome.WindowChrome>
        <WindowChrome CaptionHeight="35"  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" />
        <CommandBinding Command="{x:Static SystemCommands.MinimizeWindowCommand}"
                        CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_Minimize" />
    </Window.CommandBindings>

    <Grid Background="{StaticResource AccentColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0" Background="{StaticResource MainColor}">
            <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}"
                    WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
                    Command="{x:Static SystemCommands.CloseWindowCommand}" />
            <Button DockPanel.Dock="Right" HorizontalAlignment="Right"  Style="{StaticResource MinimizeButtonStyle}" 
                    WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Minimize"
                        Command="{x:Static SystemCommands.MinimizeWindowCommand}" />
            <ToggleButton HorizontalAlignment="Right" IsChecked="{Binding IsTopmost, Mode=TwoWay}" Style="{StaticResource PinToggleStyle}"
                          WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Makes this window always on top"/>
        </DockPanel>

        <TextBlock Grid.Row="0" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Center" ui:Translator.Key="SHORTCUTS_TITLE"/>

        <DockPanel Grid.Row="3">
            <TextBlock FontSize="14" Margin="10" Foreground="LightGray" HorizontalAlignment="Left" DockPanel.Dock="Bottom">
                <Hyperlink Style="{StaticResource SettingsLink}"
                            Command="{cmds:Command PixiEditor.Window.OpenSettingsWindow, UseProvided=True}">
                    <Hyperlink.CommandParameter>
                        <s:Int32>2</s:Int32>
                    </Hyperlink.CommandParameter>
                    <Run ui:Translator.Key="EDIT"/>
                    <Run Text="" FontFamily="{StaticResource Feather}"/>
                </Hyperlink>
            </TextBlock>
            <ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Auto">
                <WrapPanel HorizontalAlignment="Center" Margin="2">
                    <ItemsControl ItemsSource="{Binding Controller.CommandGroups}" Background="Transparent">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate DataType="{x:Type commands:CommandGroup}">
                                <StackPanel Visibility="{Binding HasAssignedShortcuts, Converter={StaticResource BoolToVisibility}}">
                                    <TextBlock Text="{Binding DisplayName}" Foreground="White" FontSize="15" FontWeight="Medium" Margin="10,8,0,5"/>
                                    <ItemsControl ItemsSource="{Binding VisibleCommands}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type commands1:Command}">
                                                <StackPanel Orientation="Horizontal" Margin="20,0,0,0" Visibility="{Binding Shortcut.Key, ConverterParameter=None, Converter={converters:EqualityBoolToVisibilityConverter Invert=True}}"
                                                            ToolTip="{Binding Description}">
                                                    <ItemsControl ItemsSource="{Binding Shortcut.Modifiers, Converter={converters:ModifierFlagToModifiersConverter}}">
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate DataType="{x:Type ModifierKeys}">
                                                                <Border Style="{StaticResource KeyBorder}">
                                                                    <TextBlock ui:Translator.LocalizedString="{Binding BindsDirectlyToSource=True, Converter={converters:KeyToStringConverter}}" Style="{StaticResource KeyBorderText}"/>
                                                                </Border>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <StackPanel Orientation="Horizontal"/>
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                    </ItemsControl>
                                                    <Border Style="{StaticResource KeyBorderLast}">
                                                        <TextBlock Text="{Binding Shortcut.Key, Converter={converters:KeyToStringConverter}}" Style="{StaticResource KeyBorderText}"/>
                                                    </Border>

                                                    <TextBlock Text="{Binding DisplayName}" Foreground="#FFEEEEEE" VerticalAlignment="Center" FontSize="14" Margin="8,0,0,0"/>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel ItemWidth="300"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </WrapPanel>
            </ScrollViewer>
        </DockPanel>
    </Grid>
</Window>
