<Page 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"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

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

    <Page.Resources>
        <Double x:Key="A_Double_ListItem_Width">398</Double>
        <Double x:Key="A_Double_ListItem_Height">520</Double>
        <Thickness x:Key="A_Margin_ListItem">2</Thickness>

        <ItemsPanelTemplate x:Key="A_ItemsPanel_RallyLine">
            <StackPanel IsItemsHost="True"
                        Orientation="Horizontal"
                        Margin="{Convert {StaticResource A_Margin_ListItem}, Converter={StaticResource H_InvertConverter}}"/>
        </ItemsPanelTemplate>

        <Style x:Key="A_Style_FZMaterial_ShadowBase_Dynamic"
               TargetType="{Type FZMaterial}"
               BasedOn="{StaticResource A_Style_FZMaterial_ShadowBase_Dynamic}">
            <Setter Property="Margin" Value="-10"/>
        </Style>

         <Style x:Key="A_Style_ContentControl_RallyLine_ContainerStyle"
                TargetType="ContentControl"
                BasedOn="{StaticResource A_Style_ContentControl_Carousel_ContainerStyle_SelectOnMouseHover}">
            <Style.Resources>
                <CornerRadius x:Key="A_CornerRadius_Dynamic_CarouselTile">3</CornerRadius>
                <Style x:Key="H_Style_TemplatedElement_MouseRollover"
                       BasedOn="{StaticResource A_Style_Control_CarouselItem_MouseRollover_AlwaysSelectWhenClicked}"
                       TargetType="{x:Type Control}">
                    <Setter Property="DynamicData.Data">
                        <Setter.Value>
                            <DynamicDataSource>
                                <DynamicDataItem Name="MouseRolloverCornerRadius"
                                                 DataType="CornerRadius"
                                                 Value="3" />
                                <DynamicDataItem Name="MouseRolloverDisableWhenSelected"
                                                 DataType="Boolean"
                                                 Value="False" />
                            </DynamicDataSource>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="Margin" Value="{StaticResource A_Margin_ListItem}"/>
            <Setter Property="Width" Value="{StaticResource A_Double_ListItem_Width}"/>
            <Setter Property="Height" Value="{StaticResource A_Double_ListItem_Height}"/>
         </Style>

         <MappingConverter x:Key="A_RallyLineToBackgroundPathConverter" CheckEnumKey="XAMLRallyRaceLine">
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Off}" Value="game:\media\UI\Textures\Data_Bound\PDLC2\Rally_Driving_Line_Off.png" />
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Inherit}" Value="game:\media\UI\Textures\Data_Bound\PDLC2\Rally_Driving_Line_On.png" />
         </MappingConverter>

         <MappingConverter x:Key="A_RallyLineToItemTitle" CheckEnumKey="XAMLRallyRaceLine">
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Off}" Value="{Loc Campaign.IDS_Astra_RallyLine_Off}" />
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Inherit}" Value="{Loc Campaign.IDS_Astra_RallyLine_On}" />
         </MappingConverter>

         <MappingConverter x:Key="A_RallyLineToItemDesc" CheckEnumKey="XAMLRallyRaceLine">
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Off}" Value="{Loc Campaign.IDS_Astra_RallyLine_Off_Sub}" />
            <MappingConverterEntry Key="{Static XAMLRallyRaceLine.Inherit}" Value="{Loc Campaign.IDS_Astra_RallyLine_On_Sub}" />
         </MappingConverter>

        <DataTemplate x:Key="A_DataTemplate_RallyLineItem">
            <Grid Margin="4"
                  IsHitTestVisible="False">
                <FZMaterial ImageSource="{Binding Value, Converter={StaticResource A_RallyLineToBackgroundPathConverter}}"/>
                <Grid VerticalAlignment="Top"
                    Height="68">
                    <FZMaterial Color="#1c1c1c" Opacity="0.7"/>
                    <FZTextBlock Text="{Binding Value, Converter={StaticResource A_RallyLineToItemTitle}}"
                        TextAlignment="Center"
                        VerticalAlignment="Center"
                        Color="{StaticResource H_Color_Primary_White}"
                        CapHeight="20"
                        FontFamily="Horizon_A"
                        Margin="24,0"/>
                </Grid>
                <Grid VerticalAlignment="Bottom"
                    Height="50">
                    <FZMaterial Color="#1c1c1c" Opacity="0.7"/>
                    <FZTextBlock Text="{Binding Value, Converter={StaticResource A_RallyLineToItemDesc}}"
                        TextAlignment="Center"
                        VerticalAlignment="Center"
                        Color="#cdcdcd"
                        CapHeight="18"
                        FontFamily="Horizon_B"
                        Margin="24,0"/>
                </Grid>
            </Grid>
        </DataTemplate>

        <Style x:Key="A_Style_FZRun_Description_Highlight" TargetType="local:FZRun">
            <Setter Property="FontFamily" Value="Horizon_C" />
            <Setter Property="Color" Value="{StaticResource H_Color_Primary_Yellow}" />
        </Style>
        
        <MappingConverter x:Key="A_MappingConverter_DescriptionHighlight">
            <MappingConverterEntry Key="{NoCase HIGHLIGHT}" Value="{StaticResource A_Style_FZRun_Description_Highlight}" />
        </MappingConverter>

        <Style x:Key="A_Style_FZTextBlock_Description" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_HorizonD}">
            <Setter Property="MarkupConverter" Value="{StaticResource A_MappingConverter_DescriptionHighlight}"/>
        </Style>
    </Page.Resources>

    <Grid>
        <FZMaterialGlassCapture />
        <FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}" />
        <FZMaterialGlassCapture />
        <ContentControl x:Name="BottomBar"
            Style="{StaticResource A_Style_ButtonBar}">
            <ControllerButtonPanel x:Name="PART_HelpPanel"
                Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <ControllerButtonControl
                    Button="{Binding Button, ElementName=SelectButtonInput}"
                    Description="{Loc HelpButtons.IDS_Select}" />
            </ControllerButtonPanel>
        </ContentControl>

        <Grid x:Name="PART_LayoutRoot">
            <Border Style="{StaticResource A_Style_Border_ScenePadding}">
                <DockPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Width="800"
                           Margin="0,0,0,0">
                    <Grid Height="72"
                          DockPanel.Dock="Top">
                        <FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll1px}"
                            Color="{StaticResource H_Color_Primary_Purple}"/>
                        <FZTextBlock Text="{Loc Campaign.IDS_Astra_RallyLine_Title}"
                            TextAlignment="Center"
                            Color="{StaticResource H_Color_Primary_White}"
                            CapHeight="29"
                            FontFamily="Horizon_A"
                            Margin="21"/>
                    </Grid>
                    <Grid MinHeight="84" x:Name="DescriptionPanel"
                        DockPanel.Dock="Bottom">
                        <FZMaterial Style="{StaticResource H_Style_Container_GlassHighBlur_Description}"/>
                        <local:FZTextBlock Text="{Loc Campaign.IDS_Astra_RallyLine_Desc}"
                                           Style="{StaticResource A_Style_FZTextBlock_Description}"
                                           HorizontalAlignment="Left"
                                           VerticalAlignment="Center"
                                           Margin="22,30"
                                           CapHeight="15"
                                           TextWrapping="Wrap"
                                           Color="{StaticResource H_Color_Primary_White}"/>
                    </Grid>
                    <CommonListBox x:Name="PART_ItemListBox"
                                   Margin="0,4"
                                   ItemsPanel="{StaticResource A_ItemsPanel_RallyLine}"
                                   ItemContainerStyle="{StaticResource A_Style_ContentControl_RallyLine_ContainerStyle}"
                                   ItemTemplate="{StaticResource A_DataTemplate_RallyLineItem}"
                                   ItemsSource="{Binding Items}"
                                   local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                   SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
                        <CommonListBox.Template>
                            <ControlTemplate TargetType="ItemsControl">
                                <ItemsPresenter/>
                            </ControlTemplate>
                        </CommonListBox.Template>
                    </CommonListBox>
                </DockPanel>
            </Border>
        </Grid>
    </Grid>
</Page>
