<Page x:Class="ForzaUI.Scenes.Anthem.A_QuickChatPhraseSelectPopup"
      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:local="clr-namespace:ForzaUI"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      mc:Ignorable="d" 
      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>
            <Thickness x:Key="A_Thickness_QuickChatPhraseItemMargin">0,0,4,0</Thickness>

            <local:MappingConverter x:Key="A_MappingConverter_CollapsedIfAvailable" Default="{x:Static Visibility.Visible}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Available}" Value="{x:Static Visibility.Collapsed}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_VisibleIfBound" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Bound}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_VisibleIfCurrent" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Current}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_VisibleIfLocked" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Locked}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_VisibleIfCurrentOrBound" Default="{x:Static Visibility.Collapsed}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Bound}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Current}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_QuickChatPhraseStateToBackgroundColor" Default="{StaticResource A_Color_Tile_Text}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Current}" Value="{StaticResource A_Color_Header_Background}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_ItemStateToScreenReaderLine" Default="{x:Null}">
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Locked}" Value="{local:Loc GameOptions2.IDS_QuickChat_ScreenReader_ItemState_Locked}" />
                <local:MappingConverterEntry Key="{x:Static local:QuickChatPhraseState.Current}" Value="{local:Loc GameOptions2.IDS_QuickChat_ScreenReader_ItemState_Current}" />
            </local:MappingConverter>

            <Style x:Key="A_Style_ControllerButtonControl_QuickChatPhraseInput"
                TargetType="{x:Type local:ControllerButtonControl}"
                BasedOn="{StaticResource A_Style_ControllerButtonControl_Default_ShowAlways}">
                <Setter Property="Margin" Value="0,0"/>
                <Setter Property="HideBackground" Value="True"/>
                <Setter Property="AllowMouseClick" Value="False"/>
                <Setter Property="SupportsControllerInput" Value="True"/>
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_VisibleIfBound}}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_QuickChatPhraseTick"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"/>
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/Tick.png"/>
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_VisibleIfCurrent}}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_QuickChatPhraseTick_PC"
                BasedOn="{StaticResource A_Style_FZMaterial_QuickChatPhraseTick}"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_VisibleIfCurrentOrBound}}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_QuickChatPhraseLock"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"/>
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/Locked_Icon.png"/>
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_VisibleIfLocked}}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_QuickChatStatusBackground"
                BasedOn="{StaticResource A_Style_FZMaterial_FlatPanel_Base}"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"/>
                <Setter Property="Height" Value="32"/>
                <Setter Property="MinWidth" Value="32"/>
                <Setter Property="Margin" Value="4,0,0,0"/>
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_CollapsedIfAvailable}}"/>
                <Setter Property="Color" Value="{Binding State, Converter={StaticResource A_MappingConverter_QuickChatPhraseStateToBackgroundColor}}"/>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_ListBoxItem_QuickChatPhrase">
                <DockPanel IsHitTestVisible="False" Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}">
                    <local:FZMaterial x:Name="PhraseStatusBackground"
                        Style="{StaticResource A_Style_FZMaterial_QuickChatStatusBackground}"
                        DockPanel.Dock="Right">
                        <Grid x:Name="ItemStateContainer"
                              local:ScreenReader.Event="OnChange"
                              local:ScreenReader.LineType="ItemDescription">
                            <local:ControllerButtonControl x:Name="InputBindingControl"
                                Style="{StaticResource A_Style_ControllerButtonControl_QuickChatPhraseInput}"
                                InputOverride="{Binding Input}"
                                local:ScreenReader.Event="OnChange"
                                local:ScreenReader.LineType="SelectedValue" />
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseTick}"/>
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseLock}"/>
                        </Grid>
                    </local:FZMaterial>
                    <Decorator DockPanel.Dock="Left"
                        Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}"
                        Width="{Binding ActualWidth, ElementName=PhraseStatusBackground}"/>
                    <local:FZTextBlock x:Name="TextBlock" Text="{Binding Text}"
                        Style="{StaticResource A_Style_FZTextBlock_GridMenuItemText}"
                        local:ScreenReader.Event="OnChange"
                        local:ScreenReader.ControlType="Button"
                        local:ScreenReader.LineType="SelectedItem"
                        local:ScreenReader.SelectedNumber="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}}"
                        local:ScreenReader.SelectedCount="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}}"/>
                </DockPanel>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                        <Setter TargetName="TextBlock" Property="local:ScreenReader.Line" Value="{Binding Text}" />
                        <Setter TargetName="ItemStateContainer" Property="local:ScreenReader.Line" Value="{Binding State, Converter={StaticResource A_MappingConverter_ItemStateToScreenReaderLine}}" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True" />
                            <Condition Binding="{Binding State}" Value="{x:Static local:QuickChatPhraseState.Bound}" />
                        </MultiDataTrigger.Conditions>
                        <Setter TargetName="InputBindingControl" Property="local:ScreenReader.Line" Value="{Binding ScreenReaderName, RelativeSource={RelativeSource Self}}" />
                    </MultiDataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="A_DataTemplate_ListBoxItem_QuickChatPhrase_PC">
                <DockPanel IsHitTestVisible="False" Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}">
                    <local:FZMaterial x:Name="PhraseStatusBackground"
                        Style="{StaticResource A_Style_FZMaterial_QuickChatStatusBackground}"
                        DockPanel.Dock="Right">
                        <Grid x:Name="ItemStateContainer"
                              local:ScreenReader.Event="OnChange"
                              local:ScreenReader.LineType="ItemDescription">
                            <local:ControllerButtonControl x:Name="InputBindingControl"
                                Style="{StaticResource A_Style_ControllerButtonControl_QuickChatPhraseInput}"
                                InputOverride="{Binding Input}"
                                Visibility="{x:Static Visibility.Collapsed}"
                                local:ScreenReader.Event="OnChange"
                                local:ScreenReader.LineType="SelectedValue" />
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseTick_PC}"/>
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseLock}"/>
                        </Grid>
                    </local:FZMaterial>
                    <Decorator DockPanel.Dock="Left"
                        Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}"
                        Width="{Binding ActualWidth, ElementName=PhraseStatusBackground}"/>
                    <local:FZTextBlock x:Name="TextBlock" Text="{Binding Text}"
                        Style="{StaticResource A_Style_FZTextBlock_GridMenuItemText}"
                        local:ScreenReader.Event="OnChange"
                        local:ScreenReader.ControlType="Button"
                        local:ScreenReader.LineType="SelectedItem"
                        local:ScreenReader.SelectedNumber="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}}"
                        local:ScreenReader.SelectedCount="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}}"/>
                </DockPanel>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                        <Setter TargetName="TextBlock" Property="local:ScreenReader.Line" Value="{Binding Text}" />
                        <Setter TargetName="ItemStateContainer" Property="local:ScreenReader.Line" Value="{Binding State, Converter={StaticResource A_MappingConverter_ItemStateToScreenReaderLine}}" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True" />
                            <Condition Binding="{Binding State}" Value="{x:Static local:QuickChatPhraseState.Bound}" />
                        </MultiDataTrigger.Conditions>
                        <Setter TargetName="InputBindingControl" Property="local:ScreenReader.Line" Value="{Binding ScreenReaderName, RelativeSource={RelativeSource Self}}" />
                    </MultiDataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <Style x:Key="A_Style_ListBox_QuickChatMenu"
                BasedOn="{StaticResource A_Style_ListBox_GridMenu}"
                TargetType="{x:Type local:GridListBox}">
                <Setter Property="ItemTemplate" Value="{StaticResource A_DataTemplate_ListBoxItem_QuickChatPhrase}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsPC, RelativeSource={RelativeSource AncestorType=Page}}" Value="True">
                        <Setter Property="ItemTemplate" Value="{StaticResource A_DataTemplate_ListBoxItem_QuickChatPhrase_PC}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

        </ResourceDictionary>
    </Page.Resources>

    <Grid>
        <Grid>
            <!-- Background Blur -->
            <local:FZMaterialGlassCapture />
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"/>

            <!-- 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>
        </Grid>

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

                <ContentControl Content="{local:Loc ScreenTitles.IDS_QuickChatPhraseSelect}"
                        Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"/>

                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}"
                                Tag="/ForzaUI;component/Textures/Anthem/Icons/Titles/PopupQuickChat.png">
                    <local:GridListBox x:Name="PART_OptionsList"
                                       ItemsSource="{Binding Collection}"
                                       Style="{StaticResource A_Style_ListBox_QuickChatMenu}"
                                       SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=Page}, Mode=TwoWay}"
                                       local:FocusOnPageFocusGained.SelectorSelectedItem="True"/>
                </ContentControl>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
