<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_PanelWidth">700</System:Double>
            <System:Double x:Key="A_Double_InternalItemWidth">650</System:Double>

            <Style x:Key="A_Style_SpinnerControl_Override"
                   TargetType="local:SpinnerControl" BasedOn="{StaticResource A_Style_SpinnerControl_Default_InItemsList_Ellipsis}">
                <Style.Resources>
                    <GridLength x:Key="A_GridLength_SpinnerWidth">278</GridLength>
                </Style.Resources>
            </Style>
            
            <Style x:Key="A_Style_ListBoxItem_TextMenu_Setting" 
                   TargetType="{x:Type ListBoxItem}" 
                   BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}">
                <Setter Property="Visibility" Value="Visible" />
                <Setter Property="Height" Value="{StaticResource A_Double_TextMenu_Height_Default}" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <ListBoxItem x:Name="ListBoxItem"  Template="{StaticResource A_ControlTemplate_TextMenu_Default}" Focusable="False">
                                <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}"/>
                                    
                                <ListBoxItem.Style>
                                    <Style TargetType="ListBoxItem">
                                        <Style.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=Spinner}" />
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </ListBoxItem.Style>
                            </ListBoxItem>
                            <ControlTemplate.Triggers>
                                <DataTrigger Binding="{Binding Enabled}" Value="False">
                                    <Setter TargetName="ListBoxItem" Property="IsEnabled" Value="False" />
                                    <Setter TargetName="Spinner" Property="Tag" Value="Locked" />
                                </DataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Enabled}" Value="False">
                        <Setter Property="Focusable" Value="False" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Visible}" Value="False">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </DataTrigger>
                    <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 -->
        <local:FZMaterialGlassCapture />
        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"/>
        <local:FZMaterialGlassCapture />

        <!-- Help Button Bar -->
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="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 Width="{StaticResource A_Double_PanelWidth}" Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <StackPanel x:Name="MainContent" Width="{StaticResource A_Double_PanelWidth}"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Center"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                        Focusable="False">

                <ContentControl Content="{Binding Title, Converter={StaticResource A_StringToUpper}}"
                                Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"/>

                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}" Tag="/ForzaUI;component/Textures/Anthem/Icons/Titles/PopupSettings.png">
                        <StackPanel Orientation="Vertical" Width="{StaticResource A_Double_InternalItemWidth}" KeyboardNavigation.DirectionalNavigation="Contained">
                            <local:FZTextBlock Margin="0,0,0,30" Text="{Binding Message}"
                                               Visibility="{Binding Message, Converter={StaticResource A_StringVisConverter}}"
                                               Style="{StaticResource A_Style_FZTextBlock_PopupText}"/>

                        <Decorator Visibility="{Binding ShowSettings, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <local:CommonListBox x:Name="Menu"
                                             Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_Setting}"
                                             ItemsSource="{Binding Settings}"
                                             SelectedItem="{Binding SelectedItem}"
                                             KeyboardNavigation.DirectionalNavigation="Continue" />
                        </Decorator>
                        <Grid Visibility="{Binding ShowGlobalSettings, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                            <local:CommonListBox Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}"
                                             Focusable="False"
                                             KeyboardNavigation.DirectionalNavigation="Continue"
                                             Visibility="{Binding GlobalSettingsHeader, Converter={StaticResource A_StringVisConverter}}">
                                <ListBoxItem Style="{StaticResource A_Style_ListBoxItem_TextMenu_NotFocusable}" Margin="0, 7, 0, 0">
                                    <local:FZTextBlock x:Name="Text" Text="{Binding GlobalSettingsHeader}"
                                             Style="{StaticResource A_Style_FZTextBlock_OptionText}"
                                             Color="{StaticResource A_Color_SubHeader_Text}"
                                             Focusable="False"/>
                                </ListBoxItem>
                            </local:CommonListBox>

                            <local:CommonListBox x:Name="GlobalSettingsMenu"
                                             Style="{StaticResource A_Style_ListBox_List_AudioOnUnfocus}"
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_Setting}"
                                             ItemsSource="{Binding GlobalSettings}"
                                             KeyboardNavigation.DirectionalNavigation="Continue"
                                             Visibility="{Binding GlobalSettings, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                        </Grid>

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