<Window x:Class="PixiEditor.Views.Dialogs.DebugDialogs.Localization.LocalizationDebugWindow"
        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:local="clr-namespace:PixiEditor.Views.Dialogs.DebugDialogs.Localization"
        xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
        xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours"
        xmlns:views="clr-namespace:PixiEditor.Views"
        xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
        xmlns:enums="clr-namespace:PixiEditor.Models.Enums"
        xmlns:helpers="clr-namespace:PixiEditor.Helpers"
        xmlns:xaml="clr-namespace:PixiEditor.Models.Commands.XAML"
        xmlns:dialogs="clr-namespace:PixiEditor.Views.Dialogs"
        xmlns:globalization="clr-namespace:System.Globalization;assembly=System.Runtime"
        xmlns:main="clr-namespace:PixiEditor.ViewModels.SubViewModels.Main"
        xmlns:localization="clr-namespace:PixiEditor.Extensions.Common.Localization;assembly=PixiEditor.Extensions"
        xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
        x:Name="popup"
        mc:Ignorable="d"
        Foreground="White"
        ui:Translator.Key="LOCALIZATION_DEBUG_WINDOW_TITLE"
        MinHeight="240" MinWidth="465"
        Height="350" Width="465"
        FlowDirection="{helpers:Localization FlowDirection}"
        d:DataContext="{d:DesignInstance local:LocalizationDataContext}">

    <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>

    <Window.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}" />
    </Window.Resources>

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

        <b:Interaction.Behaviors>
            <behaviours:ClearFocusOnClickBehavior />
        </b:Interaction.Behaviors>

        <dialogs:DialogTitleBar TitleKey="LOCALIZATION_DEBUG_WINDOW_TITLE"
                                CloseCommand="{x:Static SystemCommands.CloseWindowCommand}" />

        <StackPanel Grid.Row="1" Margin="5">
            <StackPanel Orientation="Horizontal" Height="25">
                <TextBlock ui:Translator.Key="LOCALIZATION_VIEW_TYPE" Margin="0,0,5,0" MinWidth="160" />
                <ComboBox
                    SelectedItem="{Binding DebugViewModel.LocalizationKeyShowMode}"
                    ItemsSource="{helpers:Enum {x:Type localization:LocalizationKeyShowMode}}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Height="25" Margin="0,5,0,0">
                <TextBlock ui:Translator.Key="FORCE_OTHER_FLOW_DIRECTION" Margin="0,0,5,0" MinWidth="160" />
                <CheckBox IsChecked="{Binding DebugViewModel.ForceOtherFlowDirection}" />
            </StackPanel>
            <Button ui:Translator.Key="LOAD_LANGUAGE_FROM_FILE"
                    Command="{xaml:Command PixiEditor.Debug.SetLanguageFromFilePicker}"
                    Style="{StaticResource DarkRoundButton}" Margin="0,5,0,0" />
            <TextBlock Text="POEditor" FontWeight="Bold" FontSize="22" Margin="0,10,0,0" />
            <Grid Height="25">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
                <TextBlock ui:Translator.Key="API_KEY" Margin="0,0,5,0"></TextBlock>
                <TextBox Grid.Column="1" Style="{StaticResource DarkTextBoxStyle}" TextChanged="ApiKeyChanged"
                         Text="{Binding ApiKey}">
                </TextBox>
                <Button Margin="5,0,0,0" Grid.Column="2"
                        ui:Translator.Key="LOG_IN"
                        Command="{Binding LoadApiKeyCommand}" />
            </Grid>
            <StackPanel
                Visibility="{Binding LoggedIn, Mode=OneWay, Converter={BoolToVisibilityConverter}}">
                <Grid Margin="0,5,0,0" Height="25">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock ui:Translator.Key="LANGUAGE" Margin="0,0,5,0" />
                    <Grid Grid.Column="1">
                        <ComboBox ItemsSource="{Binding LanguageCodes}"
                                  SelectedItem="{Binding SelectedLanguage}"
                                  x:Name="LanguageComboBox">
                            <ComboBox.ItemContainerStyle>
                                <Style TargetType="ComboBoxItem">
                                    <Setter Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate DataType="local:PoeLanguage">
                                                <StackPanel Orientation="Horizontal">
                                                    <Ellipse Width="10" Height="10"
                                                             VerticalAlignment="Center"
                                                             Fill="{Binding StatusBrush}"
                                                             Margin="0,0,5,0" />
                                                    <TextBlock VerticalAlignment="Center">
                                                        <Run Text="{Binding Name}"/>
                                                        <Run Text="{Binding Code, StringFormat='(\{0\})'}"/>
                                                    </TextBlock>
                                                </StackPanel>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <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>
                        <TextBlock ui:Translator.Key="SELECT_A_LANGUAGE" Visibility="{Binding SelectedItem, ElementName=LanguageComboBox, Converter={converters:NullToVisibilityConverter}}"
                                   Margin="5,0,0,0" VerticalAlignment="Center"
                                   IsHitTestVisible="False">
                        </TextBlock>
                    </Grid>
                </Grid>
                <Border Background="{StaticResource DarkerAccentColor}" Padding="5"
                        BorderThickness="1" CornerRadius="5" BorderBrush="{StaticResource BrighterAccentColor}" 
                        Margin="0,5,0,5"
                        Visibility="{Binding SelectedLanguage, Converter={converters:NotNullToVisibilityConverter}}">
                    <StackPanel>
                        <Grid Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock>
                                <Run Text="{Binding SelectedLanguage.Name}"/>
                                <Run Text="{Binding SelectedLanguage.Code, StringFormat='(\{0\})'}"/>
                            </TextBlock>
                            <TextBlock Grid.Column="1">
                                <Run Text="{Binding SelectedLanguage.Percentage, Mode=OneWay, StringFormat='\{0\}%'}"/>
                                <Run ui:Translator.Key="DONE"/>
                            </TextBlock>
                        </Grid>
                        <Grid Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="4" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Border Background="{Binding SelectedLanguage.StatusBrush}" CornerRadius="2" />
                            <TextBlock Grid.Column="1" ui:Translator.LocalizedString="{Binding SelectedLanguage.StatusText}" Margin="5,0" />
                            <TextBlock Grid.Column="2" ui:Translator.TooltipKey="COPY_TO_CLIPBOARD">
                                <Hyperlink Command="{Binding CopySelectedUpdatedCommand}">
                                    <Run
                                        Text="{Binding SelectedLanguage.UpdatedLocal, Mode=OneWay, StringFormat='g', ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}" />
                                    <Run Text=" &#xe855;" FontFamily="{StaticResource Feather}" />
                                </Hyperlink>
                            </TextBlock>
                        </Grid>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="{Binding Source={x:Static main:DebugViewModel.IsDebugBuild}, Converter={converters:BoolToValueConverter FalseValue=Auto, TrueValue=*}}" />
                            </Grid.ColumnDefinitions>
                            <Button ui:Translator.Key="APPLY" Command="{Binding ApplyLanguageCommand}" />
                            <Button Grid.Column="1" Margin="5,0,0,0"  ui:Translator.Key="UPDATE_SOURCE" Command="{Binding UpdateSourceCommand}"
                                    Visibility="{Binding Source={x:Static main:DebugViewModel.IsDebugBuild}, Converter={BoolToVisibilityConverter}}"/>
                        </Grid>
                    </StackPanel>
                </Border>
            </StackPanel>
            <TextBlock Text="{Binding StatusMessage}" />
        </StackPanel>
    </Grid>
</Window>