<UserControl x:Class="HandBrakeWPF.Views.ChaptersView"
             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"
             d:DesignHeight="170"
             d:DesignWidth="616"
             mc:Ignorable="d" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Margin="10,5,10,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <CheckBox Content="{x:Static Properties:Resources.ChaptersView_CreateChapterMarkers}" IsChecked="{Binding IncludeChapterMarkers}" Grid.Column="0" VerticalAlignment="Center" VerticalContentAlignment="Center" />
            <Button Content="{x:Static Properties:Resources.ChaptersView_Import}" Name="import" Grid.Column="2" Width="75" Margin="0,0,10,0" Command="{Binding RelayCommand}" CommandParameter="Import" />
            <Button Content="{x:Static Properties:Resources.ChaptersView_Export}" Name="export" Grid.Column="3" Width="75" Command="{Binding RelayCommand}" CommandParameter="Export" />
        </Grid>

        <ListView Grid.Row="1" Margin="10" VerticalAlignment="Stretch" x:Name="chaptersList"
                  Background="Transparent"
                  ItemsSource="{Binding Chapters}" 
                  BorderBrush="{StaticResource Ui.ContrastLight}"
                  KeyboardNavigation.TabNavigation="Continue"
                  KeyDown="ChaptersList_OnKeyDown"
                  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" />
                    <GridViewColumn Header="{x:Static Properties:Resources.ChaptersView_ChapterNumber}" Width="75" />
                    <GridViewColumn Header="{x:Static Properties:Resources.ChaptersView_Duration}" Width="83" />
                    <GridViewColumn Header="{x:Static Properties:Resources.ChaptersView_ChapterName}" Width="Auto" />
                </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.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{x:Static Properties:Resources.ChapterView_ImportNames}" Command="{Binding RelayCommand}" CommandParameter="Import" />
                    <MenuItem Header="{x:Static Properties:Resources.ChapterView_ExportNames}" Command="{Binding RelayCommand}" CommandParameter="Export" />
                    <Separator />
                    <MenuItem Header="{x:Static Properties:Resources.ChapterView_ResetChapterNames}" Command="{Binding RelayCommand}" CommandParameter="Reset" />
                </ContextMenu>
            </ListView.ContextMenu>

            <ListView.ItemTemplate>
                <DataTemplate>

                    <Grid HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="72" />
                            <ColumnDefinition Width="80" />
                            <ColumnDefinition Width="166" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Column="1" Text="{Binding ChapterNumber}" HorizontalAlignment="Left" Margin="15,0,0,0" />
                        <TextBlock Grid.Column="2" Text="{Binding Duration}" />
                        <TextBox Grid.Column="3" Text="{Binding ChapterName}" x:Name="chapterName" behaviours:TextBoxBehavior.TripleClickSelectAll="True" PreviewMouseDown="ChapterName_OnPreviewMouseDown" />

                    </Grid>

                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>
    </Grid>
</UserControl>
