<UserControl x:Class="HandBrakeWPF.Views.VideoView"
             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:Converters="clr-namespace:HandBrakeWPF.Converters"
             xmlns:Video="clr-namespace:HandBrakeWPF.Converters.Video"
             xmlns:Properties="clr-namespace:HandBrakeWPF.Properties"
             xmlns:cal="http://www.caliburnproject.org"
             mc:Ignorable="d" >

    <UserControl.Resources>
        <Converters:BooleanConverter x:Key="boolConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
        <Converters:EnumComboConverter x:Key="enumComboConverter" />
        <Converters:InverseBooleanConverter x:Key="inverseConverter" />
        <Video:VideoEncoderConverter x:Key="videoEncoderConverter" />
    </UserControl.Resources>

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


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

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

            <StackPanel Orientation="Vertical" Grid.Column="0" >

                <TextBlock Text="Video" FontWeight="Bold" Margin="0,0,0,10"/>

                <StackPanel Orientation="Horizontal" Margin="0,0,0,10" >
                    <TextBlock Text="Video Codec:" Width="100" />

                    <ComboBox Width="120">
                        <ComboBox.SelectedItem>
                            <MultiBinding Converter="{StaticResource videoEncoderConverter}">
                                <Binding Path="SelectedVideoEncoder" />
                            </MultiBinding>
                        </ComboBox.SelectedItem>
                        <ComboBox.ItemsSource>
                            <MultiBinding Converter="{StaticResource videoEncoderConverter}">
                                <Binding Path="VideoEncoders"/>
                                <Binding Path="Task" />
                            </MultiBinding>
                        </ComboBox.ItemsSource>
                    </ComboBox>

                </StackPanel>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Framerate (FPS):" VerticalAlignment="Top" Margin="0,5,0,0" Width="100"/>
                    <StackPanel Orientation="Vertical">
                        <ComboBox Width="120" ItemsSource="{Binding Framerates}" SelectedItem="{Binding SelectedFramerate}"  
                                  Visibility="{Binding DisplayNonQSVControls, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />
                        <TextBlock Text="Same as source"  VerticalAlignment="Center" Margin="0,5,0,0"
                                   Visibility="{Binding DisplayNonQSVControls, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}"/>

                        <StackPanel Orientation="Vertical" Visibility="{Binding DisplayNonQSVControls, Converter={StaticResource boolToVisConverter}}">
                            <RadioButton Content="Constant Framerate" IsChecked="{Binding IsConstantFramerate}" Margin="0,5,0,0" />
                            <RadioButton Content="Variable Framerate" IsChecked="{Binding IsVariableFramerate}" Margin="0,5,0,0" 
                                     Visibility="{Binding ShowPeakFramerate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
                            <RadioButton Content="Peak Framerate" IsChecked="{Binding IsPeakFramerate}" Margin="0,5,0,0"
                                     Visibility="{Binding ShowPeakFramerate, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </StackPanel>


            <StackPanel Orientation="Vertical" Grid.Column="1">
                <TextBlock Text="Quality" FontWeight="Bold" Margin="0,0,0,10"/>

                <StackPanel Orientation="Horizontal" Margin="0,0,0,10" >
                    <RadioButton Content="Constant Quality:" IsChecked="{Binding IsConstantQuantity}"  Margin="0,0,10,0" />
                    <TextBlock Text="{Binding DisplayRF}" MinWidth="30" />
                    <TextBlock Text="{Binding Rfqp}" FontWeight="Bold" Margin="5,0,0,0" />

                    <TextBlock Text="{x:Static Properties:Resources.Video_LosslessWarning}" Visibility="{Binding IsLossless, Converter={StaticResource boolToVisConverter}}" 
                           Margin="10,0,0,0" ToolTip="{x:Static Properties:Resources.Video_LosslessWarningTooltip}" FontWeight="Bold" />
                </StackPanel>

                <Slider Width="280" Value="{Binding RF, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"  Maximum="{Binding QualityMax}" Minimum="{Binding QualityMin}"
                        IsEnabled="{Binding IsConstantQuantity}" Margin="20,0,0,10"
                        ToolTip="{x:Static Properties:Resources.Video_QualitySlider}" Style="{StaticResource LongToolTipHolder}" 
                        IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" />

                <Grid Margin="20,0,0,15" Width="280" HorizontalAlignment="Left">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{x:Static Properties:Resources.Video_LowQuality}" />
                    <TextBlock Text="{Binding HighQualityLabel}" HorizontalAlignment="Right" Grid.Column="1" />
                </Grid>

                <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                    <RadioButton Content="Avg Bitrate (kbps):" IsChecked="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="0,0,10,0"/>
                    <TextBox Width="75" Text="{Binding Task.VideoBitrate, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="30,0,0,0" Visibility="{Binding DisplayNonQSVControls, Converter={StaticResource boolToVisConverter}}">
                    <CheckBox Content="2-Pass Encoding" IsEnabled="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}"
                              IsChecked="{Binding TwoPass}" Margin="0,0,10,0" />
                    <CheckBox Content="Turbo first pass" IsEnabled="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}"
                              IsChecked="{Binding TurboFirstPass}" Visibility="{Binding DisplayTurboFirstPass, Converter={StaticResource boolToVisConverter}}" />
                </StackPanel>

            </StackPanel>

            <!-- H264 settings -->
            <Grid Grid.Row="1" Grid.ColumnSpan="2" Margin="0,10,0,0" Visibility="{Binding DisplayH264Options, Converter={StaticResource boolToVisConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Text="Optimise Video:" Margin="0,0,0,8" Grid.Row="0"  Grid.ColumnSpan="2" FontWeight="Bold" VerticalAlignment="Center" />

                <CheckBox Content="Use Advanced Tab instead" Grid.Row="1" IsChecked="{Binding UseAdvancedTab}" 
                          Visibility="{Binding ShowAdvancedTab, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />

                <Grid Grid.Row="2" Margin="0,5,0,0" IsEnabled="{Binding UseAdvancedTab, Converter={StaticResource inverseConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

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



                    <!-- Row 1 -->
                    <TextBlock Text="x264 Preset:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"
                               Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" />
                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal"
                                Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" >
                        <Slider Minimum="0" Maximum="9" Width="150" Value="{Binding X264PresetValue, Mode=Default, UpdateSourceTrigger=PropertyChanged}" 
                            IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" ToolTip="{x:Static Properties:Resources.Video_EncoderPreset}" 
                            Style="{StaticResource LongToolTipHolder}" />
                        <TextBlock Text="{Binding X264Preset, Converter={StaticResource enumComboConverter}}" Margin="5,0,0,0" />
                    </StackPanel>

                    <TextBlock Text="x264 Tune:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0,10,0,0" 
                               Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" />
                    <ComboBox Width="100" Grid.Row="2" Grid.Column="1" Margin="5,10,5,0" Height="22"
                              ItemsSource="{Binding X264Tunes, Converter={StaticResource enumComboConverter}}" 
                              SelectedItem="{Binding X264Tune, Converter={StaticResource enumComboConverter}}"
                              Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}"
                              ToolTip="{x:Static Properties:Resources.Video_EncoderTune}"
                              Style="{StaticResource LongToolTipHolder}" />
                    <CheckBox IsChecked="{Binding FastDecode}" Content="Fast Decode" Grid.Row="2" Grid.Column="2" Margin="10,10,10,0" VerticalAlignment="Center"
                              Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}"
                              ToolTip="{x:Static Properties:Resources.Video_x264FastDecode}"/>

                    <TextBlock Text="QSV Preset:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"
                               Visibility="{Binding DisplayQSVOptions, Converter={StaticResource boolToVisConverter}}" />
                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal"
                                Visibility="{Binding DisplayQSVOptions, Converter={StaticResource boolToVisConverter}}" >
                        <Slider Minimum="0" Maximum="{Binding QsvSliderMax}" Width="150" Value="{Binding QsvPresetValue, Mode=Default, UpdateSourceTrigger=PropertyChanged}" 
                            IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" />
                        <TextBlock Text="{Binding QsvPreset, Converter={StaticResource enumComboConverter}}" Margin="5,0,0,0" />
                    </StackPanel>


                    <!-- Row 2-->
                    <TextBlock Text="H.264 Profile:" Grid.Row="3" Grid.Column="0" Margin="0,10,0,0" VerticalAlignment="Center" />
                    <ComboBox Width="100" Grid.Row="3" Grid.Column="1" Margin="5,10,5,0" Height="22" VerticalAlignment="Center"
                          ItemsSource="{Binding H264Profiles, Converter={StaticResource enumComboConverter}}" 
                          SelectedItem="{Binding H264Profile, Converter={StaticResource enumComboConverter}}"
                          Style="{StaticResource LongToolTipHolder}"
                          ToolTip="{x:Static Properties:Resources.Video_EncoderProfile}" />

                    <TextBlock Text="H.264 Level:" Grid.Row="3" Grid.Column="2" Margin="10,10,0,0" VerticalAlignment="Center" />
                    <ComboBox Width="100" Grid.Row="3" Grid.Column="3" Margin="5,10,5,0" Height="22" VerticalAlignment="Center"
                          ItemsSource="{Binding H264Levels}" 
                          SelectedItem="{Binding H264Level}"
                          Style="{StaticResource LongToolTipHolder}"
                          ToolTip="{x:Static Properties:Resources.Video_EncoderLevel}"/>

                    <!-- Row 3 -->
                    <TextBlock Text="Extra Options:" Grid.Row="4" Grid.Column="0" Margin="0,10,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"
                               Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" />
                    <TextBox Text="{Binding ExtraArguments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Height="30" MaxLines="2" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,10,0,0" VerticalAlignment="Center"
                             ToolTip="{Binding FullOptionsTooltip}" Style="{StaticResource LongToolTipHolder}"
                             Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" >
                        <TextBox.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Copy Full Query" cal:Message.Attach="[Event Click] = [Action CopyQuery]"  />
                            </ContextMenu>
                        </TextBox.ContextMenu>
                    </TextBox>


                </Grid>
            </Grid>


            <!-- H265 settings -->

            <Grid Grid.Row="1" Grid.ColumnSpan="2" Margin="0,10,0,0" Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Text="Optimise Video:" Margin="0,0,0,8" Grid.Row="0"  Grid.ColumnSpan="2" FontWeight="Bold" VerticalAlignment="Center" />

                <CheckBox Content="Use Advanced Tab instead" Grid.Row="1" IsChecked="{Binding UseAdvancedTab}" 
                           Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />

                <Grid Grid.Row="2" Margin="0,5,0,0" IsEnabled="{Binding UseAdvancedTab, Converter={StaticResource inverseConverter}}">

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

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


                    <!-- Row 1 -->

                    <TextBlock Text="x265 Preset:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"
                                Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" />
                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal"
                                 Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" >
                        <Slider Minimum="0" Maximum="9" Width="150" Value="{Binding X265PresetValue, Mode=Default, UpdateSourceTrigger=PropertyChanged}" 
                             IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" ToolTip="{x:Static Properties:Resources.Video_EncoderPreset}" 
                             Style="{StaticResource LongToolTipHolder}" />
                        <TextBlock Text="{Binding X265Preset}" Margin="5,0,0,0" />
                    </StackPanel>

                    <TextBlock Text="x265 Tune:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0,10,0,0" 
                                Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" />
                    <ComboBox Width="100" Grid.Row="2" Grid.Column="1" Margin="5,10,5,0" Height="22"
                               ItemsSource="{Binding X265Tunes}" 
                               SelectedItem="{Binding X265Tune}"
                               Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}"
                               ToolTip="{x:Static Properties:Resources.Video_EncoderTune}"
                               Style="{StaticResource LongToolTipHolder}" />

                    <TextBlock Text="H.265 Profile:" Grid.Row="2" Grid.Column="2" Margin="10,10,0,0" VerticalAlignment="Center" 
                                Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" />
                    <ComboBox Width="100" Grid.Row="2" Grid.Column="3" Margin="5,10,5,0" Height="22" VerticalAlignment="Center"
                               Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}"
                           ItemsSource="{Binding H265Profiles}" 
                           SelectedItem="{Binding H265Profile}"
                           Style="{StaticResource LongToolTipHolder}"
                           ToolTip="{x:Static Properties:Resources.Video_EncoderProfile}" />

                    <!-- Row 3 -->
                    <TextBlock Text="Extra Options:" Grid.Row="4" Grid.Column="0" Margin="0,10,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"
                                Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" />
                    <TextBox Text="{Binding ExtraArguments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              Height="30" MaxLines="2" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,10,0,0" VerticalAlignment="Center"
                              ToolTip="{Binding FullOptionsTooltip}" Style="{StaticResource LongToolTipHolder}"
                              Visibility="{Binding DisplayX265Options, Converter={StaticResource boolToVisConverter}}" >
                        <TextBox.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Copy Full Query" cal:Message.Attach="[Event Click] = [Action CopyQuery]"  />
                            </ContextMenu>
                        </TextBox.ContextMenu>
                    </TextBox>
                </Grid>
            </Grid>
        </Grid>

    </Grid>
</UserControl>
