<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>
            <System:Double x:Key="A_Double_Icon_Width">36</System:Double>
            <System:Double x:Key="A_Double_Icon_Height">36</System:Double>
            
            <Thickness x:Key="A_Thickness_QuickChatPhraseItemMargin">0,0,7,0</Thickness>

            <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_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_FZTextBlock_QuickChatPhraseText"
                BasedOn="{StaticResource A_Style_FZTextBlock_GridMenuItemText}"
                TargetType="{x:Type local:FZTextBlock}">
                <Setter Property="Stretch" Value="None"/>
                <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
                <Setter Property="MaxWidth" Value="232"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Value="True">
                        <Setter Property="Color" Value="{StaticResource A_Color_ListItemText_Focused}" />
                        <Setter Property="MaxWidth" Value="infinity"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <AutoScrollSettings x:Key="A_AutoScrollSettings_QuickChatPhraseText"
                ScrollOrientation="Horizontal"
                Speed="40"
                InitialPause="0:0:0.5"/>
            <Style x:Key="A_Style_FZTextBlock_AutoScroll_QuickChatPhraseText" 
                BasedOn="{StaticResource A_Style_FZTextBlock_QuickChatPhraseText}" TargetType="FZTextBlock">
                <Setter Property="TextAlignment" Value="Center" />
                <Setter Property="ScreenReader.Event" Value="OnChange" />
                <Setter Property="ScreenReader.ControlType" Value="Button" />
                <Setter Property="ScreenReader.LineType" Value="SelectedItem" />
                <Setter Property="ScreenReader.SelectedNumber" Value="{Binding (ItemsControl.AlternationIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}}"/>
                <Setter Property="ScreenReader.SelectedCount" Value="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}}"/>
                <Setter Property="AutoScroll" Value="{StaticResource A_AutoScrollSettings_QuickChatPhraseText}" />
                <Setter Property="AutoScroll.AllowScrolling" Value="False"/>
                <Setter Property="Stretch" Value="None" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="Text" Value="{Binding Text}" />
            </Style>

            <Style x:Key="A_Style_ControllerButtonControl_QuickChatPhraseInput"
                TargetType="{x:Type local:ControllerButtonControl}"
                BasedOn="{StaticResource A_Style_ControllerButtonControl_Standalone}">
                <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="Width" Value="{StaticResource A_Double_Icon_Width}" />
                <Setter Property="Height" Value="{StaticResource A_Double_Icon_Height}" />
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Green}"/>
                <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="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/Locked_Icon.png"/>
                <Setter Property="Width" Value="19.5"/>
                <Setter Property="Height" Value="24"/>
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Black}"/>
                <Setter Property="Visibility" Value="{Binding State, Converter={StaticResource A_MappingConverter_VisibleIfLocked}}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Value="True">
                        <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_QuickChatItemStateGrid"
                TargetType="{x:Type Grid}">
                <Setter Property="Height" Value="32"/>
                <Setter Property="MinWidth" Value="32"/>
                <Setter Property="Margin" Value="4,0,0,0"/>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_ListBoxItem_QuickChatPhrase">
                <DockPanel IsHitTestVisible="False" Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}">
                    <Grid x:Name="ItemStateContainer"
                                Style="{StaticResource A_Style_QuickChatItemStateGrid}"
                                DockPanel.Dock="Right"
                                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}">
                            <FZMaterial.Preset>
                                <FZMaterialPresetRoundtangle  CornerRadius="8" />
                            </FZMaterial.Preset>
                            <local:FZMaterial ImageSource="\Textures\Data_Bound\Checkbox\Checkbox_On.png" 
                              Color="{StaticResource H_Color_Primary_Black}"/>
                        </local:FZMaterial>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseLock}"/>
                    </Grid>
                    <Decorator DockPanel.Dock="Left"
                        Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}"
                        Width="{Binding ActualWidth, ElementName=ItemStateContainer}"/>
                    <Decorator ClipToBounds="True">
                        <FZTextBlock x:Name="AutoScrollTextBlock" 
                            Style="{StaticResource A_Style_FZTextBlock_AutoScroll_QuickChatPhraseText}" />
                    </Decorator>
                </DockPanel>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                        <Setter TargetName="AutoScrollTextBlock" Property="local:ScreenReader.Line" Value="{Binding Text}" />
                        <Setter TargetName="ItemStateContainer" Property="local:ScreenReader.Line" Value="{Binding State, Converter={StaticResource A_MappingConverter_ItemStateToScreenReaderLine}}" />
                        <Setter TargetName="AutoScrollTextBlock" Property="AutoScroll.AllowScrolling" Value="True"/>
                        <Setter TargetName="AutoScrollTextBlock" Property="TextTrimming" Value="None"/>
                    </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}">
                    <Grid x:Name="ItemStateContainer"
                            Style="{StaticResource A_Style_QuickChatItemStateGrid}"
                            DockPanel.Dock="Right"
                            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}">
                            <FZMaterial.Preset>
                                <FZMaterialPresetRoundtangle CornerRadius="8"/>
                            </FZMaterial.Preset>
                            <local:FZMaterial ImageSource="\Textures\Data_Bound\Checkbox\Checkbox_On.png" 
                                              Color="{StaticResource H_Color_Primary_Black}"/>
                        </local:FZMaterial>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_QuickChatPhraseLock}"/>
                    </Grid>
                    <Decorator DockPanel.Dock="Left"
                        Margin="{StaticResource A_Thickness_QuickChatPhraseItemMargin}"
                        Width="{Binding ActualWidth, ElementName=ItemStateContainer}"/>
                    <Decorator ClipToBounds="True">
                        <FZTextBlock x:Name="AutoScrollTextBlock"
                                Style="{StaticResource A_Style_FZTextBlock_AutoScroll_QuickChatPhraseText}"/>
                    </Decorator>
                </DockPanel>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                        <Setter TargetName="AutoScrollTextBlock" Property="local:ScreenReader.Line" Value="{Binding Text}" />
                        <Setter TargetName="ItemStateContainer" Property="local:ScreenReader.Line" Value="{Binding State, Converter={StaticResource A_MappingConverter_ItemStateToScreenReaderLine}}" />
                        <Setter TargetName="AutoScrollTextBlock" Property="AutoScroll.AllowScrolling" Value="True"/>
                        <Setter TargetName="AutoScrollTextBlock" Property="TextTrimming" Value="None"/>
                    </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_ListBoxItem_QuickChatGridMenu"
                    BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NoGaps}"
                    TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Width" Value="Auto" />
                    <Setter Property="Height" Value="Auto" />
                    <Setter Property="Margin" Value="2" />
            </Style>

            <Style x:Key="A_Style_ListBox_QuickChatMenu"
                BasedOn="{StaticResource A_Style_ListBox_TextMenu}"
                TargetType="{x:Type local:WrapListBox}">
                <Setter Property="EmptyItemStyle">
                    <Setter.Value>
                        <Style TargetType="Control">
                            <Setter Property="Margin" Value="2"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate
                                        TargetType="{Type Control}">
                                        <FZMaterial
                                            Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                            Preset="{StaticResource H_GlassRoundtangle_1px}"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="Width" Value="1560"/>
                <Setter Property="MaxHeight" Value="672"/>
                <Setter Property="ItemWidth" Value="312"/>
                <Setter Property="ItemHeight" Value="68"/>
                <Setter Property="ItemContainerStyle" Value="{StaticResource A_Style_ListBoxItem_QuickChatGridMenu}"/>
                <Setter Property="ItemTemplate" Value="{StaticResource A_DataTemplate_ListBoxItem_QuickChatPhrase}"/>
                <Setter Property="ScrollOrientation" Value="Vertical"/>
                <Setter Property="OverrideAcrossNavigation" Value="True"/>
                <Setter Property="Margin" Value="-2"/>
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_Carousel_Default}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsPC, Source={StaticResource PART_UISceneContext}}" 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="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>
        </Grid>

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}"
              Focusable="False">
            <Grid x:Name="MainContent"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="0"/>
                </Grid.ColumnDefinitions>

                <Decorator
                        Grid.Row="0"
                        Grid.Column="0"
                        HorizontalAlignment="Left"
                        Width="365"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                    <ContentControl
                            Content="{local:Loc ScreenTitles.IDS_QuickChatPhraseSelect}"
                            Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                            BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Stats.png" />
                </Decorator>
                <Decorator
                        Focusable="False"
                        Grid.Row="1"
                        Grid.Column="0" >
                    <FZButtonsSelector
                            ItemsSource="{Binding Categories, RelativeSource={RelativeSource AncestorType=Page}}"
                            SelectedIndex="0"
                            Style="{StaticResource H_Style_TabBar_Scrolling}"
                            x:Name="PART_ItemsSelector_Category"
                    	    Width="1560"/>
                </Decorator>

                <WrapListBox DataContext="{Binding SelectedItem, ElementName=PART_ItemsSelector_Category}"
                             x:Name="PART_OptionsList"
                             Grid.Row="2"
                             Grid.Column="0"
                             ItemsSource="{Binding ListData}"
                             Style="{StaticResource A_Style_ListBox_QuickChatMenu}"
                             SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=Page}, Mode=TwoWay}"
                             local:FocusOnPageFocusGained.SelectorSelectedItem="True"/>
                <ScrollBar
                    Grid.Row="2"
                    Grid.Column="1"
                    Style="{StaticResource H_Style_ScrollBar}"
                    Margin="8,0,0,0"
                    Minimum="{Binding ScrollWindowMin, ElementName=PART_OptionsList}"
                    Maximum="{Binding ScrollWindowMax, ElementName=PART_OptionsList}"
                    Value="{Binding ScrollWindowValue, ElementName=PART_OptionsList, Mode=TwoWay}"
                    ViewportSize="{Binding ScrollWindowSize, ElementName=PART_OptionsList}">
                    <DynamicData.Data>
                        <DynamicDataItem
                            Name="ScrollBarHideWhenNotNeeded"
                            DataType="Boolean"
                            Value="True" />
                    </DynamicData.Data>
                </ScrollBar>
            </Grid>
        </Grid>
    </Grid>
</Page>
