<Page 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:local="clr-namespace:ForzaUI"
      x:Name="page"
      x:Class="ForzaUI.A_RivalsResultsMenu"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

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

    <Page.Resources>
        <ResourceDictionary>
            <Color x:Key="A_Color_HighlightTime">#7AC943</Color>

            <Style x:Key="A_Style_FZTextBlock_Label"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Yellow}" />
                <Setter Property="CapHeight" Value="20" />
                <Setter Property="Margin" Value="0,0,11,0" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>

            <Style x:Key="A_Style_FZTextBlock_Time"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
                <Setter Property="CapHeight"
                        Value="20" />
                <Setter Property="VerticalAlignment"
                        Value="Center" />
                <Setter Property="Color"
                        Value="{StaticResource H_Color_Primary_White}" />
            </Style>

            <Style x:Key="A_Style_FZTextBlock_YourTime_Split"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_Time}">
                <Setter Property="Color"
                        Value="{StaticResource H_Color_Primary_Green}" />
                <Setter Property="CapHeight"
                        Value="20" />
                <Setter Property="FontFamily"
                        Value="Horizon_B" />    
            </Style>

            <Style x:Key="A_Style_FZMaterial_RivalResultsMenuDirtyIcon"
                   TargetType="local:FZMaterial">
                <Setter Property="Visibility"
                        Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" />
                <Setter Property="ImageSource"
                        Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Dirty_Lap.png" />
                <Setter Property="Width"
                        Value="32" />
                <Setter Property="Height"
                        Value="32" />
                <Setter Property="VerticalAlignment"
                        Value="Center" />
                <Setter Property="Margin"
                        Value="16,0,0,0" />
            </Style>

            <Style x:Key="A_Style_FZTextBlock_RivalTitleText" TargetType="FZTextBlock"
                BasedOn="{StaticResource H_Style_PostRace_TitleText}">
                <Setter Property="Text" Value="{Binding RivalsUserProfile.FormattedGamertag}"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding HasRival}" Value="False">
                        <Setter Property="Text" Value="{Loc InGame.IDS_PostRace_Finished}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <MappingConverter x:Key="A_Converter_IsDirtyToFormatString" Default="{Loc Scoreboard.IDS_ScreenReader_Format_PlayerTime_Clean}">
                <MappingConverterEntry Key="True" Value="{Loc Scoreboard.IDS_ScreenReader_Format_PlayerTime_Dirty}" />
            </MappingConverter>

        </ResourceDictionary>
    </Page.Resources>
   
    <Border x:Name="PART_LayoutRoot">
        <Grid>
            <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}">
                <ContentControl x:Name="PART_DefaultHelpPanel"
                    local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_BeatenRivalMenu_CollectReward}"
                    local:ControllerButtonPanel.XDescription="{local:Loc HelpButtons.IDS_BeatenRivalMenu_ContinueLapping}"
                    Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>

            <Decorator Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
                <StackPanel HorizontalAlignment="Center" 
                            Margin="0,204,0,0"
                            Orientation="Vertical"
                            local:MultiStringFormatter.Format="{Loc Scoreboard.IDS_ScreenReader_Format_RivalHeader}"
                            local:MultiStringFormatter.Param0="{Binding RivalResultIntroText}"
                            local:MultiStringFormatter.Param1="{Binding Text, ElementName=rivalTitleText}"
                            local:ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                            local:ScreenReader.LineType="ScreenDescription"
                            local:ScreenReader.Event="OnChange">

                    <!-- ZIndex on this decorator ensures that it renders in front of the BgEllipse, which is below for layout reasons -->
                    <Decorator ZPanel.ZIndex="1" Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}" 
                               Margin="55,15"
                               HorizontalAlignment="Left">
                        <ContentControl Content="{Binding RivalResultIntroText}"
                                        Style="{StaticResource A_Style_ContentControl_Header}"
                                        MinWidth="212"/>
                    </Decorator>

                    <Grid>
                        <!-- this grid allows the BgEllipse viewbox (which spans all cols/rows) to size itself based on the actual notification content in the center of the 3x3 grid, without actually affecting the size of it as it would if they shared the same grid cell -->
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Viewbox x:Name="BgEllipseForContrast" Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="3" Stretch="Fill" StretchDirection="Both" Margin="{StaticResource A_Thickness_BgEllipseMargins}"
                             MaxWidth="{Binding ActualWidth, ElementName=rivalTitleText, Mode=OneWay, Converter={MathOperationConverter Operation=Add}, ConverterParameter={StaticResource A_Double_BgEllipsePaddingW}}"
                             MaxHeight="{Binding ActualHeight, ElementName=rivalTitleText, Mode=OneWay, Converter={MathOperationConverter Operation=Add}, ConverterParameter={StaticResource A_Double_BgEllipsePaddingH}}">
                            <!-- this material should be a circle, so it can be distorted by the viewbox around it into an appropriately sized/shaped ellipse -->
                            <FZMaterial Style="{StaticResource H_Style_FZMaterial_BgEllipse_CircleShadow}" />
                        </Viewbox>
                        <Decorator Grid.Row="1" Grid.Column="1" 
                                   Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_1}"
                                   LayoutTransform="{StaticResource H_Transform_PostRaceItalicise}"
                                   Margin="0,0,0,3"
                                   HorizontalAlignment="Center">
                            <local:FZTextBlock x:Name="rivalTitleText"  Style="{StaticResource A_Style_FZTextBlock_RivalTitleText}"
                                               CapHeight="85"/>
                        </Decorator>
                    </Grid>

                    <StackPanel Orientation="Horizontal" 
                                Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_2}"
                                HorizontalAlignment="Right"
                                Margin="0,28,0,0">
                        <local:FZMaterial Style="{StaticResource H_Style_Container_GlassHighBlur_Description}" 
                                          Color="{StaticResource H_Color_Glass_Purple_40pc}">
                            <StackPanel Orientation="Horizontal" 
                                        Margin="25,14"
                                        LayoutTransform="{StaticResource H_Transform_PostRaceItalicise}"
                                        local:MultiStringFormatter.Format="{Binding YourTimeIsDirty, Converter={StaticResource A_Converter_IsDirtyToFormatString}}"
                                        local:MultiStringFormatter.Param0="{Binding Text, ElementName=yourTimeLabel}"
                                        local:MultiStringFormatter.Param1="{Binding Text, ElementName=yourTimeValue, Converter={StaticResource A_TimeDurationNarrationConverter}}"
                                        local:ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                        local:ScreenReader.LineType="SelectedDetails"
                                        local:ScreenReader.Event="OnChange">
                                <StackPanel Visibility="{Binding HasRival, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                            Orientation="Horizontal"
                                            local:MultiStringFormatter.Format="{Binding RivalTimeIsDirty, Converter={StaticResource A_Converter_IsDirtyToFormatString}}"
                                            local:MultiStringFormatter.Param0="{Binding Text, ElementName=rivalTimeLabel}"
                                            local:MultiStringFormatter.Param1="{Binding Text, ElementName=rivalTimeValue, Converter={StaticResource A_TimeDurationNarrationConverter}}"
                                            local:ManualPassthroughProperty.Input="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                                            local:ManualPassthroughProperty.Allowed="{Binding HasRival}"
                                            local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                            local:ScreenReader.LineType="ItemDescription"
                                            local:ScreenReader.Event="OnChange">
                                        <local:FZTextBlock x:Name="rivalTimeLabel" Style="{StaticResource A_Style_FZTextBlock_Label}"
                                                        Text="{local:Loc Rivals.IDS_RivalTime}" />
                                        <local:FZTextBlock x:Name="rivalTimeValue" Style="{StaticResource A_Style_FZTextBlock_Time}"
                                                        Margin="0"
                                                        Text="{Binding RivalTime}"/>
                                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RivalResultsMenuDirtyIcon}"
                                                        Tag="{Binding RivalTimeIsDirty}"/>

                                        <Decorator Width="34"/>
                                </StackPanel>

                                <local:FZTextBlock x:Name="yourTimeLabel" Style="{StaticResource A_Style_FZTextBlock_Label}"
                                           Text="{local:Loc Rivals.IDS_YourTime}" />
                                <local:FZTextBlock x:Name="yourTimeValue" Style="{StaticResource A_Style_FZTextBlock_Time}"
                                                   Margin="0"
                                                   Text="{Binding YourTime}" />
                                <Decorator Margin="0,0,10,0">
                                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RivalResultsMenuDirtyIcon}"
                                                      Tag="{Binding YourTimeIsDirty}" />
                                </Decorator>
                                <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_YourTime_Split}"
                                                   Text="{Binding YourTimeSplit}" 
                                                   Visibility="{Binding HasRival, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                                   local:MultiStringFormatter.Format="{Loc Scoreboard.IDS_ScreenReader_Format_Rival_Gap}"
                                                   local:MultiStringFormatter.Param0="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource A_TimeDurationNarrationConverter}}"
                                                   local:ManualPassthroughProperty.Input="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                                                   local:ManualPassthroughProperty.Allowed="{Binding HasRival}"
                                                   local:ScreenReader.Line="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                                   local:ScreenReader.LineType="ItemState"
                                                   local:ScreenReader.Event="OnChange"/>
                            </StackPanel>
                        </local:FZMaterial>
                    </StackPanel>
                </StackPanel>
            </Decorator>
        </Grid>
    </Border>
</Page>
