<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.Scenes.Anthem.A_GrandmasterLeaderboard"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">  
    
    <Page.Resources>
        <ResourceDictionary>
            <GridLength x:Key="A_GridLength_Column_Position_Width">52</GridLength>
            <GridLength x:Key="A_GridLength_Column_PositionSpacer_Width">32</GridLength>
            <GridLength x:Key="A_GridLength_Column_Rank_Width">94</GridLength>
            <GridLength x:Key="A_GridLength_Column_Rank_Width_Space">16</GridLength>
            <GridLength x:Key="A_GridLength_Column_DriverName_Width">410</GridLength>

            <GridLength x:Key="A_GridLength_Column_Score_Width">198</GridLength>
            <GridLength x:Key="A_GridLength_Column_Score_Width_Space">42</GridLength>

            <Style x:Key="A_Style_ColumnDefinition_Member_Width" TargetType="{x:Type ColumnDefinition}">
                <Setter Property="Width" Value="0"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}" Value="True">
                        <Setter Property="Width" Value="{StaticResource A_GridLength_Column_Score_Width}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_ColumnDefinition_Member_Spacer_Width" TargetType="{x:Type ColumnDefinition}">
                <Setter Property="Width" Value="0"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}" Value="True">
                        <Setter Property="Width" Value="{StaticResource A_GridLength_Column_Score_Width_Space}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>            

            <local:MappingConverter x:Key="A_Converter_Is_Team_Narrated_Desc">
                <local:MappingConverterEntry Key="true" Value="{Binding ClubName}" />
                <local:MappingConverterEntry Key="false" Value="{Binding UserProfile.FormattedGamertag}" />
            </local:MappingConverter>


            <Style x:Key="A_Style_Team_Description">
                <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding UserProfile.FormattedGamertag}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}" Value="True">
                        <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding ClubName}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>            

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


            <!-- 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_Rank_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Rank_Width_Space}"/>

                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_DriverName_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>

                            <ColumnDefinition Style="{StaticResource A_Style_ColumnDefinition_Member_Width}"/>
                            <ColumnDefinition Style="{StaticResource A_Style_ColumnDefinition_Member_Spacer_Width}"/>

                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_Width}"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_Width_Space}"/>

                            <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_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="4" Text="{local:Loc PreRaceMenu.IDS_StartingGrid_DriverName}" Margin="10,0,0,0" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" 
                                           Visibility="{Binding IsTeamView, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}"/>
                        <local:FZTextBlock Grid.Column="4" Text="{local:Loc Scoreboard.IDS_Grandmaster_Team_Leaderboard_Name}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}"
                                           Visibility="{Binding IsTeamView, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                        
                        <local:FZTextBlock Grid.Column="6" Text="{Binding Source={local:Loc Scoreboard.IDS_Grandmaster_Team_Leaderboard_Members}}"
                                           Visibility="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                           Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="8" Text="{Binding Source={local:Loc Scoreboard.IDS_Grandmaster_Leaderboard_WinsThisSeries}}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                        <local:FZTextBlock Grid.Column="10" Text="{Binding Source={local:Loc Scoreboard.IDS_Grandmaster_Leaderboard_LossesThisSeries}}" Style="{StaticResource A_Style_FZTextBlock_DriverListHeading}" />
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Row" TargetType="ListBoxItem">
                <Grid Style="{StaticResource A_Style_Team_Description}" Margin="{StaticResource A_Thickness_LeaderboardRowMargin}"
                     x:Name="RowDescription"
                     local:ScreenReader.LineType="ItemDescription"
                     local:ScreenReader.Event="OnChange"
                     local:ScreenReader.ControlType="Button"                                                               
                     local:MultiStringFormatter.Param1="{Binding Wins}"
                     local:MultiStringFormatter.Param2="{Binding Source={local:Loc InGame.IDS_PostRace_EventWinningTeam }}"
                     local:MultiStringFormatter.Param3="{Binding Losses}"
                     local:MultiStringFormatter.Param4="{Binding Source={local:Loc Scoreboard.IDS_Grandmaster_Leaderboard_LossesThisSeries}}"                     
                     local:MultiStringFormatter.Format="{StaticResource A_String_Format_Narration}">

                    <StackPanel Name="Content" Orientation="Horizontal" Visibility="{Binding IsLoading, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                        <ContentControl Style="{StaticResource A_Style_ContentControl_SelectableRow}">
                            <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_Rank_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Rank_Width_Space}"/>

                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_DriverName_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Spacer_Width}"/>

                                    <ColumnDefinition Style="{StaticResource A_Style_ColumnDefinition_Member_Width}"/>
                                    <ColumnDefinition Style="{StaticResource A_Style_ColumnDefinition_Member_Spacer_Width}"/>

                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_Width}"/>
                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_Width_Space}"/>

                                    <ColumnDefinition Width="{StaticResource A_GridLength_Column_Score_Width}"/>
                                </Grid.ColumnDefinitions>
                                <ContentControl Grid.Column="0" Template="{StaticResource A_ControlTemplate_Cell_Position}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-18,0,0,0"/>
                                <ContentControl Grid.Column="2" Style="{StaticResource A_Style_ControlTemplate_Cell_SeriesRank}" VerticalAlignment="Center" />
                                
                                <ContentControl Grid.Column="4" Template="{StaticResource A_ControlTemplate_Cell_DriverName}" 
                                                Visibility="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}" VerticalAlignment="Center" />

                                <ContentControl Grid.Column="4" Template="{StaticResource A_ControlTemplate_Cell_GrandmasterTeamName}" 
                                                Visibility="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" VerticalAlignment="Center" />
                                
                                <ContentControl Grid.Column="6" Template="{StaticResource A_ControlTemplate_Cell_MemberCount}" 
                                                Visibility="{Binding IsTeamView, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" VerticalAlignment="Center" />
                                <ContentControl Grid.Column="8" Template="{StaticResource A_ControlTemplate_Cell_Wins}" VerticalAlignment="Center" />
                                <ContentControl Grid.Column="10" Template="{StaticResource A_ControlTemplate_Cell_Losses}" VerticalAlignment="Center" />
                            </Grid>
                        </ContentControl>
                    </StackPanel>
                </Grid>

                <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_Grandmaster" TargetType="ListBoxItem" BasedOn="{StaticResource A_Style_ListBoxItem_LeaderboardBase}">
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_Row}" />
            </Style>

        </ResourceDictionary>
    </Page.Resources>

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

    <Border>
        <Grid x:Name="LayoutRoot">
            <!-- Background Blur -->
           <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />
            <Grid Visibility="{Binding IsInPauseFlow, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                <local:FZMaterialGlassCapture />
                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"/>
            </Grid>

            <local:FZMaterialGlassCapture />

            <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_Scoreboard_Grandmaster_TypeAdventureFilter}"
                                    Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>

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

                    <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                                Orientation="Horizontal"
                                HorizontalAlignment="Center">
                        <StackPanel>
                            <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_Grandmaster}"  
                                                     Style="{StaticResource A_Style_CommonListBox_Leaderboard}" 
                                                     VerticalAlignment="Top"
                                                     VirtualizingStackPanel.VirtualizationMode="Recycling" ScrollViewer.CanContentScroll="True"
                                                     Panel.ZIndex="2"/>
                            <Control Style="{StaticResource A_Style_FooterRow}" Template="{StaticResource A_ControlTemplate_FooterRow_Default}" />
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </Border>
        </Grid>
    </Border>
</Page>