<Window
    x:Class="mpvnet.InputWindow"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:mpvnet"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    mc:Ignorable="d"
    
    Title="Input Editor"
    Height="500"
    Width="750"
    FontSize="13"
    ShowInTaskbar="False"
    Foreground="{Binding Theme.Foreground}"
    Background="{Binding Theme.Background}"
    Loaded="Window_Loaded"
    Closed="Window_Closed"
    >
    
    <Window.Resources>
        <Style x:Key="DataGridFontCentering" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HeaderStyle" TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="{DynamicResource RegionBrush}" />
            <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
            <Setter Property="MinHeight" Value="22" />
            <Setter Property="Cursor" Value="Hand" />
        </Style>

        <Style TargetType="Button">
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border x:Name="border"
                                BorderBrush="{DynamicResource PrimaryTextBrush}"
                                BorderThickness="0"
                                Background="{DynamicResource RegionBrush}">

                            <ContentPresenter HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          TextElement.FontWeight="Normal">
                            </ContentPresenter>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" TargetName="border" Value="{DynamicResource HighlightBrush}"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="BorderBrush" TargetName="border" Value="#2C628B"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" TargetName="border" Value="0.25"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <local:SearchTextBoxUserControl
            HintText="Type ? to get help."
            x:Name="SearchControl"
            Width="300"
            Margin="0,20,0,20"
            Grid.ColumnSpan="2" 
            />

        <DataGrid
            Name="DataGrid"
            Grid.Row="1"
            CommandManager.PreviewCanExecute="DataGrid_PreviewCanExecute"
            AutoGenerateColumns="False"
            ColumnHeaderStyle="{StaticResource HeaderStyle}"
            Foreground="{Binding Theme.Foreground}"
            Background="{Binding Theme.Background}"
            RowBackground="{Binding Theme.Background}"
            HorizontalGridLinesBrush="{Binding Theme.Foreground}"
            VerticalGridLinesBrush="{Binding Theme.Foreground}"
            CellStyle="{StaticResource DataGridFontCentering}"
            >

            <DataGrid.Resources>
                <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}">
                    <Setter Property="Background" Value="{Binding DataContext.Theme.Background, ElementName=DataGrid}" />
                </Style>
            </DataGrid.Resources>
            
            <DataGrid.Columns>
                <DataGridTextColumn Header="Menu" Binding="{Binding Path}"/>
                
                <DataGridTemplateColumn Header="Input">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button MinHeight="20" Click="ButtonClick">
                                <TextBlock Text="{Binding Input}"></TextBlock>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTextColumn Header="Command" Binding="{Binding Command}" MaxWidth="330" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>