<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"
    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">15,-0.5,0,0</Thickness>

            <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_Tight}" />
                    <local:FZTextBlock Text="/" Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_Tight}" />
                    <local:FZTextBlock Text="{Binding NumLaps}" Style="{StaticResource A_Style_FZTextBlock_HudVeryLarge_Tight}" />
                    <local:FZTextBlock Text="{Binding Units}" Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_Tight}" 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_Tight}"/>
                    <local:FZTextBlock Text="{Binding Units}"
                                       Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_Tight}"
                                       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_HudVeryLarge_Tight}"/>
                    <local:FZTextBlock Text="{Binding Units}"
                                       Style="{StaticResource A_Style_FZTextBlock_HudMediumLarge_Tight}"
                                       Margin="15,-0.5,0,0"/>
                </StackPanel>
            </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>
                </Style.Triggers>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_ListItemTemplate">
                <local:FZMaterial x:Name="ItemBorder" Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" Margin="0,0,0,2" Width="229" Height="32">
                    <DockPanel Margin="8,0,8,0" LastChildFill="False" RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                        <local:FZTextBlock Text="{Binding Label}" Style="{StaticResource A_Style_FZTextBlock_HudMedium}" VerticalAlignment="Center" MaxWidth="105" />
                        <local:FZTextBlock Text="{Binding Value}" Style="{StaticResource A_Style_FZTextBlock_HudMedium}" VerticalAlignment="Center" MaxWidth="106" DockPanel.Dock="Right" />
                        <local: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>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.0"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LayoutRoot">
                          <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Shown"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,1,0,20">
        <ContentControl Style="{StaticResource A_ContentControl_TemplateSelectionTriggers}"  Margin="-1,0,0,20"/>
        <local:CommonListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource A_DataTemplate_ListItemTemplate}" Background="{x:Null}" BorderBrush="{x:Null}" BorderThickness="0" HorizontalAlignment="Left">
            <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>