<UserControl xmlns="https://github.com/avaloniaui"
             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:pages="clr-namespace:GalaxyBudsClient.Interface.ViewModels.Pages"
             xmlns:ext="clr-namespace:GalaxyBudsClient.Interface.MarkupExtensions"
             xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
             xmlns:input="clr-namespace:FluentAvalonia.UI.Input;assembly=FluentAvalonia"
             xmlns:controls="clr-namespace:GalaxyBudsClient.Interface.Controls"
             xmlns:i18N="clr-namespace:GalaxyBudsClient.Generated.I18N"
             xmlns:config="clr-namespace:GalaxyBudsClient.Model.Config"
             xmlns:model="clr-namespace:GalaxyBudsClient.Model"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="400"
             x:Class="GalaxyBudsClient.Interface.Pages.HotkeyPage"
             x:DataType="pages:HotkeyPageViewModel"
             x:CompileBindings="True">
    <Design.DataContext>
        <pages:HotkeyPageViewModel />
    </Design.DataContext>

    <UserControl.Resources>
        <input:XamlUICommand x:Key="NewCommand"
                             Label="{ext:Translate hotkey_add_short}"
                             IconSource="{StaticResource NewIcon}"
                             Description="{ext:Translate {x:Static i18N:Keys.HotkeyAdd}}"
                             Command="{Binding DoNewCommand}" />

        <input:XamlUICommand x:Key="EditCommand"
                             Label="{ext:Translate hotkey_edit}"
                             IconSource="{StaticResource EditIcon}"
                             Description="{ext:Translate hotkey_edit_long}"
                             Command="{Binding DoEditCommand}" />

        <input:StandardUICommand x:Key="DeleteCommand" Kind="Delete"
                                 Label="{ext:Translate hotkey_delete}"
                                 Description="{ext:Translate hotkey_delete}"
                                 Command="{Binding DoDeleteCommand}" />
    </UserControl.Resources>

    <Border Margin="{StaticResource AppPageMargin}"
            Classes="Card">
        <Grid RowDefinitions="Auto,*">
            <ui:CommandBar DefaultLabelPosition="Right" Padding="5,0">
                <ui:CommandBar.PrimaryCommands>
                    <ui:CommandBarButton
                        Command="{StaticResource NewCommand}" />
                    <ui:CommandBarButton
                        IsEnabled="{Binding #HotkeyList.SelectedValue, Converter={x:Static ObjectConverters.IsNotNull}}"
                        Command="{StaticResource EditCommand}"
                        CommandParameter="{Binding #HotkeyList.SelectedItem}" />
                    <ui:CommandBarButton
                        IsEnabled="{Binding #HotkeyList.SelectedValue,Converter={x:Static ObjectConverters.IsNotNull}}"
                        Command="{StaticResource DeleteCommand}"
                        CommandParameter="{Binding #HotkeyList.SelectedItem}" />
                </ui:CommandBar.PrimaryCommands>
            </ui:CommandBar>
            
            <ListBox Grid.Row="1"
                     ItemsSource="{Binding Hotkeys, Source={x:Static config:Settings.Data}}"
                     IsVisible="{Binding !NoHotkeys}"
                     Name="HotkeyList">
                <ListBox.ItemTemplate>
                    <DataTemplate x:DataType="model:Hotkey">
                        <Border Background="Transparent">
                            <Panel>
                                <StackPanel Spacing="4" Margin="4 10" VerticalAlignment="Center">
                                    <TextBlock Text="{Binding HotkeyName}"
                                               Classes="BaseTextBlockStyle"
                                               VerticalAlignment="Bottom"
                                               HorizontalAlignment="Left"
                                               TextTrimming="CharacterEllipsis" />

                                    <TextBlock Classes="CaptionTextBlockStyle"
                                               Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                                               VerticalAlignment="Top"
                                               TextWrapping="Wrap"
                                               Text="{Binding ActionName}" />
                                </StackPanel>

                                <StackPanel Orientation="Horizontal"
                                            HorizontalAlignment="Right">
                                    <ui:CommandBarButton HorizontalAlignment="Right"
                                                         Command="{StaticResource EditCommand}"
                                                         CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
                                                         HotKey="{x:Null}" />
                                    <ui:CommandBarButton HorizontalAlignment="Right"
                                                         Command="{StaticResource DeleteCommand}"
                                                         CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
                                                         HotKey="{x:Null}" />
                                </StackPanel>
                            </Panel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <controls:EmptyView Grid.Row="1"
                                IsVisible="{Binding NoHotkeys}"
                                Text="{ext:Translate {x:Static i18N:Keys.HotkeyEmpty}}"
                                Symbol="FlashOff" />
        </Grid>
    </Border>
</UserControl>