<UserControl x:Class="HandBrakeWPF.Views.Options.OptionsAdvanced"
             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:Properties="clr-namespace:HandBrakeWPF.Properties"
             xmlns:options="clr-namespace:HandBrakeWPF.Converters.Options"
             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.Resources>
        <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
            <Setter Property="Margin" Value="0,0,5,0" />
        </Style>

        <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="Padding" Value="5,2" />
            <Setter Property="MinHeight" Value="22" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="ToolTipService.ShowDuration" Value="20000" />
        </Style>

        <Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
            <Setter Property="Margin" Value="0,2,0,2" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
        <options:FileSizeConverter x:Key="fileSizeConverter" />
        <options:ProcessPriorityConverter x:Key="ProcessPriorityConverter" />
        <options:LogLevelConverter x:Key="LogLevelConverter" />
        <options:DefaultRangeModeConverter x:Key="defaultRangeModeConverter" />

    </UserControl.Resources>


    <StackPanel  Name="Advanced" Orientation="Vertical" Margin="10,5,0,0">

        <TextBlock Text="{x:Static Properties:Resources.Options_Advanced}" Style="{StaticResource pageHeader}"  />

        <StackPanel Orientation="Vertical" Margin="0,10,0,10">

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

            <StackPanel Orientation="Vertical" Margin="20,0,0,0">

                <CheckBox Content="{x:Static Properties:Resources.Options_PreventSleep}" IsChecked="{Binding PreventSleep}" />

                <CheckBox Content="{x:Static Properties:Resources.Options_PauseOnLowBattery}" IsChecked="{Binding PauseOnLowBattery}" Visibility="{Binding HasSystemBattery, Converter={StaticResource boolToVisConverter}}" />
                <StackPanel Orientation="Horizontal" Margin="20,0,0,0" Visibility="{Binding HasSystemBattery, Converter={StaticResource boolToVisConverter}}">
                    <TextBlock Text="{x:Static Properties:Resources.Options_LowBatteryLevel}" Width="230" VerticalAlignment="Center" />
                    <TextBox x:Name="LowBatteryLevel" Text="{Binding LowBatteryLevel, UpdateSourceTrigger=PropertyChanged}"  Width="120" VerticalContentAlignment="Center" />
                    <TextBlock Text="%" VerticalAlignment="Center" Margin="5,0,0,0" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <CheckBox Content="{x:Static Properties:Resources.Options_LowDiskspaceSize}" IsChecked="{Binding PauseOnLowDiskspace}" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <TextBlock Text="{x:Static Properties:Resources.Options_LowDiskspaceLevelText}" TextWrapping="Wrap" Width="250"  />

                    <TextBox x:Name="PauseOnLowDiskspaceLevel" Text="{Binding PauseOnLowDiskspaceLevel, Converter={StaticResource fileSizeConverter}, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"  Width="120"/>
                    <TextBlock Text="{x:Static Properties:Resources.Options_LowDiskspaceSizeGB}" VerticalAlignment="Center" Margin="5,0,0,0" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <TextBlock Text="{x:Static Properties:Resources.Options_PriorityLevel}" Width="250" VerticalAlignment="Center" />
                    <ComboBox Name="processPriorityLevel" ItemsSource="{Binding PriorityLevelOptions, Converter={StaticResource ProcessPriorityConverter}}" SelectedItem="{Binding SelectedPriority, Converter={StaticResource ProcessPriorityConverter}}" Width="120" />
                </StackPanel>
            </StackPanel>
        </StackPanel>

        <StackPanel Orientation="Vertical" Margin="0,10,0,10">

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

            <StackPanel Orientation="Vertical" Margin="20,0,0,0">
                <CheckBox  IsChecked="{Binding RecursiveFolderScan}" Content="{x:Static Properties:Resources.Options_RecursiveFolderScan}" />

                <TextBlock Text="{x:Static Properties:Resources.Options_ExcludeExtensions}" Margin="0,5,0,0"/>
                <TextBlock Text="{x:Static Properties:Resources.Options_ExcludeExtensionsInfo}" Margin="0,0,0,10" Style="{StaticResource subText}" />

                <StackPanel Orientation="Vertical" Margin="20,0,0,0">
                    <ListBox ItemsSource="{Binding ExcludedFileExtensions}" Width="150" HorizontalAlignment="Left" Height="100" >

                        <ListBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                <Setter Property="Margin" Value="0,0,0,1" />
                            </Style>
                        </ListBox.ItemContainerStyle>

                        <ListBox.ItemTemplate>
                            <DataTemplate x:Name="ExtensionTemplate">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Text="{Binding}" />

                                    <Button Style="{StaticResource TransparentButtonStyle}" 
                                            Grid.Column="1"
                                            Command="{Binding DataContext.RemoveExtensionCommand, 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>
                                </Grid>

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

                    <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                        <TextBox Text="{Binding NewExtension}" Width="150" />
                        <Button Content="{x:Static Properties:Resources.Options_AddExt}" Command="{Binding RelayCommand}" CommandParameter="AddExcludedExtension" Margin="10,0,0,0" />
                    </StackPanel>


                </StackPanel>
            </StackPanel>

        </StackPanel>

        <StackPanel Orientation="Vertical" Margin="0,10,0,10">

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

            <StackPanel Orientation="Vertical" Margin="20,0,0,0">

                <CheckBox Content="{x:Static Properties:Resources.Options_DvdRead}" IsChecked="{Binding DisableLibdvdNav}" Margin="0,8,0,0" />

                <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                    <TextBlock Text="{x:Static Properties:Resources.Options_PreviewScanCount}" VerticalAlignment="Center" Width="300" />
                    <ComboBox Name="numberOfPreviews" ItemsSource="{Binding PreviewPicturesToScan}" SelectedItem="{Binding SelectedPreviewCount}" Width="120" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,20,0,0">
                    <TextBlock Text="{x:Static Properties:Resources.Options_MinTitleScanLength}" TextWrapping="Wrap" VerticalAlignment="Center" Width="300" />
                    <TextBox x:Name="MinTitleLength" VerticalAlignment="Center" Text="{Binding MinLength}"  Width="120"/>
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <CheckBox IsChecked="{Binding MaxDurationEnabled}" VerticalAlignment="Center" VerticalContentAlignment="Center" Width="300" Margin="0,0,5,0" >
                        <TextBlock Text="{x:Static Properties:Resources.Options_MaxTitleScanDuration}" TextWrapping="WrapWithOverflow" VerticalAlignment="Center"/>
                    </CheckBox>
                    <TextBox x:Name="MaxTitleLength" VerticalAlignment="Center" Text="{Binding MaxLength}" IsEnabled="{Binding MaxDurationEnabled}"  Width="120"/>
                </StackPanel>

                <CheckBox Content="{x:Static Properties:Resources.Options_KeepDuplicateTitles}" IsChecked="{Binding KeepDuplicateTitles}" Margin="0,20,0,0" />

                <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                    <TextBlock Text="{x:Static Properties:Resources.Options_RangeModeSelection}" VerticalAlignment="Center" Width="300" />
                    <ComboBox Name="defaultRangeMode" ItemsSource="{Binding DefaultRangeModes, Converter={StaticResource defaultRangeModeConverter}}" SelectedItem="{Binding SelectedDefaultRangeMode, Converter={StaticResource defaultRangeModeConverter}}" Width="120" />
                </StackPanel>

            </StackPanel>
        </StackPanel>

        <StackPanel Orientation="Vertical" Margin="0,10,0,10">
            <TextBlock Text="{x:Static Properties:Resources.Options_x264}" Style="{StaticResource subHeader}" Margin="0,0,0,10"/>
            <StackPanel Orientation="Horizontal" Margin="20,0,0,0">
                <TextBlock Text="{x:Static Properties:Resources.Options_x264Granularity}" VerticalAlignment="Center" Width="250" />
                <ComboBox Name="x264Granularity" ItemsSource="{Binding ConstantQualityGranularity}" SelectedItem="{Binding SelectedGranularity}" Width="120"/>
            </StackPanel>
        </StackPanel>

        <StackPanel Orientation="Vertical"  Visibility="{Binding IsProcessIsolationAllowed, Converter={StaticResource boolToVisConverter}}" >

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation}" Style="{StaticResource subHeader}" Margin="0,10,0,10"/>
            </StackPanel>


            <TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation_Warning1}" Margin="20,0,0,0"  TextWrapping="Wrap" Style="{StaticResource subText}" />
            <TextBlock Text="{x:Static Properties:Resources.OptionsView_ProcessIsolation_Warning2}" Margin="20,0,0,0"  TextWrapping="Wrap" Style="{StaticResource subText}" />

            <CheckBox Content="{x:Static Properties:Resources.OptionsView_EnableWorkerProcesses}" IsChecked="{Binding RemoteServiceEnabled}" Margin="20,10,0,0" />

            <StackPanel Orientation="Horizontal" Margin="20,10,0,0">
                <TextBlock Text="{x:Static Properties:Resources.OptionsView_WorkerDefaultPort}" />
                <TextBox Text="{Binding RemoteServicePort}" Width="100" IsEnabled="{Binding RemoteServiceEnabled}"  />
            </StackPanel>

            <StackPanel Orientation="Horizontal" Margin="20,10,0,0" IsEnabled="{Binding IsSimultaneousEncodesSupported}" >
                <TextBlock Text="{x:Static Properties:Resources.OptionsView_SimultaneousEncodes}" VerticalAlignment="Center"/>
                <ComboBox ItemsSource="{Binding SimultaneousEncodesList}" SelectedItem="{Binding SimultaneousEncodes}" IsEnabled="{Binding RemoteServiceEnabled}" />

            </StackPanel>
            <StackPanel Orientation="Vertical">
                <TextBlock Text="{x:Static Properties:Resources.OptionsView_SimultaneousHardwareLimitNotice}" Visibility="{Binding IsSimultaneousEncodesSupported, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" 
                                       Margin="20,0,0,0" TextWrapping="Wrap" Style="{StaticResource subText}" />

                <TextBlock Text="{x:Static Properties:Resources.OptionsView_NotSupported}" Margin="20,0,0,0" Visibility="{Binding IsSimultaneousEncodesSupported, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
            </StackPanel>

        </StackPanel>


        <StackPanel Orientation="Vertical" Margin="0,15,0,10">

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

            <StackPanel Orientation="Vertical" Margin="20,0,0,0">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{x:Static Properties:Resources.Options_LogLevel}" Width="250" VerticalAlignment="Center" />
                    <ComboBox Name="logVerbosityLevel" ItemsSource="{Binding LogVerbosityOptions, Converter={StaticResource LogLevelConverter}}" SelectedItem="{Binding SelectedVerbosity, Converter={StaticResource LogLevelConverter}}" Width="120" />
                </StackPanel>

                <CheckBox Content="{x:Static Properties:Resources.Options_7DayLogClear}" Margin="0,5,0,0" IsChecked="{Binding ClearOldLogs}" />
                <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                    <Button Content="{x:Static Properties:Resources.Options_ViewLogDirectory}" Command="{Binding RelayCommand}" CommandParameter="ViewLogDirectory" Margin="0,0,5,0" />
                    <Button Content="{x:Static Properties:Resources.Options_ClearLogs}" Command="{Binding RelayCommand}" CommandParameter="ClearLogHistory" />
                </StackPanel>

                <CheckBox Content="{x:Static Properties:Resources.Options_CopyLogToEncDir}" Margin="0,25,0,0" IsChecked="{Binding CopyLogToEncodeDirectory}" />
                <CheckBox Content="{x:Static Properties:Resources.Options_CopyLogToDir}" Margin="0,5,0,0" IsChecked="{Binding CopyLogToSpecifiedLocation}" />
                <StackPanel Orientation="Horizontal" Margin="25,5,0,10">
                    <TextBlock Text="{x:Static Properties:Resources.Options_LogPath}" VerticalAlignment="Center" />
                    <TextBox Width="380" Text="{Binding LogDirectory}" />
                    <Button Content="{x:Static Properties:Resources.Browse}" Margin="5,0,0,0" Command="{Binding RelayCommand}" CommandParameter="BrowseLogPath" />
                </StackPanel>
       
            </StackPanel>

        </StackPanel>

    </StackPanel>

</UserControl>
