<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    xmlns:local="clr-namespace:ForzaUI" 
    x:Class="ForzaUI.HUDChallengeControl"
    x:Name="UserControl"
    RenderTransformOrigin="0.5,0.5"
    Margin="0,0,0,0"
    HorizontalAlignment="Left"
    VerticalAlignment="Top">

    <UserControl.Resources>
        <ResourceDictionary>
            <System:Double x:Key="A_Double_HUDChallenge_RowHeight">32</System:Double>

            <Style x:Key="A_Style_FZTextBlock_HudMedium_BucketList" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HudMedium}">
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_IsTalking_Base"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Width" Value="32"/>
                <Setter Property="Height" Value="32"/>
                <Setter Property="Margin" Value="6,0,0,0"/>
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/HUD/LeaderboardIcons/Leaderboard_Icon_Mic.png"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_IsTalking_Local"
                BasedOn="{StaticResource A_Style_FZMaterial_IsTalking_Base}"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Visibility" Value="{Binding LocalPlayerIsTalking, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_IsTalking_Remote"
                BasedOn="{StaticResource A_Style_FZMaterial_IsTalking_Base}"
                TargetType="{x:Type local:FZMaterial}">
                <Setter Property="Visibility" Value="{Binding RemotePlayerIsTalking, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}"/>
            </Style>
            <Thickness x:Key="A_Thickness_BucketList_TextMargin">0,0,0,0</Thickness>
            <Thickness x:Key="A_Thickness_BucketList_ItemMargin_NonPlayer">-2,0,38,0</Thickness>
            <Thickness x:Key="A_Thickness_BucketList_ItemMargin_Player">-2,0,0,0</Thickness>

            <Thickness x:Key="A_Thickness_BucketList_ItemMargin_First">0,0,0,10</Thickness>
            <Thickness x:Key="A_Thickness_BucketList_ItemMargin">0,0,0,3</Thickness>

            <local:MappingConverter x:Key="A_MappingConverter_TimeRemaining_Visibility" Default="Visible">
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.Destination}" Value="{x:Static Visibility.Collapsed}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SurfaceDrive}" Value="{x:Static Visibility.Collapsed}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.HardcoreSprint}" Value="{x:Static Visibility.Collapsed}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.DamageControl}" Value="{x:Static Visibility.Collapsed}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MaintainMinSpeed}" Value="{x:Static Visibility.Collapsed}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MaintainSpeed}" Value="{x:Static Visibility.Collapsed}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_Current_Visibility" Default="Collapsed">
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.Destination}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillScore}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillMastery}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.Smashable}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillDrive}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.StuntDrive}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SurfaceDrive}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.HardcoreSprint}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiSpeedTrap}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiSpeedZone}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiDriftZone}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiDangerSign}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiSpeedTrapCount}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MultiSpeedZoneCount}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.DamageControl}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MaintainMinSpeed}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.MaintainSpeed}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_Current_Visibility_CreateFlow" Default="Collapsed">
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillScore}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillDrive}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.SkillMastery}" Value="{x:Static Visibility.Visible}" />
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.StuntDrive}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_MappingConverter_Damage_Visibility" Default="Collapsed">
                <local:MappingConverterEntry Key="{x:Static local:HUDChallengeType.DamageControl}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_Converter_HUDSceneToVisibility_Default" Default="Visible">
                <local:MappingConverterEntry Key="{x:Static local:SceneEntryEnum.BucketListChallengeCreationHud}" Value="{x:Static Visibility.Collapsed}" />
            </local:MappingConverter>
            
            <local:MappingConverter x:Key="A_Converter_HUDSceneToVisibility_CreateFlow" Default="Collapsed">
                <local:MappingConverterEntry Key="{x:Static local:SceneEntryEnum.BucketListChallengeCreationHud}" Value="{x:Static Visibility.Visible}" />
            </local:MappingConverter>

            <ControlTemplate x:Key="A_ControlTemplate_Control_TimeRemaining">
                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" 
                                  Margin="{StaticResource A_Thickness_BucketList_ItemMargin_First}"
                                  Height="{StaticResource A_Double_HUDChallenge_RowHeight}">
                    <Grid Margin="{StaticResource A_Thickness_BucketList_TextMargin}"
                        RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                        RenderTransformOrigin="0.5,0.5">
                        <local:FZTextBlock HorizontalAlignment="Left" Text="{Binding TimeRemaining.Label, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" MaxWidth="170" Margin="10,0,10,0"/>
                        <local:FZTextBlock HorizontalAlignment="Right" Text="{Binding TimeRemaining.FormattedValue, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" MaxWidth="170" Margin="10,0,10,0"/>
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

            <Double x:Key="A_Double_HudChallenge_PillWidth">312</Double>

            <ControlTemplate x:Key="A_ControlTemplate_Control_Target">
                <local:FZMaterial x:Name="Container"
                                  Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" 
                                  Margin="{StaticResource A_Thickness_BucketList_ItemMargin}"
                                  Height="{StaticResource A_Double_HUDChallenge_RowHeight}">
                    <Viewbox StretchDirection="DownOnly">
                        <Grid MinWidth="{StaticResource A_Double_HudChallenge_PillWidth}">
                            <DockPanel Margin="{StaticResource A_Thickness_BucketList_TextMargin}"
                                RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                                RenderTransformOrigin="0.5,0.5">
                                <local:FZTextBlock DockPanel.Dock="Left" HorizontalAlignment="Left" Text="{Binding Target.Label, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" Margin="10,0,10,0"/>
                                <local:FZTextBlock DockPanel.Dock="Right" x:Name="Value" HorizontalAlignment="Right" Text="{Binding Target.FormattedValue, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" Margin="10,0,10,0"/>
                            </DockPanel>
                        </Grid>
                    </Viewbox>
                </local:FZMaterial>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.Destination}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.SurfaceDrive}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.HardcoreSprint}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.DamageControl}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.MaintainMinSpeed}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.MaintainSpeed}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin_First}"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Control_Current">
                <local:FZMaterial x:Name="Container"
                                  Style="{StaticResource A_Style_FZMaterial_HighlightHudItem}"
                                  Height="{StaticResource A_Double_HUDChallenge_RowHeight}" >
                    <Grid Margin="{StaticResource A_Thickness_BucketList_TextMargin}"
                        RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                        RenderTransformOrigin="0.5,0.5">
                        <local:FZTextBlock HorizontalAlignment="Left" Text="{Binding Current.Label, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" Margin="10,0,10,0"/>
                        <local:FZTextBlock HorizontalAlignment="Right" Text="{Binding Current.FormattedValue, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" Margin="10,0,10,0"/>
                    </Grid>
                </local:FZMaterial>
                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding ChallengeType}" Value="{x:Static local:HUDChallengeType.DamageControl}">
                        <Setter TargetName="Container" Property="Margin" Value="{StaticResource A_Thickness_BucketList_ItemMargin}"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

            <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPresetRoundtangle_FlatPanel_DamageBar" BasedOn="{StaticResource A_FZMaterialPreset_FlatPanel_Base}" CornerRadius="2"/>
            <local:LinearTransformConverter x:Key="A_LinearTransformConverter_MaxBarWidth" Scale="156"/>
            <Color x:Key="A_Color_HUD_DamageBar_Background">#73000000</Color>
            <ControlTemplate x:Key="A_ControlTemplate_Control_Damage">
                <local:FZMaterial x:Name="Damage"
                              Style="{StaticResource A_Style_FZMaterial_HighlightHudItem}"
                              Height="{StaticResource A_Double_HUDChallenge_RowHeight}" >
                    <Grid>
                        <Grid Margin="{StaticResource A_Thickness_BucketList_TextMargin}" 
                            RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                            RenderTransformOrigin="0.5,0.5">
                            <local:FZTextBlock HorizontalAlignment="Left" Text="{Binding Damage.Label, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" MaxWidth="170" Margin="10,0,10,0"/>
                        </Grid>
                        <Grid HorizontalAlignment="Right" VerticalAlignment="Center" Width="156" Height="12" Margin="10,0,10,0">
                            <local:FZMaterial Color="{StaticResource A_Color_HUD_DamageBar_Background}" Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_DamageBar}"/>
                            <Grid HorizontalAlignment="Left" Width="{Binding Damage.Value, Converter={StaticResource A_LinearTransformConverter_MaxBarWidth}}" ClipToBounds="True">
                                <local:FZMaterial Color="{StaticResource A_Color_HUD_Text}" Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_DamageBar}" Width="156"/>
                            </Grid>
                        </Grid>
                    </Grid>
                </local:FZMaterial>
            </ControlTemplate>

        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel x:Name="LayoutRoot" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Right" Width="625">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LayoutRoot">
                            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(local:EventFire.EventName)" Storyboard.TargetName="EventFire">
                            <DiscreteStringKeyFrame KeyTime="0:0:0.5" Value="HiddenComplete"/>
                        </StringAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Show">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="LayoutRoot">
                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>


        <StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left">
            <StackPanel Visibility="{Binding ChallengeTitle, Converter={StaticResource A_StringVisConverter}}">
                <Decorator RenderTransformOrigin="0.5,0.5" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}">
                    <local:FZTextBlock Text="{Binding ChallengeTitle, Converter={StaticResource A_StringToUpper}}" Color="{StaticResource A_Color_HUD_AlternateText}" Style="{StaticResource A_Style_FZTextBlock_HudMedium_BucketList}" TextWrapping="Wrap"/>
                </Decorator>
                <local:FZMaterial Height="1" Margin="0,16"/>
            </StackPanel>

            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{StaticResource A_Double_HudChallenge_PillWidth}" Visibility="{Binding SceneEnum, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_HUDSceneToVisibility_Default}}">
                <Control Template="{StaticResource A_ControlTemplate_Control_TimeRemaining}" Visibility="{Binding ChallengeType, Converter={StaticResource A_MappingConverter_TimeRemaining_Visibility}}"/>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{StaticResource A_Double_HudChallenge_PillWidth}"
                    Visibility="{Binding ShowCurrentAndTarget, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                    <Control Template="{StaticResource A_ControlTemplate_Control_Target}"/>
                    <Control Template="{StaticResource A_ControlTemplate_Control_Current}" Visibility="{Binding ChallengeType, Converter={StaticResource A_MappingConverter_Current_Visibility}}"/>
                    <Control Template="{StaticResource A_ControlTemplate_Control_Damage}" Visibility="{Binding ChallengeType, Converter={StaticResource A_MappingConverter_Damage_Visibility}}"/>
                    <Decorator Height="10"/>
                </StackPanel>
                <Decorator Height="12"/>
            </StackPanel>

            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{StaticResource A_Double_HudChallenge_PillWidth}" Visibility="{Binding SceneEnum, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_Converter_HUDSceneToVisibility_CreateFlow}}">
                <Control Template="{StaticResource A_ControlTemplate_Control_TimeRemaining}" />
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{StaticResource A_Double_HudChallenge_PillWidth}"
                    Visibility="{Binding ShowCurrentAndTarget, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                    <Control Template="{StaticResource A_ControlTemplate_Control_Current}" Visibility="{Binding ChallengeType, Converter={StaticResource A_MappingConverter_Current_Visibility_CreateFlow}}"/>
                    <Control Template="{StaticResource A_ControlTemplate_Control_Damage}" Visibility="{Binding ChallengeType, Converter={StaticResource A_MappingConverter_Damage_Visibility}}"/>
                    <Decorator Height="10"/>
                </StackPanel>
                <Decorator Height="12"/>
            </StackPanel>

            <DockPanel Visibility="{Binding ChallengeObjective, Converter={StaticResource A_StringVisConverter}}" 
                 MaxWidth="{StaticResource A_Double_HudInstruction_MaxWidth}">
                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_HudInstruction_InfoIcon}"
                    DockPanel.Dock="Left"/>
                <StackPanel DockPanel.Dock="Left">
                    <Decorator Height="9"/>
                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HudInstruction}" 
                                       local:TextBlockInlineMarkup.ResourceBaseName=""
                                       local:TextBlockInlineMarkup.Markup="{Binding ChallengeObjective}"/>
                </StackPanel>
            </DockPanel>
            <local:EventFire x:Name="EventFire"/>
        </StackPanel>
    </StackPanel>
</UserControl>
