<UserControl
    x:Class="Translumo.MVVM.Views.HotkeysSettingsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:common="clr-namespace:Translumo.MVVM.Common"
    xmlns:controls="clr-namespace:Translumo.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.Resources>
        <common:KeyCombinationValueConverter x:Key="KeyCombinationConverter" />
        <common:GamepadKeyCombinationValueConverter x:Key="GamepadKeyCombinationValueConverter" />
    </UserControl.Resources>

    <DockPanel LastChildFill="True">
        <ItemsControl
            Name="IcHotKeys"
            DockPanel.Dock="Top"
            ItemsSource="{Binding Model}">
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="FrameworkElement.Margin" Value="0 0 0 7" />
                </Style>
            </ItemsControl.ItemContainerStyle>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <controls:HotkeyInput
                            Width="90"
                            VerticalContentAlignment="Center"
                            Background="{DynamicResource PrimaryHueLightBrush}"
                            GamepadHotKey="{Binding GamepadHotKey, Mode=TwoWay, Converter={StaticResource GamepadKeyCombinationValueConverter}}"
                            HotKey="{Binding HotKey, Mode=TwoWay, Converter={StaticResource KeyCombinationConverter}}">
                            <b:Interaction.Triggers>
                                <b:EventTrigger EventName="LostFocus">
                                    <b:InvokeCommandAction Command="{Binding DataContext.ExitEditModeCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
                                </b:EventTrigger>
                                <b:EventTrigger EventName="GotFocus">
                                    <b:InvokeCommandAction Command="{Binding DataContext.EnterEditModeCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />
                                </b:EventTrigger>
                            </b:Interaction.Triggers>
                        </controls:HotkeyInput>
                        <Label Content="{Binding Description}" Style="{StaticResource ControlCaptionLabel}" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DockPanel>
</UserControl>
