<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      x:Class="ForzaUI.A_CarMeetsHud"
      x:Name="Page"
      WindowTitle="Page"
      FlowDirection="LeftToRight"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}}">
    <Page.Resources>

        <System:Double x:Key="A_Double_PrestigeIcon_Width">40</System:Double>
        <System:Double x:Key="A_Double_PrestigeIcon_Height">30</System:Double>

        <local:MappingConverter x:Key="A_Converter_HudStateToPanelVisibility" Default="Visible">
            <local:MappingConverterEntry Key="{x:Static local:CarMeetsHudStateEnum.InViewCar}" Value="Collapsed"/>
            <local:MappingConverterEntry Key="{x:Static local:CarMeetsHudStateEnum.None}" Value="Collapsed"/>
        </local:MappingConverter>
        <local:MappingConverter x:Key="A_Converter_HudStateToPanelVisibility_ViewCarExclusive" Default="Collapsed">
            <local:MappingConverterEntry Key="{x:Static local:CarMeetsHudStateEnum.InViewCar}" Value="Visible"/>
        </local:MappingConverter>

        <Style x:Key="A_Style_FZMaterial_Panel_Background"
           TargetType="local:FZMaterial">
            <Setter Property="Color" Value="{StaticResource H_Color_Glass_Purple_20pc}" />
            <Setter Property="Preset" Value="{GlassRoundtangle BlurAmount=Medium}" />
        </Style>

        <Style x:Key="A_Style_FZMaterial_SubPanel_Background"
               BasedOn="{StaticResource A_Style_FZMaterial_Panel_Background}"
               TargetType="local:FZMaterial">
            <Setter Property="Color" Value="{StaticResource H_Color_Glass_Purple_60pc}" />
            <Setter Property="Height" Value="36" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
        </Style>

        <Style x:Key="A_Style_FZMaterial_CarMeet_Owner"
           TargetType="local:FZMaterial">
            <Setter Property="ImageSource"
                Value="{Binding Owner, Converter={StaticResource A_GamerPicConverter}, ConverterParameter={StaticResource A_Size_Auction_GamerPicSizeParams}}" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Owner}"
                         Value="{x:Null}">
                    <Setter Property="ImageSource"
                        Value="/ForzaUI;component/Textures/Anthem/NoGamerpic.png" />
                    <Setter Property="Color"
                        Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_Control_CarMeet_Owner"
           TargetType="Control">
            <Style.Resources>
                <Style x:Key="A_Style_ProgressBar_WaitSpinner_Dynamic"
                TargetType="{x:Type ProgressBar}"
                BasedOn="{StaticResource A_Style_ProgressBar_WaitSpinner}"/>
            </Style.Resources>
            <Setter Property="Template" Value="{DynamicResource A_Template_Control_CarMeet_Owner}"/>
        </Style>

        <ControlTemplate TargetType="Control"
                     x:Key="A_Template_Control_CarMeet_Owner">
            <StackPanel Height="84" Orientation="Horizontal">
                <Grid Width="84">
                    <local:FZMaterial x:Name="OwnerGamerPicMaterial"
                                  Style="{StaticResource A_Style_FZMaterial_CarMeet_Owner}"
                                  Height="84"
                                  Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_InnerInnerAll}"
                                  Stretch="Uniform"
                                  Tag="{Binding Path=(local:BindingProxy.B), RelativeSource={RelativeSource TemplatedParent}}"
                                  Visibility="{Binding Downloaded, RelativeSource={RelativeSource Self}, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}" />
                    <ProgressBar Style="{DynamicResource A_Style_ProgressBar_WaitSpinner_Dynamic}"
                             HorizontalAlignment="Center"
                             VerticalAlignment="Center"
                             Visibility="{Binding Downloaded, ElementName=OwnerGamerPicMaterial, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}"/>
                </Grid>

                <StackPanel Orientation="Vertical" Margin="12,7,0,0">

                    <Control DataContext="{Binding Owner}" x:Name="Player_Level" Template="{StaticResource A_ControlTemplate_PlayerLevel_WithPrestige}" Margin="3"/>

                    <Decorator Height="12"/>
                    <StackPanel Orientation="Horizontal">
                        <local:FZTextBlock Text="{Binding Owner.FormattedClubTag}"
                                       HorizontalAlignment="Left"
                                       FontFamily="Horizon_A"
                                       x:Name="OwnerClubTagName"
                                       CapHeight="21"
                                       VerticalAlignment="Center"
                                       Color="{TemplateBinding local:BindingProxy.A}"
                                       Visibility="{Binding Owner.FormattedClubTag, Converter={StaticResource A_StringVisConverter}}"/>
                        <local:FZTextBlock Text="{Binding Owner.FormattedGamertag}"
                                       x:Name="OwnerName"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Bottom"
                                       FontFamily="Horizon_A"
                                       CapHeight="21"
                                       Stretch="Uniform"
                                       Color="{TemplateBinding local:BindingProxy.A}"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding Owner.FormattedClubTag, Converter={StaticResource A_StringVisConverter}}" Value="{x:Static Visibility.Visible}">
                    <Setter TargetName="OwnerName" Property="Margin" Value="5,0,0,0"/>
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style TargetType="local:FZTextBlock"
               x:Key="A_Style_FZTextBlock_CarMeet_CarDetail">
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="LineAdjust" Value="-0.35" />
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="StretchDirection" Value="DownOnly" />
            <Setter Property="CapHeight" Value="25" />
            <Setter Property="Color" Value="{StaticResource A_Color_AuctionHouse_PillDetailText}" />
            <Setter Property="TextAlignment" Value="Left" />
            <Setter Property="TextTrimming" Value="None" />
            <Setter Property="ClipToBounds" Value="False"/>
            <Setter Property="Stretch" Value="None"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="AutoScroll" Value="{StaticResource A_AutoScrollSettings_CarName}"/>
            <Setter Property="AutoScroll.AllowScrolling" Value="True"/>
        </Style>

    </Page.Resources>
    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Hud}" />
    </local:UIPageTransitionManager.TransitionManager>

    <Grid x:Name="PART_LayoutRoot">
        <Grid Style="{StaticResource A_Style_FrameworkElement_FadeOnlyTransition_0}">
            <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                            x:Name="BottomBar">
                <local:ControllerButtonPanel x:Name="PART_HelpPanel"
                                             Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                    <local:ControllerButtonControl Button="A" />
                    <local:ControllerButtonControl Button="B" />
                    <local:ControllerButtonControl Button="LThumb_LeftRight"
                                                   Description="{local:Loc HelpButtons.IDS_NavigateCars}"
                                                   Visibility="{Binding IsControllerNavigateActive, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}" />

                    <local:ControllerButtonControl x:Name="LeftArrow"
                                                   Button="DPadLeft"
                                                   Description="{local:Loc HelpButtons.IDS_NavigateCarsLeft}"
                                                   Visibility="{Binding IsKeyboardNavigateActive, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}" />

                    <local:ControllerButtonControl x:Name="RightArrow"
                                                   Button="DPadRight"
                                                   Description="{local:Loc HelpButtons.IDS_NavigateCarsRight}"
                                                   Visibility="{Binding IsKeyboardNavigateActive, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}" />
                    <local:ControllerButtonControl x:Name="CarMeetsThrottle"
                                                   InputOverride="{local:Input Command=INPUTCMD_CAR_MEETS_THROTTLE, Context=INPUTCONTEXT_CAR_MEETS}"
                                                   Description="{local:Loc HelpButtons.IDS_RevEngine}">
                        <local:ControllerButtonControl.Style>
                            <Style TargetType="{x:Type local:ControllerButtonControl}"
                                BasedOn="{StaticResource A_Style_ControllerButtonControl_Default}">
                                <Setter Property="Visibility" Value="Visible"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsCurrentCarElectric}" Value="True">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding IsPlayerCar}" Value="False">
                                        <Setter Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </local:ControllerButtonControl.Style>
                    </local:ControllerButtonControl>
                    <local:ControllerButtonControl x:Name="PhotoModeButton"
                                                   InputOverride="{local:Input Command=INPUTCMD_CAR_MEETS_PHOTO, Context=INPUTCONTEXT_CAR_MEETS}"
                                                   Visibility="{Binding CarMeetsState, Converter={StaticResource A_Converter_HudStateToPanelVisibility}}"
                                                   Description="{local:Loc HelpButtons.IDS_PhotoMode_Picture}"
                                                   Command="{Binding PhotoModeCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
                    <local:ControllerButtonControl x:Name="CinematicCamButton"
                                                   InputOverride="{local:Input Command=INPUTCMD_CAR_MEETS_CINEMATIC_CAM, Context=INPUTCONTEXT_CAR_MEETS}"
                                                   Description="{local:Loc HelpButtons.IDS_CinematicCamera}"
                                                   Command="{Binding CinematicCameraCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
                    <local:ControllerButtonControl x:Name="HideUIButton"
                                                   InputOverride="{local:Input Command=INPUTCMD_CAR_MEETS_HIDE_UI, Context=INPUTCONTEXT_CAR_MEETS}"
                                                   Description="{local:Loc HelpButtons.IDS_HideShowUI}"
                                                   Command="{Binding HideUICommand, RelativeSource={RelativeSource AncestorType=Page}}" />
                    <local:ControllerButtonControl x:Name="ResetDamageButton"
                                                   InputOverride="{local:Input Command=INPUTCMD_CAR_MEETS_RESET_DAMAGE, Context=INPUTCONTEXT_CAR_MEETS}"
                                                   Description="{local:Loc HelpButtons.IDS_PhotoMode_ResetDamage}"
                                                   Command="{Binding ResetDamageCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
                    <local:ControllerButtonControl x:Name="ToggleCamHeight"
                                                   Button="L3"
                                                   Visibility="{Binding CarMeetsState, Converter={StaticResource A_Converter_HudStateToPanelVisibility_ViewCarExclusive}}"
                                                   Description="{local:Loc HelpButtons.IDS_Toggle_CameraHeight}"
                                                   Command="{Binding ToggleCameraHeightCommand, RelativeSource={RelativeSource AncestorType=Page}}"/>

                </local:ControllerButtonPanel>
            </ContentControl>

            <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
                <Grid x:Name="AdjustableSafeFrame"
                      Margin="{Binding SafeFrameMargin}">

                    <StackPanel Width="380" HorizontalAlignment="Left"
                                Visibility="{Binding CarMeetsState, Converter={StaticResource A_Converter_HudStateToPanelVisibility}}">
                        <ContentControl Content="{Binding Title}"
                                        Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"/>

                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Panel_Background}">
                            <StackPanel>
                                <Control HorizontalAlignment="Left"
                                         Style="{StaticResource A_Style_Control_CarMeet_Owner}"
                                         local:BindingProxy.A="{StaticResource H_Color_Primary_White}"
                                         local:BindingProxy.B="{StaticResource H_Color_Primary_Grey_70pc}"
                                         Margin="20"/>

                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_SubPanel_Background}">
                                    <local:ControllerButtonControl Button="X"
                                                                   Description="{local:Loc HelpButtons.IDS_PlayerMenu}"
                                                                   HideBackground="true"
                                                                   Margin="20,0"
                                                                   HorizontalAlignment="Left"/>
                                </local:FZMaterial>

                                <!-- Car info -->
                                <StackPanel HorizontalAlignment="Left"
                                            Orientation="Vertical"
                                            VerticalAlignment="Top"
                                            Margin="20">
                                    <local:FZTextBlock Color="{StaticResource A_Color_SubHeader_Text}"
                                                       CapHeight="25"
                                                       HorizontalAlignment="Stretch"
                                                       LineAdjust="-0.35"
                                                       Style="{StaticResource A_Style_FZTextBlock_CarMeet_CarDetail}"
                                                       FontFamily="Horizon_A"
                                                       Text="{Binding CarModel, Converter={StaticResource A_StringToUpper}}" 
                                                       AutoScroll.AllowScrolling="True"
                                                       TextTrimming="None"/>
                                    <Decorator Height="11" />
                                    <local:FZTextBlock Color="{StaticResource H_Color_Primary_White}"
                                                       FontFamily="Horizon_B"
                                                       CapHeight="23"
                                                       Style="{StaticResource A_Style_FZTextBlock_CarMeet_CarDetail}"
                                                       VerticalAlignment="Center">
                                        <local:FZRun Text="{Binding CarYear}"
                                                     FontFamily="Horizon_B"/>
                                        <local:FZRun Text=" " />
                                        <local:FZRun Text="{Binding CarManufacturer, Converter={StaticResource A_StringToUpper}}"/>
                                    </local:FZTextBlock>
                                </StackPanel>

                                <!--Rarity, PI and Class-->
                                <StackPanel HorizontalAlignment="Left"
                                            VerticalAlignment="Bottom"
                                            Orientation="Horizontal"
                                            Margin="20,0,20,20">
                                    <Control Style="{StaticResource A_Style_Control_AuctionHouse_RarityPillWithHEBonus}"
                                             HorizontalAlignment="Left"/>

                                    <Control Margin="10,0,0,0" Height="35"
                                             Width="95"
                                             Style="{StaticResource A_Style_Control_CarClassBadge_Small}"
                                             local:BindingProxy.A="{Binding CarPerformanceRating}"
                                             local:BindingProxy.B="{Binding CarClass}"/>
                                </StackPanel>

                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_SubPanel_Background}"
                                                  Visibility="{Binding IsPlayerCar, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                                    <local:ControllerButtonControl Button="Y"
                                                                   Description="{local:Loc HelpButtons.IDS_CarMenu}"
                                                                   HideBackground="true"
                                                                   Margin="20,0"
                                                                   HorizontalAlignment="Left"
                                                                   />
                                </local:FZMaterial>

                            </StackPanel>
                        </local:FZMaterial>
                    </StackPanel>

                    <!--LINK Container-->
                    <Decorator HorizontalAlignment="Left"
                               VerticalAlignment="Bottom"
                               Margin="0,0,0,83"
                               Visibility="{Binding CarMeetsState, Converter={StaticResource A_Converter_HudStateToPanelVisibility}}">
                        <local:HUDAnnaControl HUDData.Type="HUDStatusAnna"
                                              CanShowDestination="False"/>
                    </Decorator>
                    <local:HUDWaitSpinnerControl HUDData.Type="HUDStatusWaitSpinner"
                                                 HorizontalAlignment="Right"
                                                 VerticalAlignment="Bottom"/>

                    <!--Convoy-->
                    <local:HUDMiniLeaderboardControl HUDData.Type="HUDStatusMiniLeaderboard"
                                                     Visibility="{Binding CarMeetsState, Converter={StaticResource A_Converter_HudStateToPanelVisibility}}"/>

                    <!-- Notifications and Transient Controls -->
                    <StackPanel VerticalAlignment="Bottom">
                        <local:HUDMinorNotificationControl HUDData.Type="HUDStatusMinorNotification" />
                        <Decorator Style="{StaticResource A_Style_FrameworkElement_SubtitlesSpaceMaker}" />
                    </StackPanel>
                    
                    <local:HUDRadioControl HUDData.Type="HUDStatusRadio" Margin="0,0,0,320" />

                    <!-- Network Controls -->
                    <local:HUDNetworkStatusControl HUDData.Type="HUDStatusNetworkStatus" />
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</Page>
