<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"
             xmlns:converters="clr-namespace:HandBrakeWPF.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">

    <UserControl.Resources>
        <converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />

        <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="*" />
                <ColumnDefinition Width="250" />
            </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"
                      Grid.IsSharedSizeScope="true">

                <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.ContextMenu>
                    <ContextMenu>
                        <!-- Maybe Later -->
                        <!--<MenuItem Header="{x:Static Properties:Resources.MetaData_Add}" Command="{Binding RelayCommand}" CommandParameter="Add" />-->
                    </ContextMenu>
                </ListView.ContextMenu>

                <ListView.View>
                    <GridView AllowsColumnReorder="False">
                        <GridViewColumn Header="" Width="10" />
                        <!-- TODO Localise if we ever decide to enable this functionality in the UI.-->
                        <GridViewColumn Header="Enabled" Width="60" />
                        <GridViewColumn Header="Annotation" Width="170" />
                        <GridViewColumn Header="Value" Width="250" />
                        <GridViewColumn Header="" Width="50" />
                    </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="60" />
                                <ColumnDefinition Width="170" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="50" />
                            </Grid.ColumnDefinitions>

                            <CheckBox Grid.Column="1" IsChecked="{Binding Enabled}" VerticalAlignment="Center" HorizontalAlignment="Left" />

                            <!-- Annotation -->
                            <TextBlock Grid.Column="2" Text="{Binding Annotation}" HorizontalAlignment="Left" Margin="0,0,0,0"
                                       Visibility="{Binding IsNew, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}"
                                       />

                            <TextBox Grid.Column="2" Text="{Binding Annotation}"  behaviours:TextBoxBehavior.TripleClickSelectAll="True" 
                                     Visibility="{Binding IsNew, Converter={StaticResource boolToVisConverter}}" VerticalAlignment="Center"
                                     TextWrapping="Wrap" HorizontalAlignment="Stretch" Padding="0,2,0,2" Margin="1,1,10,1"  />


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


                            <!--  Delete  -->
                            <StackPanel Grid.Column="4" Grid.Row="0" VerticalAlignment="Center" Visibility="{Binding IsNew, Converter={StaticResource boolToVisConverter}}">

                                <Button Style="{StaticResource TransparentButtonStyle}" Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"          
                                        CommandParameter="{Binding}">
                                    <Button.Content>
                                        <Image Width="16" Height="16" Margin="10,0,10,0" Source="Images/close64.png" />
                                    </Button.Content>
                                </Button>
                            </StackPanel>

                        </Grid>

                    </DataTemplate>
                </ListView.ItemTemplate>

            </ListView>

            <Grid Margin="5,0,5,0" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

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

                <Grid Grid.Row="0" Grid.RowSpan="2">

                    <Border BorderBrush="DarkGray" Background="WhiteSmoke" BorderThickness="2" Canvas.ZIndex="1" 
                            Margin="20,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" CornerRadius="2" Opacity="0.9">

                        <CheckBox IsChecked="{Binding CoverArtImage.Enabled}" Canvas.ZIndex="1" Content="Enabled" VerticalAlignment="Top" HorizontalAlignment="Center" 
                                  Visibility="{Binding CoverArtImage.IsNoCoverArt, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" Margin="8,5,8,5"  />
                    </Border>
                   

                    <Image Source="{Binding CoverArtImage.Image}" Canvas.ZIndex="0">
                    </Image>

                    <TextBlock Text="No Cover Art" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding CoverArtImage.IsNoCoverArt, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" 
                           FontWeight="SemiBold" FontSize="16" />
                </Grid>

                <Grid Grid.Row="1" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>


                    
                    <Button Grid.Column="1" Margin="0,0,0,10" Command="{Binding RelayCommand}" CommandParameter="PreviousCoverArt" Content="&lt; Previous" Padding="8,2"
                            IsEnabled="{Binding IsNextAvailable}" Opacity="0.9" FontWeight="Bold"
                            Visibility="{Binding CoverArtImage.IsNoCoverArt, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
                    <Button Grid.Column="2" Margin="5,0,0,10" Command="{Binding RelayCommand}" CommandParameter="NextCoverArt" Content="Next &gt;" Padding="8,2"
                            IsEnabled="{Binding IsBackAvailable}" Opacity="0.9" FontWeight="Bold"
                            Visibility="{Binding CoverArtImage.IsNoCoverArt, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
                </Grid>


            </Grid>
    
        </Grid>

    </Grid>

</UserControl>
