<UserControl x:Class="HandBrakeWPF.Views.MetaDataView"
             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:Properties="clr-namespace:HandBrakeWPF.Properties"
             xmlns:behaviours="clr-namespace:HandBrakeWPF.Behaviours"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">

    <UserControl.Resources>
        <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="Margin" Value="0,5,0,0"></Setter>
        </Style>
    </UserControl.Resources>

    <Grid Margin="10,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Text="{x:Static Properties:Resources.MetaDataView_Title}" FontWeight="Bold" Margin="0,5,0,0" Grid.Row="0" />

        <!-- Metadata Input Area -->
        <Grid Grid.Row="1"  Margin="0,10,10,10">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>


            <ListView Grid.Row="0"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" x:Name="metadataList"
                      Background="Transparent"
                      ItemsSource="{Binding SourceMetadata}" 
                      BorderBrush="{StaticResource Ui.ContrastLight}"
                      KeyboardNavigation.TabNavigation="Continue"
                      KeyDown="MetadataList_OnKeyDown"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                      SelectionMode="Single">

                <ListView.Resources>
                    <Style TargetType="{x:Type GridViewColumnHeader}" >
                        <Setter Property="Template" >
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                                    <Border BorderBrush="{StaticResource Ui.ContrastLight}" BorderThickness="0,0,0,1" Margin="0,0,0,5">
                                        <TextBlock Text="{TemplateBinding Content}" TextAlignment="Left" Margin="0,2,0,3" Style="{StaticResource sectionHeader}"
                                       TextTrimming="CharacterEllipsis"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListView.Resources>

                <ListView.View>
                    <GridView AllowsColumnReorder="False">
                        <GridViewColumn Header="" Width="10" />
                        <!-- TODO Localise if we ever decide to enable this functionality in the UI.-->
                        <GridViewColumn Header="Annotation" Width="170" />
                        <GridViewColumn Header="Value" Width="250" />
                    </GridView>
                </ListView.View>

                <ListView.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Margin" Value="0,0,0,1" />
                    </Style>
                </ListView.ItemContainerStyle>


                <ListView.ItemTemplate>
                    <DataTemplate>

                        <Grid HorizontalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="10" />
                                <ColumnDefinition Width="170" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Grid.Column="1" Text="{Binding Annotation}" HorizontalAlignment="Left" Margin="0,0,0,0" />

                            <TextBox Grid.Column="2" Text="{Binding Value}" x:Name="metadataValue" behaviours:TextBoxBehavior.TripleClickSelectAll="True" 
                                     TextWrapping="Wrap" HorizontalAlignment="Stretch" Padding="0,2,0,2" PreviewMouseDown="MetadataValue_OnPreviewMouseDown" />

                        </Grid>

                    </DataTemplate>
                </ListView.ItemTemplate>

            </ListView>

        </Grid>

    </Grid>
    
</UserControl>
