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

    <Page.Resources>
        <System:Double x:Key="A_Double_SlotMenu_WrapPanel_ItemsPerRow">1</System:Double>
        <local:LinearTransformConverter x:Key="A_LinearTransformConverter_SlotMenu_RowsToHeight"
                                            Scale="54" /> 
        
        <DataTemplate x:Key="A_DataTemplate_ListItem_PreRaceMenu">
            <Grid Name="Container">
                <RoutedEventCommand x:Name="MouseLeftButtonUpCommand" 
                                    local:RoutedEventCommand.Action="{Binding RelativeSource={RelativeSource Self}}"
                                    RoutedEvent="UIElement.MouseLeftButtonUp"
                                    Command="{Binding OnSelectCommand, ElementName=MouseLeftButtonUpCommand}" />
                <local:FZTextBlock Name="OptionText"
                                   Text="{Binding Heading}"
                                   IsHitTestVisible="False"
                                   Style="{StaticResource A_Style_FZTextBlock_OptionText_Heading}"/>
                <FZMaterial Name="OptionIcon" 
                            ImageSource="{Binding IconPath}" 
                            Visibility="{Binding IconPath, Converter={StaticResource A_StringVisConverter}}" 
                            IsHitTestVisible="False"
                            HorizontalAlignment="Right" 
                            Height="32" 
                            Width="32" 
                            Margin="0,0,18,0"
                            Color="{StaticResource H_Color_Primary_Black}"/>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
                    <Setter TargetName="OptionIcon" Property="Color" Value="{StaticResource H_Color_Primary_White}"/> 
                </DataTrigger>
                <!-- Disabled button -->
                <DataTrigger Binding="{Binding OnSelectCommand.DeniedCommand, Converter={StaticResource A_Converter_DeniedCommandToLockState}}" Value="{x:Static local:LockState.Locked}">
                    <Setter TargetName="OptionText" Property="Opacity" Value="0.6"/>
                    <Setter TargetName="OptionText" Property="Color" Value="{StaticResource A_Color_White}"/>
                </DataTrigger>
            </DataTemplate.Triggers>

        </DataTemplate>
        <Style x:Key="A_Style_ListItem_PreRaceMenu"
                   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>
            </Style.Triggers>
        </Style>

    </Page.Resources>

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

    <Grid x:Name="PART_LayoutRoot">
        <!-- Bars -->
        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
            <ContentControl x:Name="PART_DefaultHelpPanel" local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}" Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <Decorator Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <ContentControl Style="{StaticResource A_Style_ContentControl_ActivityInfoPanel}" Content="{Binding InfoPanel}"/>
        </Decorator>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <Decorator Style="{StaticResource A_Style_FrameworkElement_FadeOnlyTransition}"
                KeyboardNavigation.DirectionalNavigation="Contained"
                Width="370"
                HorizontalAlignment="Left"
                VerticalAlignment="Bottom" Margin="-5,0,0,81">
                <local:WrapListBox x:Name="PART_ItemListBox"
                                   ItemsSource="{Binding Items}"
                                   ScrollOrientation="Vertical"
                                   AllowMouseWheelScrolling="False"
                                   Template="{StaticResource H_ControlTemplate_Carousel_Default}"
                                   ItemWidth="370"
                                   ItemHeight="54"
                                   ItemTemplate="{StaticResource A_DataTemplate_ListItem_PreRaceMenu}"
                                   ItemContainerStyle="{StaticResource A_Style_ListItem_PreRaceMenu}"
                                   EmptyItemStyle="{x:Null}"
                                   local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                   OverrideAcrossNavigation="True"
                                   Panel.ZIndex="1"
                                   MultiDataConversion.Converter="{MathOperationConverter Operation=Multiply}"
                                   MultiDataConversion.TargetType="{Type Double}"
                                   MultiDataConversion.Value="{Binding ItemsSource.Count, RelativeSource={RelativeSource Self}}"
                                   MultiDataConversion.Parameter="{StaticResource A_Double_SlotMenu_WrapPanel_ItemsPerRow}"
                                   Height="{Binding (MultiDataConversion.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_LinearTransformConverter_SlotMenu_RowsToHeight}}"  />
            </Grid>
        </Border>
    </Grid>
</PreRaceMenu>
