<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"
             mc:Ignorable="d" >

    <UserControl.Resources>
        <Converters:BooleanConverter x:Key="boolConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
        <Video:VideoEncoderConverter x:Key="videoEncoderConverter" />
        <Video:VideoColourRangeConverter x:Key="videoColourRangeConverter" />
    </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="2*" />
                <ColumnDefinition Width="4*" />
            </Grid.ColumnDefinitions>

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

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

                <TextBlock Text="{x:Static Properties:Resources.VideoView_Video}" Style="{StaticResource sectionHeader}" Margin="0,0,0,10"/>

                <StackPanel Orientation="Horizontal" Margin="0,0,0,10" >
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_Codec}" Width="100" />

                    <ComboBox Width="120" DisplayMemberPath="DisplayName" ToolTip="{x:Static Properties:ResourcesTooltips.Video_Encoders}" AutomationProperties.Name="{x:Static Properties:Resources.VideoView_Codec}" >
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="ComboBoxItem">
                                <Setter Property="AutomationProperties.Name" Value="{Binding DisplayName}" />
                            </Style>
                        </ComboBox.ItemContainerStyle>
                        <ComboBox.SelectedItem>
                            <MultiBinding Converter="{StaticResource videoEncoderConverter}">
                                <Binding Path="SelectedVideoEncoder" />
                            </MultiBinding>
                        </ComboBox.SelectedItem>
                        <ComboBox.ItemsSource>
                            <MultiBinding Converter="{StaticResource videoEncoderConverter}">
                                <Binding Path="VideoEncoders"/>
                                <Binding Path="Task" />
                                <Binding Path="UserSettingService" />
                            </MultiBinding>
                        </ComboBox.ItemsSource>
                    </ComboBox>

                </StackPanel>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_Framerate}" VerticalAlignment="Top" Margin="0,5,0,0" Width="100"/>
                    <StackPanel Orientation="Vertical">
                        <ComboBox Width="120" ItemsSource="{Binding Framerates}" SelectedItem="{Binding SelectedFramerate}" ToolTip="{x:Static Properties:ResourcesTooltips.Video_Framerate}"
                                  AutomationProperties.Name="{x:Static Properties:Resources.VideoView_Framerate}" HorizontalAlignment="Left" />

                        <StackPanel Orientation="Vertical" >
                            <RadioButton Content="{x:Static Properties:Resources.VideoView_ConstantFramerate}" IsChecked="{Binding IsConstantFramerate}" Margin="0,5,0,0"
                                         ToolTip="{x:Static Properties:ResourcesTooltips.Video_ConstantFramerate}" />
                            <RadioButton Content="{x:Static Properties:Resources.VideoView_VariableFramerate}" IsChecked="{Binding IsVariableFramerate}" Margin="0,5,0,0" 
                                     Visibility="{Binding ShowPeakFramerate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" ToolTip="{x:Static Properties:ResourcesTooltips.Video_VariableFramerate}"  />
                            <RadioButton Content="{x:Static Properties:Resources.VideoView_PeakFramerate}" IsChecked="{Binding IsPeakFramerate}" Margin="0,5,0,0"
                                     Visibility="{Binding ShowPeakFramerate, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" ToolTip="{x:Static Properties:ResourcesTooltips.Video_PeakFramerate}"  />
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,10,0,10" >
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_ColourRange}" Width="100" />

                    <ComboBox Width="120" AutomationProperties.Name="{x:Static Properties:Resources.VideoView_ColourRange}"
                        ItemsSource="{Binding ColourRanges, Converter={StaticResource videoColourRangeConverter}}" SelectedItem="{Binding ColourRange, Converter={StaticResource videoColourRangeConverter}}" HorizontalAlignment="Left"
                        ToolTip="{x:Static Properties:ResourcesTooltips.Video_ColourRange}" />
                </StackPanel>
            </StackPanel>

            <StackPanel Orientation="Vertical" Grid.Column="1">
                <TextBlock Text="{x:Static Properties:Resources.VideoView_Quality}" Style="{StaticResource sectionHeader}" Margin="0,0,0,10" />

                <StackPanel Orientation="Horizontal" Margin="0,0,0,10" Visibility="{Binding IsQualitySupported, Converter={StaticResource boolToVisConverter}}">
                    <RadioButton Content="{x:Static Properties:Resources.VideoView_ConstantQuality}" IsChecked="{Binding IsConstantQuantity}"  Margin="0,0,10,0"
                                 ToolTip="{x:Static Properties:ResourcesTooltips.Video_Quality}" />
                    <TextBlock Text="{Binding DisplayRF}" MinWidth="30" Visibility="{Binding IsQualityAdjustmentSupported, Converter={StaticResource boolToVisConverter}}" />
                    <TextBlock Text="{Binding Rfqp}" FontWeight="Bold" Margin="5,0,0,0" Visibility="{Binding IsQualityAdjustmentSupported, Converter={StaticResource boolToVisConverter}}" />
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_LosslessEncodeOnly}" VerticalAlignment="Center"  Visibility="{Binding SelectedVideoEncoder.IsLossless, Converter={StaticResource boolToVisConverter}}" />

                </StackPanel>

                <Slider Value="{Binding RF, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch"  Maximum="{Binding QualityMax}" Minimum="{Binding QualityMin}"
                        IsEnabled="{Binding IsConstantQuantity}" Margin="20,0,10,10" Visibility="{Binding IsQualityAdjustmentSupported, Converter={StaticResource boolToVisConverter}}"
                        ToolTip="{x:Static Properties:ResourcesTooltips.Video_Quality}" Style="{StaticResource LongToolTipHolder}" 
                        IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" />

                <Grid Margin="20,0,14,15" HorizontalAlignment="Stretch" Visibility="{Binding IsQualityAdjustmentSupported, Converter={StaticResource boolToVisConverter}}">
                    <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" Visibility="{Binding IsBitrateSupported, Converter={StaticResource boolToVisConverter}}">
                    <RadioButton Content="{x:Static Properties:Resources.VideoView_AverageBitrate}" ToolTip="{x:Static Properties:ResourcesTooltips.Video_AvgBitrate}" 
                                 IsChecked="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}" Margin="0,0,10,0"/>
                    <TextBox Width="75" Text="{Binding VideoBitrate, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}"
                             ToolTip="{x:Static Properties:ResourcesTooltips.Video_AvgBitrate}" AutomationProperties.Name="{x:Static Properties:Resources.VideoView_AverageBitrate}"  />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="25,0,0,0" Visibility="{Binding DisplayMultiPass, Converter={StaticResource boolToVisConverter}}">
                    <CheckBox Content="{x:Static Properties:Resources.VideoView_MultiPass}" IsEnabled="{Binding IsMultiPassEnabled, Converter={StaticResource boolConverter}}"
                              IsChecked="{Binding MultiPass}" Margin="0,0,10,0" ToolTip="{x:Static Properties:ResourcesTooltips.Video_MultiPass}"
                              Visibility="{Binding DisplayMultiPass, Converter={StaticResource boolToVisConverter}}"/>
                    <CheckBox Content="{x:Static Properties:Resources.VideoView_TurboAnalysisPass}" IsEnabled="{Binding IsConstantQuantity, Converter={StaticResource boolConverter}, ConverterParameter=true}"
                              IsChecked="{Binding TurboAnalysisPass}" Visibility="{Binding DisplayTurboAnalysisPass, Converter={StaticResource boolToVisConverter}}"
                              ToolTip="{x:Static Properties:ResourcesTooltips.Video_TurboAnalysisPass}" />
                </StackPanel>

            </StackPanel>

            <!-- Encoder settings -->
            <Grid Grid.Row="1" Grid.ColumnSpan="2" Margin="0,5,0,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Text="{x:Static Properties:Resources.VideoView_OptimiseVideo}" Margin="0,0,0,0" Grid.Row="0"  Grid.ColumnSpan="2" Style="{StaticResource sectionHeader}" />

                <Grid Grid.Row="1" Margin="0,8,0,0">
                    <Grid.RowDefinitions>
                        <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" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <!-- Row 1 -->
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_EncoderPreset}" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Visibility="{Binding DisplayOptimiseOptions, Converter={StaticResource boolToVisConverter}}" />
                    <StackPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Orientation="Horizontal" Visibility="{Binding DisplayOptimiseOptions, Converter={StaticResource boolToVisConverter}}">
                        <Slider Minimum="0" Maximum="{Binding VideoPresetMaxValue}" Width="150" Value="{Binding VideoPresetValue, Mode=Default, UpdateSourceTrigger=PropertyChanged}" 
                            IsSnapToTickEnabled="True" TickFrequency="1" TickPlacement="BottomRight" ToolTip="{x:Static Properties:ResourcesTooltips.Video_Presets}"   />
                        <TextBlock Text="{Binding VideoPreset.DisplayName}" Margin="5,0,0,0" />
                    </StackPanel>

                    <TextBlock Text="{x:Static Properties:Resources.VideoView_EncodeTune}" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="0,5,0,0"
                               Visibility="{Binding DisplayTuneControls, Converter={StaticResource boolToVisConverter}}"/>
                    <ComboBox Width="100" Grid.Row="2" Grid.Column="1" Margin="5,5,5,0" AutomationProperties.Name="{x:Static Properties:Resources.VideoView_EncodeTune}"
                              ItemsSource="{Binding VideoTunes}" DisplayMemberPath="DisplayName" SelectedItem="{Binding VideoTune}" HorizontalAlignment="Left"
                              ToolTip="{x:Static Properties:ResourcesTooltips.Video_EncoderTune}"  Visibility="{Binding DisplayTuneControls, Converter={StaticResource boolToVisConverter}}" >
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="ComboBoxItem">
                                <Setter Property="AutomationProperties.Name" Value="{Binding DisplayName}" />
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>
                    <CheckBox IsChecked="{Binding FastDecode}" Content="{x:Static Properties:Resources.VideoView_FastDecode}" Grid.Row="2" Grid.Column="2" Margin="10,5,10,0" VerticalAlignment="Center" VerticalContentAlignment="Center"
                              ToolTip="{x:Static Properties:ResourcesTooltips.Video_FastDecode}"  Visibility="{Binding DisplayFastDecode, Converter={StaticResource boolToVisConverter}}"/>

          
                    <!-- Row 2-->
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_EncoderProfile}" Grid.Row="3" Grid.Column="0" Margin="0,5,0,0" VerticalAlignment="Center" Visibility="{Binding DisplayProfileControl, Converter={StaticResource boolToVisConverter}}"/>
                    <ComboBox Width="100" Grid.Row="3" Grid.Column="1" Margin="5,5,5,0" VerticalAlignment="Center" Visibility="{Binding DisplayProfileControl, Converter={StaticResource boolToVisConverter}}"
                          ItemsSource="{Binding VideoProfiles}" DisplayMemberPath="DisplayName" SelectedItem="{Binding VideoProfile}" HorizontalAlignment="Left" ToolTip="{x:Static Properties:ResourcesTooltips.Video_Profile}"
                              AutomationProperties.Name="{x:Static Properties:Resources.VideoView_EncoderProfile}" >
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="ComboBoxItem">
                                <Setter Property="AutomationProperties.Name" Value="{Binding DisplayName}" />
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>

                    <TextBlock Text="{x:Static Properties:Resources.VideoView_EncoderLevel}" Grid.Row="3" Grid.Column="2" Margin="10,5,0,0" VerticalAlignment="Center" Visibility="{Binding DisplayLevelControl, Converter={StaticResource boolToVisConverter}}" />
                    <ComboBox Width="100" Grid.Row="3" Grid.Column="3" Margin="5,5,5,0" VerticalAlignment="Center" Visibility="{Binding DisplayLevelControl, Converter={StaticResource boolToVisConverter}}"
                          ItemsSource="{Binding VideoLevels}"  DisplayMemberPath="DisplayName" SelectedItem="{Binding VideoLevel}" ToolTip="{x:Static Properties:ResourcesTooltips.Video_Level}"
                              AutomationProperties.Name="{x:Static Properties:Resources.VideoView_EncoderLevel}" >
                        <ComboBox.ItemContainerStyle>
                            <Style TargetType="ComboBoxItem">
                                <Setter Property="AutomationProperties.Name" Value="{Binding DisplayName}" />
                            </Style>
                        </ComboBox.ItemContainerStyle>
                    </ComboBox>

                    <!-- Row 3 -->
                    <TextBlock Text="{x:Static Properties:Resources.VideoView_ExtraOptions}" Grid.Row="4" Grid.Column="0" Margin="0,5,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" />
                    <TextBox Text="{Binding ExtraArguments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="WrapWithOverflow"
                             AutomationProperties.Name="{x:Static Properties:Resources.VideoView_ExtraOptions}" ToolTip="{Binding FullOptionsTooltip}"
                             Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" Margin="5,5,5,2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" >
                        <TextBox.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Copy Full Query" Command="{Binding RelayCommand}" CommandParameter="CopyQuery"  />
                                <Separator />
                                <MenuItem Command="ApplicationCommands.Cut" />
                                <MenuItem Command="ApplicationCommands.Copy" />
                                <MenuItem Command="ApplicationCommands.Paste" />
                            </ContextMenu>
                        </TextBox.ContextMenu>
                    </TextBox>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
