<Page x:Class="ForzaUI.Scenes.Anthem.A_RivalsMenu"
      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"
      mc:Ignorable="d"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      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>

        <!-- Template for restrictions elements that are shown as a string -->
        <DataTemplate DataType="{x:Type System:String}">
            <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                              Margin="0,0,5,0"
                              Color="{StaticResource A_Color_ItemStatusBackground}"
                              VerticalAlignment="Bottom"
                              HorizontalAlignment="Left">
                <local:FZTextBlock Text="{Binding Converter={StaticResource A_StringToUpper}}"
                                   Margin="12"
                                   Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}"/>
            </local:FZMaterial>
        </DataTemplate>

        <!-- Template for restrictions elements that are shown as a string -->
        <ItemsPanelTemplate x:Key="A_Template_RestrictionsPanel">
            <WrapPanel IsItemsHost="True" />
        </ItemsPanelTemplate>

        <Style TargetType="local:FZTextBlock"
               x:Key="A_Style_FZTextBlock_RivalDetailsHeader"
               BasedOn="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}">
            <Setter Property="CapHeight" Value="17"/>
            <Setter Property="FontFamily" Value="Horizon_A"/>
        </Style>
        <Style TargetType="local:FZTextBlock"
               x:Key="A_Style_FZTextBlock_RivalDetails"
               BasedOn="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}">
            <Setter Property="CapHeight" Value="22"/>
            <Setter Property="FontFamily" Value="Horizon_B"/>
        </Style>

        <Style x:Key="A_Style_HideIfNoTargetTime" TargetType="FrameworkElement">
            <Setter Property="Visibility"
                    Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedItem.RivalInfo.HasTarget, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="True">
                    <DataTrigger.Setters>
                        <Setter Property="Visibility"
                                Value="Visible" />
                    </DataTrigger.Setters>
                </DataTrigger>
            </Style.Triggers>
        </Style>
      
        <Style x:Key="A_Style_AutoScrollPanel_Description" BasedOn="{StaticResource A_Style_AutoScrollPanel_Masked}" TargetType="local:AutoScrollPanel">
            <Style.Resources>
                <ControlTemplate x:Key="A_ControlTemplate_AutoscrollTemplate_Dynamic">
                    <local:FZTextBlock Text="{Binding Description}"
                         Style="{StaticResource A_Style_FZTextBlock_DescriptionBlockBody}"
                         Color="{StaticResource A_Color_Body_Text}"
                         TextWrapping="Wrap" />
                </ControlTemplate>
            </Style.Resources>
        </Style>

        <Style TargetType="FrameworkElement"
               x:Key="A_Style_FrameworkElement_SelectedTrackComparison">
            <Setter Property="local:MultiDataConversion.TargetType" Value="{x:Type Int32}" />
            <Setter Property="local:MultiDataConversion.Value" Value="{Binding ActiveTrack, RelativeSource={RelativeSource AncestorType=Page}}" />
            <Setter Property="local:MultiDataConversion.Parameter" Value="{Binding MediaTrack}" />
            <Setter Property="local:MultiDataConversion.Converter" Value="{StaticResource A_CompareConverter}" />
        </Style>
        <Style TargetType="FrameworkElement"
               x:Key="A_Style_FrameworkElement_HiddenIfSelectedItemTrackDoesntMatch"
               BasedOn="{StaticResource A_Style_FrameworkElement_SelectedTrackComparison}">
            <Setter Property="Visibility" Value="Collapsed" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding (local:MultiDataConversion.Output), RelativeSource={RelativeSource Self}}"
                             Value="0">
                    <Setter Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="FrameworkElement"
               x:Key="A_Style_FrameworkElement_HiddenIfSelectedItemTrackMatches"
               BasedOn="{StaticResource A_Style_FrameworkElement_SelectedTrackComparison}">
            <Setter Property="Visibility" Value="Visible" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding (local:MultiDataConversion.Output), RelativeSource={RelativeSource Self}}"
                             Value="0">
                    <Setter Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <local:MappingConverter x:Key="A_Converter_TrackToCoverImage"
                                Default="/ForzaUI;component/Textures/Data_Bound/PDLC1/Rivals/UKLarge.png">
            <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.ExpansionOne}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC1/Rivals/ExpansionOneLarge.png" />
            <local:MappingConverterEntry Key="{x:Static local:XAMLTrack.ExpansionTwo}" Value="/ForzaUI;component/Textures/Data_Bound/PDLC2/Rivals/ExpansionTwoLarge.png" />
        </local:MappingConverter>
        <Style TargetType="local:FZMaterial"
               x:Key="A_Style_FZMaterial_HiddenIfNotLoaded"
               BasedOn="{StaticResource A_Style_FrameworkElement_SelectedTrackComparison}">
            <Setter Property="Visibility" Value="Hidden" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Downloaded, RelativeSource={RelativeSource Self}}"
                             Value="True">
                    <Setter Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="local:FZMaterial"
               x:Key="A_Style_FZMaterial_SeasonPill">
            <Setter Property="Preset">
                <Setter.Value>
                    <local:FZMaterialPresetRoundtangle BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
                                                       GradientColorA="{Binding Season, Converter={StaticResource A_Converter_Season_To_Gradient_ColorA}}"
                                                       GradientColorB="{Binding Season, Converter={StaticResource A_Converter_Season_To_Gradient_ColorB}}"
                                                       GradientAngle="90"
                                                       CornerRadius="{StaticResource A_CornerRadius_Inner_All}"/>
                </Setter.Value>
            </Setter>
        </Style>

    </Page.Resources>

    <Grid>
        <local:MappingConverterResourcePreloader Converter="{StaticResource A_Converter_TrackToCoverImage}" ValueType="BitmapImage" />

        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl x:Name="TopBar" Style="{StaticResource A_Style_PlayerBarControl}" />
        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        Width="Auto">
            <ContentControl x:Name="DefaultHelpPanel"
                            local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Select}"
                            local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}">
            <Grid>
                <Grid Style="{StaticResource A_Style_FrameworkElement_ScreenTilt}">
                    <Grid>
                        <StackPanel Orientation="Vertical"
                                    VerticalAlignment="Center">
                            <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                                  local:UIPageTransitionManager.TransitionIndex="1">
                                <ContentControl x:Name="TitleBlock"
                                                Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                                local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/Rivals.png"
                                                Content="{Binding Title}"
                                                HorizontalAlignment="Left" />
                            </Grid>
                            <DockPanel DataContext="{Binding SelectedItem, ElementName=List}"
                                       Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                                       local:UIPageTransitionManager.TransitionIndex="0">
                                <Grid DockPanel.Dock="Left">
                                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll}"
                                                      Color="{StaticResource A_Color_GlassPanel_NonInteractive}"/>
                                    <Grid Width="1382"
                                          Height="498"
                                          Visibility="{Binding HasItems, ElementName=List, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}">
                                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                                          CaptureSubgraph="True">
                                            <Grid Background="#ff0A0E1A">
                                                <Grid Style="{StaticResource A_Style_FrameworkElement_HiddenIfSelectedItemTrackMatches}"
                                                      Width="1382"
                                                      Height="498">
                                                    <local:FZMaterial ImageSource="{Binding MediaTrack, Converter={StaticResource A_Converter_TrackToCoverImage}}"
                                                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                                                      Style="{StaticResource A_Style_FZMaterial_HiddenIfNotLoaded}" />
                                                </Grid>

                                                <local:MapViewControllerWindowed x:Name="RivalsMapMapView"
                                                                                 DataContext="{Binding MainMapData}"
                                                                                 MinMapHeight="1800"
                                                                                 Style="{StaticResource A_Style_MapViewController_UIMap}"
                                                                                 InterpolationTime="0.67" />

                                                <Decorator Style="{StaticResource A_Style_FrameworkElement_HiddenIfSelectedItemTrackDoesntMatch}">
                                                    <local:MapCustomRenderElement Style="{StaticResource A_Style_MapCustomRenderElement_UIMap}" DataContext="{Binding MainMapData}"
                                                                                  MapView="{Binding ElementName=RivalsMapMapView}" />
                                                </Decorator>

                                                <Grid VerticalAlignment="Top">
                                                    <local:FZMaterial Color="Black" Opacity="0.4"/>
                                                    <StackPanel Margin="24">
                                                        <StackPanel.Resources>
                                                            <System:Double x:Key="A_Double_RivalTitle_Separator">0</System:Double>
                                                            <System:Double x:Key="A_Double_RivalTitle_Separator_CHS">6</System:Double>
                                                            <System:Double x:Key="A_Double_RivalTitle_Separator_CHT">6</System:Double>
                                                            <System:Double x:Key="A_Double_RivalTitle_Separator_RU">4</System:Double>
                                                        </StackPanel.Resources>
                                                        <Viewbox StretchDirection="DownOnly" HorizontalAlignment="Left">
                                                            <StackPanel Orientation="Horizontal">
                                                                <local:FZTextBlock Text="{Binding Name, Converter={StaticResource A_StringToUpper}}"
                                                                    Style="{StaticResource A_Style_FZTextBlock_RivalsRouteName}" />
                                                            </StackPanel>
                                                        </Viewbox>
                                                        <Decorator Height="{local:LocalizedResource A_Double_RivalTitle_Separator}"/>
                                                        <StackPanel Visibility="{Binding Restrictions, FallbackValue=Collapsed, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                                            <Decorator Height="14"/>
                                                            <local:FZTextBlock Text="{local:Loc Rivals.IDS_EventRestrictions}"
                                                                               Style="{StaticResource A_Style_FZTextBlock_RivalsRouteSubName}" />
                                                            <Decorator Height="11"/>
                                                            <Grid>
                                                                <!-- Restrictions should come from the selected item, but that isn't set up yet so use the debug ones on the page -->
                                                                <ItemsControl ItemsPanel="{StaticResource A_Template_RestrictionsPanel}"
                                                                              ItemsSource="{Binding Restrictions, RelativeSource={RelativeSource AncestorType=Page}}"/>
                                                                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                                                                  Margin="0,0,5,0"
                                                                                  Color="{StaticResource A_Color_ItemStatusBackground}"
                                                                                  VerticalAlignment="Bottom"
                                                                                  HorizontalAlignment="Left"
                                                                                  Visibility="{Binding Restrictions.Count, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden_Inverse}}">
                                                                    <StackPanel Orientation="Horizontal"
                                                                                Margin="12">
                                                                        <local:FZTextBlock Text="{local:Loc Rivals.IDS_NoRestrictions}"
                                                                                           Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}"/>
                                                                    </StackPanel>
                                                                </local:FZMaterial>
                                                            </Grid>
                                                        </StackPanel>
                                                    </StackPanel>
                                                </Grid>
                                            </Grid>
                                        </local:FZMaterial>

                                        <StackPanel Margin="22,0,0,18"
                                                    VerticalAlignment="Bottom">
                                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_SeasonPill}"
                                                              HorizontalAlignment="Left"
                                                              Visibility="{Binding Restrictions, RelativeSource={RelativeSource AncestorType=Page}, FallbackValue=Collapsed, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                                <local:FZTextBlock Margin="12"
                                                                   Text="{Binding Season, Converter={StaticResource A_Converter_Season_To_String}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}"/>
                                            </local:FZMaterial>

                                            <Decorator Height="12"/>

                                        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                                          Color="{StaticResource A_Color_ItemStatusBackground}"
                                                          HorizontalAlignment="Left">
                                            <StackPanel Orientation="Horizontal"
                                                        Margin="12">
                                                <local:FZTextBlock Text="{local:Loc Rivals.IDS_Distance}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}"
                                                                   Margin="0,0,8,0"/>
                                                <local:FZTextBlock Text="{Binding MainMapData.Distance}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceLarge}" />
                                            </StackPanel>
                                        </local:FZMaterial>
                                        </StackPanel>
                                    </Grid>
                                </Grid>
                                <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                                      local:UIPageTransitionManager.TransitionIndex="20003">
                                    <ContentControl Template="{StaticResource A_ControlTemplate_SidePanel}"
                                                    Tag="{local:Loc Main.IDS_Details}"
                                                    Margin="6,0,0,0">
                                        <Grid>
                                            <StackPanel Visibility="{Binding Restrictions, FallbackValue=Hidden, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}">
                                            <Grid>
                                                <StackPanel Margin="28,24"
                                                            Visibility="{Binding RivalInfo, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}">
                                                    <local:FZTextBlock Text="{local:Loc InGame.IDS_Rival}"
                                                                       Style="{StaticResource A_Style_FZTextBlock_RivalDetailsHeader}" />
                                                    <Decorator Height="9"/>
                                                    <local:FZTextBlock Text="{Binding RivalInfo.UserProfile.FormattedGamertag}"
                                                                       Style="{StaticResource A_Style_FZTextBlock_RivalDetails}"
                                                                       Height="22" />
                                                    <Decorator Height="27"/>
                                                    <UniformGrid Columns="2">
                                                        <StackPanel>
                                                            <local:FZTextBlock Text="{local:Loc Rivals.IDS_TimeToBeat}"
                                                                               Style="{StaticResource A_Style_FZTextBlock_RivalDetailsHeader}" />
                                                            <Decorator Height="9"/>
                                                            <StackPanel Orientation="Horizontal">
                                                                <local:FZTextBlock Text="{Binding RivalInfo.TimeToBeat}"
                                                                                   Style="{StaticResource A_Style_FZTextBlock_RivalDetails}"
                                                                                   Height="22" />
                                                                <Decorator Width="9"/>
                                                                <Decorator Style="{StaticResource A_Style_HideIfNoTargetTime}">
                                                                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Dirty_Lap.png"
                                                                                      Width="24" Height="24"
                                                                                      Visibility="{Binding RivalInfo.TimeToBeatIsDirty, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}" />
                                                                </Decorator>
                                                            </StackPanel>
                                                        </StackPanel>
                                                        <StackPanel>
                                                            <local:FZTextBlock Text="{local:Loc Rivals.IDS_GapToRival}"
                                                                               Style="{StaticResource A_Style_FZTextBlock_RivalDetailsHeader}"
                                                                               HorizontalAlignment="Right" />
                                                            <Decorator Height="9"/>
                                                            <local:FZTextBlock Text="{Binding RivalInfo.TimeDifference}"
                                                                               Style="{StaticResource A_Style_FZTextBlock_RivalDetails}"
                                                                               Height="22"
                                                                               HorizontalAlignment="Right" />
                                                        </StackPanel>
                                                    </UniformGrid>
                                                </StackPanel>
                                                <ProgressBar Style="{StaticResource A_Style_ProgressBar_WaitSpinner}" 
                                                             HorizontalAlignment="Center" 
                                                             VerticalAlignment="Center"
                                                             Visibility="{Binding RivalInfo, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden_Inverse}}" />
                                            </Grid>
                                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Panel_HorizontalDivider}"
                                                              Color="{StaticResource A_Color_ThinDivider}"/>
                                            <StackPanel Orientation="Horizontal"
                                                        Margin="24,20"
                                                        Style="{StaticResource A_Style_HideIfNoTargetTime}">
                                                <local:ControllerButtonControl Style="{StaticResource A_Style_ControllerButtonControl_Default_ShowAlways}"
                                                                               Button="{x:Static local:ControllerButtonType.Y}"
                                                                               UseLargeIcon="True"
                                                                               Height="40" />
                                                <Decorator Width="18"/>
                                                <local:FZTextBlock Text="{Binding Source={local:Loc HelpButtons.IDS_TimeTrial_Change_Rival}, Converter={StaticResource A_StringToUpper}}"
                                                                   Style="{StaticResource A_Style_FZTextBlock_RivalDetailsHeader}"
                                                                   HorizontalAlignment="Left"
                                                                   CapHeight="22"
                                                                   VerticalAlignment="Center" />
                                            </StackPanel>
                                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Panel_HorizontalDivider}"
                                                              Color="{StaticResource A_Color_ThinDivider}"/>
                                            <Decorator Height="170">
                                              <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_Description}"
                                                                     AnimationContext="{Binding Description}"
                                                                     Margin="28,24" />
                                            </Decorator>
                                        </StackPanel>
                                            <local:AutoScrollPanel Style="{StaticResource A_Style_AutoScrollPanel_Description}"
                                                                   AnimationContext="{Binding Description}"
                                                                   Margin="28,24"
                                                                   Visibility="{Binding Restrictions, FallbackValue=Visible, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden_Inverse}}"/>
                                        </Grid>
                                    </ContentControl>
                                </Grid>
                            </DockPanel>

                            <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                                  local:UIPageTransitionManager.TransitionIndex="1"
                                  KeyboardNavigation.DirectionalNavigation="Contained"
                                  Margin="0,6,0,0">
                                <local:WrapListBox x:Name="List"
                                                     Style="{StaticResource A_Style_Carousel_7Item}"
                                                     ItemTemplate="{StaticResource A_ControlTemplate_Control_RivalsItemContent}"
                                                     ItemsSource="{Binding Collection}"
                                                     local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                                     SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                                     Width="1763"/>
                            </Grid>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>
        </Border>

    </Grid>
</Page>
