<Page xmlns:local="clr-namespace:ForzaUI"
      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:System="clr-namespace:System;assembly=mscorlib"
      x:Class="ForzaUI.A_RaceCustomiser"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Margin="0">
    <Page.Resources>
        <ResourceDictionary>
            <!--Item Template for item menu-->
            <DataTemplate x:Key="A_DataTemplate_ListItem_RaceCustomiserMenuItem">
                <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}" >
                    <RoutedEventCommand x:Name="MouseLeftButtonUpCommand" 
                                    local:RoutedEventCommand.Action="{Binding RelativeSource={RelativeSource Self}}"
                                    RoutedEvent="UIElement.MouseLeftButtonUp"
                                    Command="{Binding OnSelectCommand, ElementName=MouseLeftButtonUpCommand}" />
                    <local:FZMaterial x:Name="DropShadow" Opacity="0.6" Visibility="Hidden" Margin="-25,-15"
                                      Style="{StaticResource A_Style_FZMaterial_ShadowBase_ForSubgraph}">
                    </local:FZMaterial>
                    <local:FZTextBlock x:Name="ItemText"
                                           Text="{Binding Text}"
                                           Style="{StaticResource A_Style_FZTextBlock_OptionText}"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           TextWrapping="Wrap"
                                           FontFamily="Horizon_B"
                                           TextAlignment="Center"
                                           CapHeight="18"
                                           Margin="19,0,0,0"
                                           IsHitTestVisible="False"
                                           local:ScreenReader.Event="OnChange"
                                           local:ScreenReader.ControlType="Button"
                                           local:ScreenReader.LineType="SelectedItem"
                                           local:ScreenReader.SelectedNumber="{Binding (VirtualizingWrapPanel.ItemIndex), RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}, FallbackValue=0}"
                                           local:ScreenReader.SelectedCount="{Binding Items.Count, RelativeSource={RelativeSource AncestorType={x:Type Selector}}}"/>
                    <StrokeHighlightControl Style="{StaticResource A_Style_ContentControl_TileSelectionStroke}" Focusable="False"/>
                </Grid>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                        <Setter TargetName="ItemText" Property="local:ScreenReader.Line" Value="{Binding Text, ElementName=ItemText}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocused}" Value="True">
                        <Setter TargetName="DropShadow" Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <Style x:Key="A_Style_RaceCustomiser_ListBoxItem"
                   BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_Gaps}"
                           TargetType="ListBoxItem">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding OnSelectCommand.DeniedCommand, Converter={StaticResource A_Converter_DeniedCommandToLockState}}" Value="{x:Static local:LockState.Locked}">
                        <Setter Property="Tag" Value="Inactive"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding LockState}" Value="{x:Static local:LockState.Locked}">
                        <Setter Property="Tag" Value="Inactive"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZRun_Description_Bold" TargetType="local:FZRun">
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Green}" />
            </Style>

            <MappingConverter x:Key="A_MappingConverter_Bold_Description">
                <MappingConverterEntry Key="{NoCase BOLD}" Value="{StaticResource A_Style_FZRun_Description_Bold}"/>
            </MappingConverter>

            <Style x:Key="A_Style_FrameworkElement_ContentContainer"
                   TargetType="FrameworkElement"
                   BasedOn="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                <Setter Property="Margin" Value="-5,34,0,0" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding SelectedChapter, Converter={StaticResource H_TrueIfNotNull}}" Value="True">
                        <Setter Property="Margin" Value="0,60,0,-23" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <ControlTemplate x:Key="A_Template_Separator_Item">
                <local:FZMaterial Color="{StaticResource H_Color_Primary_Black}"
                                  Height="5"
                                  Width="512"/>
            </ControlTemplate>

            <Style x:Key="A_Style_Separator_Item"
                   TargetType="ListBoxItem">
                <Setter Property="Focusable"
                        Value="False" />
                <Setter Property="Height"
                        Value="5" />
                <Setter Property="Width"
                        Value="512" />
                <Setter Property="Margin"
                        Value="0,10" />
                <Setter Property="Template"
                        Value="{StaticResource A_Template_Separator_Item}"/>
            </Style>

        </ResourceDictionary>
    </Page.Resources>

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

    <Grid x:Name="PART_LayoutRoot">
        <Control x:Name="DefaultBackground"
                 Style="{StaticResource A_Style_Control_ScreenBackground}" />

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

        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <ControllerButtonPanel x:Name="PART_HelpPanel"
                                 Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <ControllerButtonControl Button="A"
                                         Description="{Loc HelpButtons.IDS_Select}" />
                <ControllerButtonControl Button="B"
                                         Description="{Loc HelpButtons.IDS_Back}" />
            </ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}"
                ClipToBounds="False">
            <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                  ClipToBounds="False">
                <StackPanel VerticalAlignment="Center"
                            HorizontalAlignment="Left"
                            ClipToBounds="False">

                    <ContentControl x:Name="ContentControl_SceneTitle"
                                    Content="{Binding ScreenTitle}"
                                    local:BindingProxy.A="{Binding ScreenTitleIcon}"
                                    Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                    HorizontalAlignment="Left"
                                    Width="512"
                                    Margin="0,0,0,4"
                                    Visibility="{Binding ScreenTitle, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"/>

                    <DockPanel Height="708">
                        <Decorator Margin="4,0,0,0"
                                   DataContext="{Binding EventInfoDataView}"
                                   DockPanel.Dock="Right">
                            <ContentControl x:Name="PART_Flyer"
                                            DataContext="{Binding CampaignSetupItem}"
                                            Style="{StaticResource A_Style_Control_CampaignFlyer}"/>
                        </Decorator>

                        <DockPanel Width="512">
                            <Control x:Name="RouteInfoRoot"
                                     Style="{StaticResource A_Style_Event_RaceInfoPanel_PreRace}" 
                                     Margin="0,0,0,2"
                                     Height="398"
                                     Width="512"
                                     DataContext="{Binding EventInfoDataView}"
                                     DockPanel.Dock="Top"/>

                            <local:WrapListBox x:Name="PART_ItemListBox"
                                                ItemsSource="{Binding Items}"
                                                ScrollOrientation="Vertical"
                                                AllowMouseWheelScrolling="False"
                                                Template="{StaticResource H_ControlTemplate_Carousel_Default}"
                                                ItemWidth="512" 
                                                ItemHeight="54"
                                                ItemTemplate="{StaticResource A_DataTemplate_ListItem_RaceCustomiserMenuItem}"
                                                ItemContainerStyle="{StaticResource A_Style_RaceCustomiser_ListBoxItem}"
                                                SeparatorPlacement="{Binding SeparatorPlacementFunc, RelativeSource={RelativeSource AncestorType=Page}}"
                                                SeparatorItemStyle="{StaticResource A_Style_Separator_Item}"
                                                local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                                OverrideAcrossNavigation="True"
                                                Panel.ZIndex="1"
                                                Height="187"
                                                Margin="0,0,0,2"
                                                DockPanel.Dock="Top"
                                                />
                            <!--Standard description panel for many screens using this menu-->
                            <local:FZMaterial x:Name="DescriptionPanel"
                                              DataContext="{Binding SelectedItem, ElementName=PART_ItemListBox}"
                                              DockPanel.Dock="Bottom"
                                              Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"
                                              Color="{StaticResource H_Color_Glass_Purple_20pc}"
                                              Panel.ZIndex="0">
                                <Grid ClipToBounds="True"
                                            Margin="15,10,15,15">
                                    <local:FZTextBlock Text="{Binding Description}"
                                                       Style="{StaticResource A_Style_FZTextBlock_HorizonB}"
                                                       MarkupConverter="{StaticResource A_MappingConverter_Bold_Description}"
                                                       HorizontalAlignment="Left"
                                                       CapHeight="18"
                                                       VerticalAlignment="Top"
                                                       TextWrapping="Wrap"
                                                       Color="{StaticResource A_Color_White}"
                                                       Stretch="None"
                                                       Margin="0,5,0,0"
                                                       AutoScroll.AllowScrolling="True"
                                                       AutoScroll="{StaticResource H_AutoScrollSettings_Descriptions}"
                                                       local:ScreenReader.Event="OnChange"
                                                       local:ScreenReader.ControlType="None"
                                                       local:ScreenReader.Line="{Binding DescriptionScreenReader, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                                       local:ScreenReader.LineType="ItemDescription"/>
                                </Grid>
                            </local:FZMaterial>
                        </DockPanel>
                    </DockPanel>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
