<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"
	  x:Class="ForzaUI.A_RivalsLeaderboard"
      mc:Ignorable="d"
	  Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      Name="p1"
      >

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

    <Page.Resources>
        <ResourceDictionary>

            <Style x:Key="A_Style_FZMaterial_AssistsIcon" TargetType="local:FZMaterial">
                <Setter Property="Height" Value="20" />
                <Setter Property="Width" Value="20" />
                <Setter Property="Color" Value="Gray" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/No_Assist.png" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsLocalPlayer}" Value="True">
                        <Setter Property="Color"
                        Value="{StaticResource A_Color_LocalPlayer_Text}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}}" Value="True">
                        <Setter Property="Color"
                        Value="{StaticResource A_Color_HighlightText}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_AssistsIconABS" TargetType="local:FZMaterial" BasedOn="{StaticResource A_Style_FZMaterial_AssistsIcon}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding UsedABS}" Value="True">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Half_Left.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding UsedAutoBrake}" Value="True">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Full.png" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_AssistsIconTCS" TargetType="local:FZMaterial" BasedOn="{StaticResource A_Style_FZMaterial_AssistsIcon}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding UsedSTM}" Value="True">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Half_Left.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding UsedTCS}" Value="True">
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Half_Right.png" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding UsedSTM}" Value="True"/>
                            <Condition Binding="{Binding UsedTCS}" Value="True"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Full.png" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_Gear" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_LeaderboardRow}">
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Text" Value="{local:Loc PreRaceMenu.IDS_StartingGrid_Gear_Manual}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding UsedClutch}" Value="True">
                        <Setter Property="Text" Value="{local:Loc PreRaceMenu.IDS_StartingGrid_Gear_ManualClutch}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding UsedAutoShift}" Value="True">
                        <Setter Property="Text" Value="{local:Loc PreRaceMenu.IDS_StartingGrid_Gear_Automatic}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <GridLength x:Key="A_GridLength_Column_Position_Width">52</GridLength>
            <GridLength x:Key="A_GridLength_Column_PositionSpacer_Width">18</GridLength>
            <GridLength x:Key="A_GridLength_Column_DriverName_Width">408</GridLength>
            <GridLength x:Key="A_GridLength_Column_CarName_Width">220</GridLength>
            <GridLength x:Key="A_GridLength_Column_CarClass_Width">185</GridLength>
            <GridLength x:Key="A_GridLength_Column_Time_Width">150</GridLength>
            <GridLength x:Key="A_GridLength_Column_ABS_Width">88</GridLength>
            <GridLength x:Key="A_GridLength_Column_TCS_Width">80</GridLength>
            <GridLength x:Key="A_GridLength_Column_Gear_Width">54</GridLength>

            <!-- Row Templates -->
            <ControlTemplate x:Key="A_ControlTemplate_HeaderRow" TargetType="Control">
                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_FlatPanel_HeaderPill}" >
                    <Grid Margin="18,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Position_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_PositionSpacer_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_DriverName_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_CarName_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_CarClass_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Time_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_ABS_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_TCS_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Gear_Width}"/>
                        </Grid.ColumnDefinitions>
                        <local:FZTextBlock Grid.Column="0" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_Position}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}"/>
                        <local:FZTextBlock Grid.Column="2" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_DriverName}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="4" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_CarName}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="6" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_Class}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="7" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_Time}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="8" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_ABS}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" HorizontalAlignment="Center"/>
                        <local:FZTextBlock Grid.Column="9" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_TCS}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" HorizontalAlignment="Center"/>
                        <local:FZTextBlock Grid.Column="10" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_Gear}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" HorizontalAlignment="Center"/>
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

             <String x:Key="A_String_Format_Narration">{0} . {1} {2} . {3} {4}</String>

            <ControlTemplate x:Key="A_ControlTemplate_Row" TargetType="ListBoxItem">
                <StackPanel Orientation="Horizontal" Margin="{StaticResource A_Thickness_LeaderboardRowMargin}">
                    <StackPanel Name="Content" Orientation="Horizontal" Visibility="{Binding IsLoading, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden_Inverse}}">
                        <ContentControl Style="{StaticResource A_Style_ContentControl_SelectableRow}">
                            <Grid x:Name="RowDescription"
                                local:ScreenReader.LineType="ItemDescription"
                                local:ScreenReader.Event="OnChange"
                                local:ScreenReader.ControlType="Button"                                                                                                                                                               
                                local:MultiStringFormatter.Param0="{Binding UserProfile.FormattedGamertag}"
                                local:MultiStringFormatter.Param1="{Binding Source={local:Loc Assists.IDS_Car}}"                                
                                local:MultiStringFormatter.Param2="{Binding CarName}"
                                local:MultiStringFormatter.Param3="{Binding Source={local:Loc Benchmark.IDS_Time}}"                                
                                local:MultiStringFormatter.Param4="{Binding Time}"
                                local:MultiStringFormatter.Format="{StaticResource A_String_Format_Narration}"
                                Margin="18,0">

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Position_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_PositionSpacer_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_DriverName_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_CarName_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_CarClass_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Time_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_ABS_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_TCS_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Gear_Width}"/>
                                </Grid.ColumnDefinitions>
                                <ContentControl Grid.Column="0" Template="{StaticResource A_ControlTemplate_Cell_Position}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-18,0,0,0"/>
                                <ContentControl Grid.Column="2" Template="{StaticResource A_ControlTemplate_Cell_DriverName}"/>
                                <ContentControl Grid.Column="4" Template="{StaticResource A_ControlTemplate_Cell_CarName}" />
                                <ContentControl Grid.Column="6" Template="{StaticResource A_ControlTemplate_Cell_Class}" HorizontalAlignment="Left" />
                                <ContentControl Grid.Column="7" Template="{StaticResource A_ControlTemplate_Cell_Time}" />
                                <local:FZMaterial Grid.Column="8" Style="{StaticResource A_Style_FZMaterial_AssistsIconABS}" />
                                <local:FZMaterial Grid.Column="9" Style="{StaticResource A_Style_FZMaterial_AssistsIconTCS}" />
                                <local:FZTextBlock Grid.Column="10" Style="{StaticResource A_Style_FZTextBlock_Gear}" />
                            </Grid>
                        </ContentControl>
                    </StackPanel>
                </StackPanel>

                <ControlTemplate.Triggers>                    
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">
                        <Setter TargetName="RowDescription" Property="local:ScreenReader.Line" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}" />
                    </DataTrigger>
                </ControlTemplate.Triggers>                
            </ControlTemplate>

            <!-- Row Style -->
            <Style x:Key="A_Style_ListBoxItem_DriverList_StartingGrid" TargetType="ListBoxItem" BasedOn="{StaticResource A_Style_ListBoxItem_LeaderboardBase}">
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_Row}" />
            </Style>

        </ResourceDictionary>
    </Page.Resources>

    <Border>
        <Grid x:Name="LayoutRoot">
            <!-- Background Blur -->
           <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

            <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}"
                    local:ControllerButtonPanel.XDescription="{local:Loc HelpButtons.IDS_Filter}"
                    local:ControllerButtonPanel.YDescription="{local:Loc HelpButtons.IDS_PlayerOptions}"
                    Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>

            <Border Style="{StaticResource A_Style_Border_ScenePadding}">
                <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,38,0,0">
                    <StackPanel Orientation="Horizontal" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                        <ContentControl x:Name="TitleBlock"
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                        Content="{Binding Title}"
                                        local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Leaderboards.png" />
                    </StackPanel>

                    <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" HorizontalAlignment="Center">
                        <Control Style="{StaticResource A_Style_HeaderRow}" Template="{StaticResource A_ControlTemplate_HeaderRow}" />
                        <local:CommonListBox x:Name="PART_ListBox_LeaderboardList" 
                                             ItemsSource="{Binding LeadersList}" 
                                             MaxHeight="561"
                                             ItemContainerStyle="{StaticResource A_Style_ListBoxItem_DriverList_StartingGrid}"  
                                             Style="{StaticResource A_Style_CommonListBox_Leaderboard}" 
                                             VerticalAlignment="Top"
                                             VirtualizingStackPanel.VirtualizationMode="Recycling" ScrollViewer.CanContentScroll="true"/>
                        <Control Style="{StaticResource A_Style_FooterRow}" Template="{StaticResource A_ControlTemplate_FooterRow_Default}" />
                    </StackPanel>
                </StackPanel>
            </Border>
        </Grid>
    </Border>
</Page>
