<ResourceDictionary 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:local="clr-namespace:ForzaUI;assembly=">

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

    <Style x:Key="A_Style_FZMaterial_RivalDirtyIconSmall" TargetType="local:FZMaterial">
        <Setter Property="Visibility" Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
        <Setter Property="ImageSourceNoPreload" Value="/ForzaUI;component/Textures/Anthem/Icons/RivalsLeaderboard/Dirty_Lap.png" />
        <Setter Property="Margin" Value="5,0,0,0"/>
        <Setter Property="Width" Value="22"/>
        <Setter Property="Height" Value="22"/>
    </Style>
    
    <Style x:Key="A_Style_FZTextBlock_RivalInfoLabel" BasedOn="{StaticResource A_Style_FZTextBlock_Heading_Small_Tight}" TargetType="local:FZTextBlock">
        <Setter Property="Color" Value="{StaticResource A_Color_ScreenTitle_Text}"/>
        <Setter Property="TextWrapping" Value="NoWrap"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="FontSize" Value="24"/>
    </Style>

    <Style x:Key="A_Style_FZTextBlock_RivalInfoValue" BasedOn="{StaticResource A_Style_FZTextBlock_HorizonB}" TargetType="local:FZTextBlock">
        <Setter Property="Color" Value="{StaticResource A_Color_ScreenTitle_Text}"/>
        <Setter Property="TextWrapping" Value="NoWrap"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="FontSize" Value="55"/>
        <Setter Property="Margin" Value="0"/>
    </Style>
    
    <Style x:Key="A_Style_Control_RivalInfoDivider" TargetType="Control">
        <Setter Property="Visibility" Value="Hidden"/>
        <Setter Property="Height" Value="32"/>
    </Style>
    
    <Style x:Key="A_Style_FZTextBlock_RivalsRouteName" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HorizonA}">
        <Setter Property="Color" Value="#ffffffff"/>
        <Setter Property="CapHeight" Value="53"/>
        <Setter Property="Stretch" Value="None"/>
    </Style>

    <Style x:Key="A_Style_FZTextBlock_RivalsRouteSubName" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_RivalsRouteName}">
        <Setter Property="CapHeight" Value="18"/>
    </Style>
    
    <Style x:Key="A_Style_FZTextBlock_RivalsRouteDescription" BasedOn="{StaticResource A_Style_FZTextBlock_RivalInfoValue}" TargetType="local:FZTextBlock">
        <Setter Property="FontSize" Value="36"/>
    </Style>
    
    <Style x:Key="A_Style_FZTextBlock_RivalsRouteDistanceSmall" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_RivalInfoLabel}">
        <Setter Property="Color" Value="{StaticResource A_Color_Body_Text}"/>
        <Setter Property="CapHeight" Value="15"/>
    </Style>

    <Style x:Key="A_Style_FZTextBlock_RivalsRouteDistanceLarge" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_RivalInfoLabel}">
        <Setter Property="CapHeight" Value="17"/>
        <Setter Property="Color" Value="{StaticResource A_Color_Body_Text}"/>
    </Style>

    <local:NumUnitConverter x:Key="A_NumUnitConverter_RivalsDistance" FractionDigits="1" ShowUnit="true" PositiveSign="False" />

    <local:FZMaterialPresetRoundtangleStroke x:Key="A_FZMaterialPresetRoundtangleStroke_MapBorder"
        CornerRadius="{StaticResource A_CornerRadius_Inner_All}"
        Thickness="1"/>

    <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_FlatPanel_RivalsDistanceGap"
        BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}"
        CornerRadius="8,0,0,0"/>

    <DataTemplate x:Key="A_ControlTemplate_Control_RivalsItemContent">
        <Grid>
        <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                          Color="#ff404040"
                              Margin="-0.5"
                              Visibility="{Binding SingleRoute, FallbackValue=Visible, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
            <Grid Margin="7">
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangleStroke_MapBorder}"
                                  Color="#ffb4b4b4">
                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/Rivals/CarouselGrid.png"/>
                </local:FZMaterial>

                <!-- This is used to blank out the grid near the route length status box, but the map route should draw on top of it -->
                <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_RivalsDistanceGap}"
                                  Color="#ff404040"
                                  VerticalAlignment="Bottom"
                                  HorizontalAlignment="Right"
                                  Margin="0,0,-0.5,-0.5"
                                  Width="{Binding ActualWidth, ElementName=LengthStatus}"
                                  Height="{Binding ActualHeight, ElementName=LengthStatus}" />
                <local:MapViewControllerWindowed x:Name="ThumbnailMapView"
                                                 DataContext="{Binding ThumbnailMapData}"
                                                 Style="{StaticResource A_Style_MapViewController_UIMap}"
                                                 DesiredMargin="15,15,15,20"
                                                 MinimumMargin="15,15,15,20"
                                                     MinMapHeight="1000"
                                                     InterpolationTime="0" />
                <local:MapCustomRenderElement Style="{StaticResource A_Style_MapCustomRenderElement_UIMap}" DataContext="{Binding ThumbnailMapData}" Width="233" Height="138"
                                              MapView="{Binding ElementName=ThumbnailMapView}" />
                <Grid VerticalAlignment="Bottom"
                      HorizontalAlignment="Right"
                      Margin="0,0,-0.5,-0.5" 
                      x:Name="LengthStatus">
                    <local:FZMaterial Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                      Margin="6,6,0.5,0.5"
                                      Color="{StaticResource A_Color_ItemStatusBackground}">
                        <local:FZTextBlock Text="{Binding ThumbnailMapData.Distance}"
                                           Style="{StaticResource A_Style_FZTextBlock_RivalsRouteDistanceSmall}"
                                           Margin="8" />
                    </local:FZMaterial>
                </Grid>

            </Grid>
        </local:FZMaterial>

            <!-- Class-based display -->
            <local:FZMaterial Visibility="{Binding SingleRoute, FallbackValue=Collapsed, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                              Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                              ImageSource="{Binding Thumbnail}"
                              Margin="-0.5"
                              Color="#fff">
                <local:FZTextBlock Text="{local:Loc Rivals.IDS_DesignSpecial}"
                                   Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                   Color="{StaticResource A_Color_Tile_Text}"
                                   Margin="27"
                                   CapHeight="15"
                                   TextAlignment="Center"
                                   VerticalAlignment="Bottom"
                                   Visibility="{Binding SingleRouteDesignSpecial, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
            </local:FZMaterial>
        </Grid>
    </DataTemplate>

    <ControlTemplate x:Key="A_ControlTemplate_RivalInfo"
           TargetType="Control">

        <Grid DataContext="{Binding RivalInfo}">
            <StackPanel x:Name="InfoPanel" VerticalAlignment="Top">
                <Grid>
                    <local:FZTextBlock Text="{Binding UserProfile.FormattedGamertag}" Stretch="Uniform" StretchDirection="DownOnly" VerticalAlignment="Center"
                                       Style="{StaticResource A_Style_FZTextBlock_RivalInfoValue}" />
                    <local:FZTextBlock Text="Placeholder" Stretch="Uniform" StretchDirection="DownOnly" Visibility="Hidden" VerticalAlignment="Center"
                                       Style="{StaticResource A_Style_FZTextBlock_RivalInfoValue}" />
                </Grid>

                <Control Style="{StaticResource A_Style_Control_RivalInfoDivider}"/>

                <local:FZTextBlock Text="{local:Loc Rivals.IDS_TimeToBeat}"
                                   Style="{StaticResource A_Style_FZTextBlock_RivalInfoLabel}" />

                <StackPanel Orientation="Horizontal">
                    <local:FZTextBlock Text="{Binding TimeToBeat}"
                                       Style="{StaticResource A_Style_FZTextBlock_RivalInfoValue}" />
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RivalDirtyIcon}" Tag="{Binding TimeToBeatIsDirty}"/>
                </StackPanel>

                <Control Style="{StaticResource A_Style_Control_RivalInfoDivider}"/>

                <local:FZTextBlock Text="{local:Loc Rivals.IDS_GapToRival}"
                                   Style="{StaticResource A_Style_FZTextBlock_RivalInfoLabel}" />
                
                <local:FZTextBlock Text="{Binding TimeDifference}"
                                   Style="{StaticResource A_Style_FZTextBlock_RivalInfoValue}" />

                <Control Style="{StaticResource A_Style_Control_RivalInfoDivider}"/>

                <local:FZTextBlock Text="{local:Loc Rivals.IDS_Rewards}"
                                   Style="{StaticResource A_Style_FZTextBlock_RivalInfoLabel}" />
                
                <DockPanel Height="64" >
                    <local:FZMaterial x:Name="Credits_Material_1"
                                      Color="{StaticResource A_Color_CreditTokenCost}"
                                      ImageSource="/ForzaUI;component/Textures/Anthem/Icons/CRIcon/CR_64.png"
                                      Width="64" DockPanel.Dock="Left" />
                    <local:FZMaterial x:Name="Credits_Material_2" Color="{StaticResource A_Color_CreditTokenCost}" Margin="0,0,0,0" Height="2" DockPanel.Dock="Top" />
                    <local:FZMaterial x:Name="Credits_Material_3" Color="{StaticResource A_Color_CreditTokenCost}" Margin="0,0,0,0" Height="2" DockPanel.Dock="Bottom" />
                    <local:FZMaterial x:Name="Credits_Material_4" Color="{StaticResource A_Color_CreditTokenCost}" Margin="0,0,0,0" Width="2" DockPanel.Dock="Right" />
                    <local:FZTextBlock Style="{StaticResource A_Style_TextBlock_CarSelect_Cost}" Text="{Binding Reward}" DockPanel.Dock="Right" FontSize="48" Stretch="UniformToFill"/>
                </DockPanel>
            </StackPanel>
            <ProgressBar x:Name="WaitSpinner"
                         IsIndeterminate="True"
                         Style="{StaticResource A_Style_ProgressBar_WaitSpinner}"
                         Height="56"
                         Visibility="Hidden"/>
        </Grid>

        <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding ItemsSource, ElementName=List}" Value="{x:Null}">
                <Setter TargetName="WaitSpinner" Property="Visibility" Value="Visible"/>
                <Setter TargetName="InfoPanel" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ItemsSource.Count, ElementName=List}" Value="0">
                <Setter TargetName="InfoPanel" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RivalInfo.UserProfile.FormattedGamertag, Converter={StaticResource A_StringVisConverter}}" Value="0">
                <Setter TargetName="WaitSpinner" Property="Visibility" Value="Visible"/>
                <Setter TargetName="InfoPanel" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ItemsPanelTemplate x:Key="A_Template_RaceIconStackPanel">
        <StackPanel IsItemsHost="True" Orientation="Horizontal" Margin="0,0,0,-20"/>
    </ItemsPanelTemplate>

    <DataTemplate x:Key="A_Template_RaceIconImage">
        <local:FZMaterial ImageSource="{Binding}" Color="#969696" Width="84" Height="84" Margin="-5,20,-5,0"/>
    </DataTemplate>

    <ControlTemplate x:Key="A_ControlTemplate_RivalsDestinationTile"
                             TargetType="{x:Type local:FZButton}">
        <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
              local:UIPageTransitionManager.TransitionIndex="{Binding (local:UIPageTransitionManager.TransitionIndex), RelativeSource={RelativeSource TemplatedParent}}">
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TileShadow}" />
            <Grid>
                <Grid>
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TileBackground_NoAlternate}"
                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                                      Visibility="{Binding UseAlternateColors, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                        <StackPanel VerticalAlignment="Bottom">
                            <Decorator VerticalAlignment="Bottom" HorizontalAlignment="Center">
                                <ItemsControl ItemsSource="{Binding Icons}" 
                                              ItemsPanel="{StaticResource A_Template_RaceIconStackPanel}"
                                              ItemTemplate="{StaticResource A_Template_RaceIconImage}"/>
                            </Decorator>
                            <Decorator VerticalAlignment="Bottom"
                                Height="{StaticResource A_Double_Size_Tile_TitlePanel}">
                                <UniformGrid Margin="{StaticResource A_Thickness_TilePadding}" Rows="2" RenderTransformOrigin="0.5,0.5">
                                    <UniformGrid.RenderTransform>
                                        <TranslateTransform Y="0"/>
                                    </UniformGrid.RenderTransform>
                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TileTitle}"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Top"
                                        Grid.Row="0"
                                        Text="{Binding Title, Converter={StaticResource A_StringToUpper}}"/>
                                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_TileText_ImageTile}"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Bottom"
                                        Grid.Row="1"
                                        local:TextBlockInlineMarkup.Markup="{Binding Subtitle}"/>
                                </UniformGrid>
                            </Decorator>
                        </StackPanel>
                    </local:FZMaterial>
                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_LockableImageTileBackground}"
                                      Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerAll}"
                                      ImageSource="{Binding Image}" Margin="3" VerticalAlignment="Top"
                                      Height="505"/>
                </Grid>
                <ContentControl Style="{StaticResource A_Style_ContentControl_TileSelectionStroke}" />
                <ContentControl Content="{Binding (local:BindingProxy.A), RelativeSource={RelativeSource TemplatedParent}}"
                                Style="{StaticResource A_Style_ContentControl_NotificationBadge_ImageTile}" />
            </Grid>
        </Grid>
    </ControlTemplate>
    
    <Style x:Key="A_Style_FrameworkElement_MapPanelNoDataContextWhenNotShown"
        TargetType="FrameworkElement">
        <Setter Property="DataContext"
            Value="{Binding SelectedItem, ElementName=List}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding Visibility, ElementName=UnloadedTrackImage}"
                            Value="{x:Static Visibility.Visible}">
                <Setter Property="DataContext"
                        Value="{Binding FallbackItem, RelativeSource={RelativeSource AncestorType=Page}}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>