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

    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Popup}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Page.Resources>
        <ResourceDictionary>
            <System:Double x:Key="A_Double_MinPanelWidth">816</System:Double>
            <System:Double x:Key="A_Double_InternalItemWidth">816</System:Double>

            <Style x:Key="A_Style_SpinnerControl_Override"
                   TargetType="local:SpinnerControl" BasedOn="{StaticResource A_Style_SpinnerControl_Default_InItemsList}">
                <Style.Resources>
                    <GridLength x:Key="A_GridLength_SpinnerWidth">372</GridLength>
                </Style.Resources>
            </Style>

            <DataTemplate DataType="{x:Type local:SettingItem}">
                <Grid>
                    <local:SpinnerControl x:Name="Spinner" Label="{Binding Name}"
                                    Style="{StaticResource A_Style_SpinnerControl_Override}"
                                    ItemsSource="{Binding Options}" SelectedItem="{Binding SelectedValue, Mode=TwoWay}" WrapSelection="{Binding WrapSelection}"/>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Enabled}" Value="False">
                        <Setter TargetName="Spinner" Property="Tag" Value="Locked" />
                    </DataTrigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=Spinner}" />
                    </Trigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <Style x:Key="A_Style_ListBoxItem_TextMenu_SpinnerSetting" 
                   TargetType="{x:Type ListBoxItem}" 
                   BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NoGaps}">
                <Setter Property="Visibility" Value="{Binding Visible,Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                <Setter Property="Focusable" Value="{Binding Enabled, FallbackValue=True}" />
                <Setter Property="Height" Value="{StaticResource A_Double_TextMenu_Height_Default}" />
                <Setter Property="IsEnabled" Value="{Binding Enabled}"/>
                <Setter Property="Margin" Value="0,0,0,4"/>
                <Style.Triggers>
                    <Trigger Property="IsKeyboardFocusWithin" Value="True">
                        <Setter Property="Selector.IsSelected" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Storyboard x:Key="A_Storyboard_ListItem_ToggleFocus">
                <StringAnimationUsingKeyFrames Storyboard.TargetName="AudioEvent" 
                                               Storyboard.TargetProperty="(local:AudioEvent.SoundName)">
                    <DiscreteStringKeyFrame KeyTime="0:0:0" Value="" />
                    <DiscreteStringKeyFrame KeyTime="0:0:0.01" Value="/Master/UI/PopUpMenu/HZ2_SFX_HUD_PopUpMenu_Move_01" />
                </StringAnimationUsingKeyFrames>
            </Storyboard>

            <Style x:Key="A_Style_ListBox_List_AudioOnUnfocus"
                   TargetType="local:CommonListBox"
                   BasedOn="{StaticResource A_Style_ListBox_TextMenu}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:CommonListBox">
                            <Grid>
                                <StackPanel Orientation="Vertical" IsItemsHost="True" />
                                <local:AudioEvent x:Name="AudioEvent" />
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                                    <Trigger.ExitActions>
                                        <BeginStoryboard HandoffBehavior="SnapshotAndReplace"
                                                         Storyboard="{StaticResource A_Storyboard_ListItem_ToggleFocus}">
                                        </BeginStoryboard>
                                    </Trigger.ExitActions>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </ResourceDictionary>
    </Page.Resources>

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

        <!-- Help Button Bar -->
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel"
                            local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                            local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>
        <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_EventSetup}" />

        <Grid HorizontalAlignment="Center"
              Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <StackPanel x:Name="MainContent"
                        MinWidth="{StaticResource A_Double_MinPanelWidth}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                        Focusable="False">

                <ContentControl Content="{Binding Title}"
                                Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"
                                Width="Auto"/>

                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}"
                                Margin="0,0,0,2">
                    <local:FZTextBlock Text="{Binding Message}"
                                       VerticalAlignment="Center"
                                       Visibility="{Binding Message, Converter={StaticResource A_StringVisConverter}}"
                                       Style="{StaticResource A_Style_FZTextBlock_PopupText}"/>
                </ContentControl>

                <StackPanel Orientation="Vertical"
                            Width="{StaticResource A_Double_InternalItemWidth}"
                            KeyboardNavigation.DirectionalNavigation="Contained">
                    <Decorator Visibility="{Binding ShowSettings, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                               Margin="0,0,0,4">
                        <local:CommonListBox x:Name="PART_Menu"
                                             Focusable="False"
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_SpinnerSetting}"
                                             Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                             ItemsSource="{Binding Settings}"
                                             KeyboardNavigation.DirectionalNavigation="Continue" />
                    </Decorator>

                    <StackPanel Visibility="{Binding ShowGlobalSettings, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                Margin="0,0,0,4">
                        <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}"
                                        Height="50"
                                        Visibility="{Binding GlobalSettingsHeader, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"
                                        Margin="0,0,0,2">
                            <local:FZTextBlock Text="{Binding GlobalSettingsHeader}"
                                               Style="{StaticResource A_Style_FZTextBlock_OptionText}"
                                               Color="{StaticResource A_Color_SubHeader_Text}"
                                               Focusable="False"/>
                        </ContentControl>

                        <Decorator Focusable="False">
                            <local:CommonListBox x:Name="GlobalSettingsMenu"
                                                 Focusable="False"
                                                 ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_SpinnerSetting}"
                                                 Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                                 ItemsSource="{Binding GlobalSettings}"
                                                 KeyboardNavigation.DirectionalNavigation="Continue"/>
                        </Decorator>
                    </StackPanel>

                    <local:CommonListBox Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                         HorizontalAlignment="Center"
                                         ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}"
                                         Focusable="False" 
                                         KeyboardNavigation.DirectionalNavigation="Continue">
                        <ListBoxItem Style="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}"
                                     Margin="0,0,0,0">
                            <local:FZButton x:Name="PART_ConfirmButton"
                                            Content="{local:Loc PopupOptions.IDS_Confirm}"
                                            Template="{StaticResource A_ControlTemplate_Button_TextMenu}" />
                        </ListBoxItem>
                    </local:CommonListBox>
                </StackPanel>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
