<Page xmlns:local="clr-namespace:ForzaUI"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      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"
      x:Class="ForzaUI.A_PCVideoOptions"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Page.Resources>
        <Style x:Key="A_Style_ListBoxItem_PCVideoOptionsItem"
               BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}"
               TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsEnabled}"
                             Value="False">
                    <Setter Property="Tag"
                            Value="Inactive" /> 
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <DataTemplate DataType="{x:Type local:PCVideoSpinnerOption}">
            <local:SpinnerControl x:Name="Spinner"
                                  Style="{StaticResource A_Style_SpinnerControl_Default_InItemsList}"
                                  Label="{Binding Name}"
                                  ItemsSource="{Binding Options}"
                                  SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                  IsEnabled="{Binding IsEnabled}"
                                  Focusable="True"/>
        </DataTemplate>

        <ControlTemplate x:Key="A_ControlTemplate_Button_Option" TargetType="local:FZButton">
            <Grid Margin="18,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.535*"/>
                    <ColumnDefinition Width="0.465*"/>
                </Grid.ColumnDefinitions>
                <local:FZMaterial x:Name="MouseHitHelper"
                                  Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                  Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                  Color="#00000000"
                                  Margin="-20,0,0,0"
                                  Grid.ColumnSpan="2"
                                  Focusable="False"/>
                <local:FZTextBlock  x:Name="ButtonText"
                                    Text="{Binding Name, Converter={StaticResource A_StringToUpper}}"
                                    Style="{StaticResource A_Style_FZTextBlock_SpinnerTitle}"
                                    HorizontalAlignment="Left"
                                    local:ScreenReader.Event="OnChange"
                                    local:ScreenReader.ControlType="List"
                                    local:ScreenReader.LineType="SelectedItem"
                                    local:ScreenReader.SelectedNumber="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}, FallbackValue=0}"
                                    local:ScreenReader.SelectedCount="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}, FallbackValue=0}"/>
                <local:FZTextBlock  x:Name="ButtonValue"
                                    Text="{Binding SelectedItem.Name}"
                                    Style="{StaticResource A_Style_FZTextBlock_SpinnerItem}"
                                    Grid.Column="1"
                                    HorizontalAlignment="Center"
                                    local:ScreenReader.Event="OnChange"
                                    local:ScreenReader.LineType="SelectedValue" />
            </Grid>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding (Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                             Value="True">
                    <Setter TargetName="ButtonText"
                            Property="Color"
                            Value="#ffffffff" />
                    <Setter TargetName="ButtonValue"
                            Property="Color"
                            Value="#ffffffff" />
                    <Setter TargetName="ButtonText"
                            Property="local:ScreenReader.Line"
                            Value="{Binding Name}" />
                    <Setter TargetName="ButtonValue"
                            Property="local:ScreenReader.Line"
                            Value="{Binding SelectedItem.Name}" />
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style x:Key="A_Style_FZButton_VideoOption" TargetType="local:FZButton" BasedOn="{StaticResource A_Style_Button_EmptyButton}">
            <Setter Property="Command" Value="{Binding Command}"/>
            <Setter Property="Focusable" Value="True"/>
            <Setter Property="local:FocusOnMouseOverBehaviour.Self" Value="True"/>
            <Setter Property="MinHeight" Value="{StaticResource A_Double_TextMenu_Height_Default}"/>
            <Setter Property="Template" Value="{StaticResource A_ControlTemplate_Button_Option}"/>
        </Style>
        
        <DataTemplate DataType="{x:Type local:PCVideoLargeListOption}">
            <local:FZButton Style="{StaticResource A_Style_FZButton_VideoOption}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type local:PCVideoButtonOption}">
            <local:FZButton Style="{StaticResource A_Style_FZButton_VideoOption}"/>
        </DataTemplate>

        <DataTemplate DataType="{x:Type local:PCVideoOptionBenchMarkMode}">
            <local:FZButton Command="{Binding OnSelect}"
                    Style="{StaticResource A_Style_Button_EmptyButton}"
                    Focusable="True"
                    local:FocusOnMouseOverBehaviour.Self="True"
                    MinHeight="{StaticResource A_Double_TextMenu_Height_Default}">
                <Grid Margin="18,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.535*"/>
                        <ColumnDefinition Width="0.465*"/>
                    </Grid.ColumnDefinitions>
                    <local:FZMaterial x:Name="MouseHitHelper"
                                      Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                      Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                      Color="#00000000"
                                      Margin="-20,0,0,0"
                                      Grid.ColumnSpan="2"
                                      Focusable="False"/>
                    <local:FZTextBlock  x:Name="ButtonText"
                                        Text="{Binding Name, Converter={StaticResource A_StringToUpper}}"
                                        Style="{StaticResource A_Style_FZTextBlock_SpinnerTitle}"
                                        HorizontalAlignment="Left" />
                </Grid>
            </local:FZButton>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding (Selector.IsSelected), RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                             Value="True">
                    <Setter TargetName="ButtonText"
                            Property="Color"
                            Value="{StaticResource A_Color_White}" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate DataType="{x:Type local:PCVideoSliderOption}">
            <Slider local:BindingProxy.A="{Binding Name}"
                    Value="{Binding SliderValue}"
                    Style="{StaticResource A_Style_Slider_Options_InItemsList}"
                    Focusable="True"
                    local:BindingProxy.C="True" />
        </DataTemplate>

        <local:NumUnitConverter x:Key="A_Converter_Degrees" FormatString="UnitStrings.IDS_Units_Degrees_Format" FractionDigits="1"/>

        <DataTemplate DataType="{x:Type local:PCVideoSliderOptionFOV}">
            <Slider local:BindingProxy.A="{Binding Name}"
                    local:BindingProxy.B="{Binding SliderValue, Converter={StaticResource A_Converter_Degrees}}"
                    Minimum="{Binding MinSliderValue}"
                    Maximum="{Binding MaxSliderValue}"
                    SmallChange="0.5"
                    Value="{Binding SliderValue}"
                    Style="{StaticResource A_Style_Slider_Options_InItemsList}"
                    Focusable="True"
                    local:BindingProxy.C="True" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type local:PCVideoSpinnerOptionAdvancedPresets}">
            <local:SpinnerControl x:Name="Spinner"
                                  Style="{StaticResource A_Style_SpinnerControl_Default_InItemsList_AltStyle}"
                                  Label="{Binding Name}"
                                  ItemsSource="{Binding Options}"
                                  SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                  Focusable="True"/>
        </DataTemplate>

        <Style x:Key="A_Style_CommonListBox_PCVideoOptions"
               BasedOn="{StaticResource A_Style_ListBox_List_Default_ScrollBar}"
               TargetType="local:CommonListBox">
            <Setter Property="ItemsSource"
                    Value="{Binding Path=AdvancedOptions.CurrentOptions.Options}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedIndex, ElementName=PART_GroupList}"
                             Value="0">
                    <Setter Property="ItemsSource"
                            Value="{Binding BasicOptions.Options}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type ContentControl}"
               x:Key="A_Style_ContentControl_AdvancedTabTitle"
               BasedOn="{StaticResource A_Style_ContentControl_TabTitle_NonCarousel}">
            <Setter Property="local:TileMenuNavigationManager.TileState"
                    Value="{x:Static local:TileState.Enabled}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding UseDynamicOptimization, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="True">
                    <Setter Property="local:TileMenuNavigationManager.TileState"
                            Value="{x:Static local:TileState.Disabled}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Page.Resources>

    <Grid>
        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />

        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <local:ControllerButtonPanel x:Name="HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A"
                                               Description="{local:Loc HelpButtons.IDS_Select}"
                                               Visibility="{Binding ShouldShowSelectButton, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                <local:ControllerButtonControl Button="B"
                                               Description="{local:Loc HelpButtons.IDS_Back}" />
                <local:ControllerButtonControl Button="X"
                                               Description="{local:Loc HelpButtons.IDS_Save}" />
                <local:ControllerButtonControl Button="Y"
                                               Description="{local:Loc HelpButtons.IDS_RunAutoDetect}"/>
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}"
                SnapsToDevicePixels="True"
                UseLayoutRounding="True" >
            <Grid x:Name="LayoutRoot" Margin="0,40,0,0">
                <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Center" >
                    <StackPanel Orientation="Horizontal" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                        <ContentControl Tag="{local:Loc ScreenTitles.IDS_MyProfile}" Content="{local:Loc ScreenTitles.IDS_VideoOptions}"
                                        local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Options.png" 
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}" 
                                        Focusable="False" />
                    </StackPanel>

                    <DockPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" >
                        <Grid DockPanel.Dock="Top">
                            <local:ItemsSelector x:Name="PART_GroupList"
                                                 Style="{StaticResource A_Style_ItemsSelector_TabTitle}"
                                                 SelectedIndex="0"
                                                 IsLocked="{Binding UseDynamicOptimization, RelativeSource={RelativeSource AncestorType=Page}}">
                                <ContentControl x:Name="BasicTabItem"
                                                Content="{local:Loc MyProfile.IDS_VideoBasic}"
                                                Style="{StaticResource A_Style_ContentControl_TabTitle_NonCarousel}"
                                                local:AccumulateSelfOnParent.SortOrder="0"/>
                                <ContentControl x:Name="AdvancedTabItem"
                                                Content="{local:Loc MyProfile.IDS_VideoAdvanced}"
                                                Style="{StaticResource A_Style_ContentControl_AdvancedTabTitle}"
                                                local:AccumulateSelfOnParent.SortOrder="1" />
                            </local:ItemsSelector>
                        </Grid>

                        <ContentControl Style="{StaticResource A_Style_DescriptionPanel_Options}"
                                        DataContext="{Binding SelectedItem, ElementName=PART_OptionsList}"
                                        Content="{Binding Description}"
                                        local:UIPageTransitionManager.TransitionIndex="1"
                                        DockPanel.Dock="Right"
                                        VerticalAlignment="Top" />

                        <local:CommonListBox x:Name="PART_OptionsList"
                                             Style="{StaticResource A_Style_CommonListBox_PCVideoOptions}" 
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_PCVideoOptionsItem}"
                                             Width="824"
                                             Height="663"
                                             AllowMouseWheelScrolling="False"
                                             Focusable="False"
                                             KeyboardNavigation.DirectionalNavigation="Contained"
                                             local:UIPageTransitionManager.TransitionIndex="0"
                                             DockPanel.Dock="Left"
                                             VerticalAlignment="Top"
                                             local:FocusOnPageFocusGained.VirtualizingSelectorSelectedItem="True"/>
                    </DockPanel>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
