<UserControl
    DataContext="{Binding (HUDData.Data), RelativeSource={RelativeSource Self}}" 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"
    mc:Ignorable="d"
    xmlns:local="clr-namespace:ForzaUI" 
    x:Class="ForzaUI.HUDRaceProgressControl"
    HorizontalAlignment="Left"
    VerticalAlignment="Top"
    x:Name="UserControl">

    <UserControl.Resources>
        <ResourceDictionary>
            <Thickness x:Key="A_Thickness_UnitsTextMargin">14,-0.5,0,0</Thickness>

            <Style x:Key="A_Style_FZTextBlock_HudVeryLarge_RaceProgress" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HUDBase}">
                <Setter Property="FontFamily" Value="Horizon_A_tf"/>
                <Setter Property="CapHeight" Value="55.5"/>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_HudMediumLarge_RaceProgress" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HudMediumLarge}">
                <Setter Property="FontFamily" Value="Horizon_A_tf"/>
            </Style>

            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_Circuit" TargetType="ContentControl">
                <StackPanel Orientation="Horizontal" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                    <local:FZTextBlock Text="{Binding CurrentLap}" Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_RaceProgress}" />
                    <local:FZTextBlock Text="/" Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_RaceProgress}" />
                    <local:FZTextBlock Text="{Binding NumLaps}" Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_RaceProgress}" />
                    <local:FZTextBlock Text="{Binding Units}" Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_RaceProgress}" Margin="{StaticResource A_Thickness_UnitsTextMargin}"/>
                </StackPanel>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_NonCircuit" TargetType="ContentControl">
                <StackPanel Orientation="Horizontal" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                    <local:FZTextBlock Text="{Binding Progress}"
                                       Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_RaceProgress}"/>
                    <local:FZTextBlock Text="{Binding Units}"
                                       Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_RaceProgress}"
                                       Margin="0,-0.5,0,0"/>
                </StackPanel>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_TimedEvent" TargetType="ContentControl">
                <StackPanel Orientation="Horizontal" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                    <local:FZTextBlock Text="{Binding Progress}"
                                       Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_RaceProgress}" 
                                       CapHeight="38"/>
                </StackPanel>
            </ControlTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_ContentControl_CustomScoring"
                             TargetType="ContentControl">
            </ControlTemplate>

            <Style x:Key="A_ContentControl_TemplateSelectionTriggers" TargetType="ContentControl">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RaceProgressType}" Value="{x:Static local:HUDRaceProgressType.Timed}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_TimedEvent}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RaceProgressType}" Value="{x:Static local:HUDRaceProgressType.Circuit}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_Circuit}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RaceProgressType}" Value="{x:Static local:HUDRaceProgressType.P2P}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_NonCircuit}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RaceProgressType}" Value="{x:Static local:HUDRaceProgressType.Rush}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_NonCircuit}"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding RaceProgressType}"
                                 Value="{x:Static local:HUDRaceProgressType.CustomScoring}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_CustomScoring}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_GlassProgressItem" TargetType="{x:Type FZMaterial}"
                BasedOn="{StaticResource A_Style_FZMaterial_GlassHudItem}">
                <Style.Resources>
                    <Color x:Key="A_Color_SplitGate_GoodSplit">#335CBC00</Color>
                    <Color x:Key="A_Color_SplitGate_BadSplit">#33FF1D25</Color>

                    <MappingConverter x:Key="A_Converter_ItemSplitGateState_to_Item_Color" Default="{StaticResource A_Color_HUD_ClearItemBackground}" CheckEnumKey="HUDRaceItemSplitGateState">
                        <MappingConverterEntry Key="{x:Static HUDRaceItemSplitGateState.None}" Value="{StaticResource A_Color_HUD_ClearItemBackground}"/>
                        <MappingConverterEntry Key="{x:Static HUDRaceItemSplitGateState.GoodSplit}" Value="{StaticResource A_Color_SplitGate_GoodSplit}"/>
                        <MappingConverterEntry Key="{x:Static HUDRaceItemSplitGateState.BadSplit}" Value="{StaticResource A_Color_HUD_ClearItemBackground}"/>
                    </MappingConverter>
                </Style.Resources>
                <Setter Property="Color" Value="{Binding RaceSplitGateState, Converter={StaticResource A_Converter_ItemSplitGateState_to_Item_Color}}"/>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_ListItemTemplate">
                <local:FZMaterial x:Name="ItemBorder" 
                                  Style="{StaticResource A_Style_FZMaterial_GlassProgressItem}" 
                                  Margin="0,0,0,2" 
                                  Width="{StaticResource A_Double_HUDProgressItem_Width}" 
                                  Height="32"
                                  Visibility="{Binding IsVisible, Converter={StaticResource A_Converter_BoolToVis}}">
                    <DockPanel Margin="7,0,8,0.5" LastChildFill="False" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5" ClipToBounds="True">
                        <FZTextBlock x:Name="Label" Text="{Binding Label}" Style="{StaticResource A_Style_FZTextBlock_HUDProgressItem_Label}" />
                        <FZTextBlock x:Name="Value" Text="{Binding Value}" Style="{StaticResource A_Style_FZTextBlock_HUDProgressItem_Value}" MaxWidth="106" DockPanel.Dock="Right" />
                        <FZMaterial Visibility="{Binding IsDirty, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}}"
                                    ImageSource="/ForzaUI;component/Textures/Anthem/Icons/Dirty_Lap_Small.png"
                                    Width="19" Height="16"
                                    Margin="0,0,5,0"
                                    VerticalAlignment="Center"
                                    DockPanel.Dock="Right" />
                    </DockPanel>
                </local:FZMaterial>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding HighlightValue}" Value="True">
                        <Setter TargetName="Value" Property="Color" Value="{StaticResource H_Color_Primary_Yellow}"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <MappingConverter x:Key="A_Converter_RaceProgressType_to_CustomItem_Margin" Default="0">
                <MappingConverterEntry Key="{x:Static HUDRaceProgressType.Rush}" Value="0,8,0,0"/>
            </MappingConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot">
        
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.0"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="PART_Hidden">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PART_LayoutRoot">
                          <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState Name="PART_Shown"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,1,0,11">
            <ContentControl Style="{StaticResource A_ContentControl_TemplateSelectionTriggers}"  Margin="-1,0,0,23"/>
            <local:CommonListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource A_DataTemplate_ListItemTemplate}" Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0" HorizontalAlignment="Left" Margin="1,0,0,0">
                <local:CommonListBox.Template>
                    <ControlTemplate TargetType="{x:Type local:CommonListBox}">
                        <StackPanel Orientation="Vertical" IsItemsHost="True"/>
                    </ControlTemplate>
                </local:CommonListBox.Template>
                <local:CommonListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <ContentPresenter/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:CommonListBox.ItemContainerStyle>
            </local:CommonListBox>
            <local:CommonListBox ItemsSource="{Binding CustomItems}" 
                                 ItemTemplate="{StaticResource A_DataTemplate_ListItemTemplate}" 
                                 Background="{x:Null}" 
                                 BorderBrush="{x:Null}" 
                                 BorderThickness="0" 
                                 HorizontalAlignment="Left"
                                 Margin="{Binding RaceProgressType, Converter={StaticResource A_Converter_RaceProgressType_to_CustomItem_Margin}}">
                <local:CommonListBox.Template>
                    <ControlTemplate TargetType="{x:Type local:CommonListBox}">
                        <StackPanel Orientation="Vertical" IsItemsHost="True"/>
                    </ControlTemplate>
                </local:CommonListBox.Template>
                <local:CommonListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <ContentPresenter/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:CommonListBox.ItemContainerStyle>
            </local:CommonListBox>
        </StackPanel>
    </Grid>
</UserControl>