<UserControl x:Class="HandBrakeWPF.Views.SubtitlesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:Converters="clr-namespace:HandBrakeWPF.Converters"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:NumericUpDown="clr-namespace:EagleBoost.Wpf.Presentation.Controls.NumericUpDown;assembly=EagleBoost.Wpf.Presentation"
             xmlns:controls="clr-namespace:HandBrakeWPF.Controls"
             d:DesignHeight="153"
             d:DesignWidth="319"
             mc:Ignorable="d">
    <UserControl.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="booleanToVisConverter" />
    </UserControl.Resources>

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

        <TextBlock Grid.Row="0"
                   Margin="10,5,0,0"
                   FontWeight="Bold"
                   Text="Subtitles" />

        <Grid Grid.Row="1" Margin="10,5,10,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Button Name="AddTrack"
                    Grid.Column="0"
                    Width="75"
                    Margin="0,0,10,0"
                    cal:Message.Attach="[Event Click] = [Action Add]"
                    Content="Add" />
            <Button Grid.Column="2"
                    MaxWidth="100"
                    cal:Message.Attach="[Event Click] = [Action Import]"
                    Content="Import SRT" />
        </Grid>

        <ListBox Grid.Row="2"
                 Margin="10,10,10,10"
                 Background="LightGray"
                 dd:DragDrop.DropHandler="{Binding}"
                 dd:DragDrop.IsDragSource="True"
                 dd:DragDrop.IsDropTarget="True"
                 ItemsSource="{Binding Task.SubtitleTracks}"
                 SelectionMode="Extended">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="Background" Value="WhiteSmoke" />
                    <Setter Property="Margin" Value="0,0,0,1" />
                </Style>
            </ListBox.ItemContainerStyle>

            <ListBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Add New Track" cal:Message.Attach="[Event Click] = [Action Add]" />
                    <MenuItem Header="Add All Remaining Tracks" cal:Message.Attach="[Event Click] = [Action AddAllRemaining]" />
                    <MenuItem Header="Add All Remaining Closed Captions" cal:Message.Attach="[Event Click] = [Action AddAllClosedCaptions]" />
                    <MenuItem Header="Add All Remaining Selected Languages" cal:Message.Attach="[Event Click] = [Action AddAllRemainingForSelectedLanguages]" />    
                    <Separator />
                    <MenuItem Header="Clear All" cal:Message.Attach="[Event Click] = [Action Clear]" />
                    <Separator />
                    <MenuItem Header="Configure Default Behaviours" cal:Message.Attach="[Event Click] = [Action SetDefaultBehaviour]" />
                </ContextMenu>
            </ListBox.ContextMenu>

            <ListBox.ItemTemplate>
                <DataTemplate>

                    <Grid HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <!--  Marker  -->
                        <Image Grid.Column="0"
                               Width="16"
                               Height="16"
                               Margin="10,0,10,0"
                               Source="Images/Movies.png" />

                        <!--  Settings  -->
                        <Grid Grid.Column="1" HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" MaxWidth="300" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="28" />
                                <RowDefinition Height="28" />
                            </Grid.RowDefinitions>

                            <!--  Row 1  -->

                            <TextBlock Grid.Column="0"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Source" />
                            <ComboBox Grid.Column="1"
                                      Height="22"
                                      MaxWidth="300"
                                      Margin="5,0,5,0"
                                      HorizontalAlignment="Stretch"
                                      ItemsSource="{Binding DataContext.SourceTracks,
                                                            RelativeSource={RelativeSource FindAncestor,
                                                                                           AncestorType={x:Type UserControl}}}"
                                      SelectedItem="{Binding SourceTrack}"
                                      Visibility="{Binding IsSrtSubtitle,
                                                           Converter={StaticResource booleanToVisConverter},
                                                           ConverterParameter=true}" />
                            <TextBlock Grid.Column="1"
                                       VerticalAlignment="Center"
                                       Text="{Binding SrtFileName}"
                                       Visibility="{Binding IsSrtSubtitle,
                                                            Converter={StaticResource booleanToVisConverter},
                                                            ConverterParameter=false}" />

                            <TextBlock Grid.Column="2"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Forced Only"
                                       Visibility="{Binding IsSrtSubtitle,
                                                            Converter={StaticResource booleanToVisConverter},
                                                            ConverterParameter=true}" />
                            <CheckBox Grid.Column="3"
                                      Margin="5,0,5,0"
                                      VerticalAlignment="Center"
                                      IsEnabled="{Binding CanBeForced}"
                                      IsChecked="{Binding Forced}"
                                      Visibility="{Binding IsSrtSubtitle,
                                                           Converter={StaticResource booleanToVisConverter},
                                                           ConverterParameter=true}" />
                            <TextBlock Grid.Column="4"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Burn In"
                                       Visibility="{Binding IsSrtSubtitle,
                                                            Converter={StaticResource booleanToVisConverter},
                                                            ConverterParameter=true}" />
                            <CheckBox Grid.Column="5"
                                      Margin="5,0,5,0"
                                      VerticalAlignment="Center"
                                      IsChecked="{Binding Burned}"
                                      IsEnabled="{Binding CanBeBurned}"
                                      Visibility="{Binding IsSrtSubtitle,
                                                           Converter={StaticResource booleanToVisConverter},
                                                           ConverterParameter=true}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <cal:ActionMessage MethodName="SelectBurnedInTrack">
                                            <cal:Parameter Value="{Binding}" />
                                        </cal:ActionMessage>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </CheckBox>
                            <TextBlock Grid.Column="6"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Default" />
                            <CheckBox Grid.Column="7"
                                      Margin="5,0,5,0"
                                      VerticalAlignment="Center"
                                      IsChecked="{Binding Default}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="Click">
                                        <cal:ActionMessage MethodName="SelectDefaultTrack">
                                            <cal:Parameter Value="{Binding}" />
                                        </cal:ActionMessage>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </CheckBox>

                            <!--  Row 2  -->
                            <TextBlock Grid.Row="1"
                                       Grid.Column="0"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Language" />
                            <ComboBox Grid.Row="1"
                                      Grid.Column="1"
                                      Height="22"
                                      MaxWidth="300"
                                      Margin="5,0,5,0"
                                      HorizontalAlignment="Stretch"
                                      IsEnabled="{Binding IsSrtSubtitle}"
                                      ItemsSource="{Binding DataContext.Langauges,
                                                            RelativeSource={RelativeSource FindAncestor,
                                                                                           AncestorType={x:Type UserControl}}}"
                                      SelectedItem="{Binding SrtLang}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="2"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Char Code" />
                            <ComboBox Grid.Row="1"
                                      Grid.Column="3"
                                      Width="100"
                                      Height="22"
                                      Margin="5,0,5,0"
                                      IsEnabled="{Binding IsSrtSubtitle}"
                                      ItemsSource="{Binding DataContext.CharacterCodes,
                                                            RelativeSource={RelativeSource FindAncestor,
                                                                                           AncestorType={x:Type UserControl}}}"
                                      SelectedItem="{Binding SrtCharCode}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="4"
                                       VerticalAlignment="Center"
                                       FontWeight="Bold"
                                       Text="Offset (ms)" />

                            <controls:NumberBox Grid.Row="1" Grid.Column="5" Width="65" Height="24" Margin="5,0,5,0"
                                            Minimum="-900000" Maximum="900000" IsEnabled="{Binding IsSrtSubtitle}"
                                            Number="{Binding SrtOffset, Mode=TwoWay}" />
                            
                        </Grid>

                        <!--  Delete  -->
                        <Image Grid.Column="2"
                               Width="16"
                               Height="16"
                               Margin="10,0,10,0"
                               Source="Images/delete.png">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="MouseDown">
                                    <cal:ActionMessage MethodName="Remove">
                                        <cal:Parameter Value="{Binding}" />
                                    </cal:ActionMessage>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Image>

                    </Grid>


                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


    </Grid>
</UserControl>
