<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" 
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    x:Class="ForzaUI.HUDEliminatorProgressControl"
    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_InProgress" 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>


            <local:MappingConverter x:Key="A_Converter_EliminatorPhase_Active" Default="{StaticResource A_Boolean_True}">
                <local:MappingConverterEntry Key="{x:Static local:EliminatorPhase.Idle}" Value="{StaticResource A_Boolean_False}"/>
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_Converter_EliminatorPhase_Collapsed_No_New_Changes" Default="Visible">
                <local:MappingConverterEntry Key="{x:Static local:EliminatorPhase.Phase_4}" Value="Collapsed"/>
            </local:MappingConverter>

            <local:MappingConverter x:Key="A_Converter_EliminatorPhase_Collapsed_In_LastRace" Default="Visible">
                <local:MappingConverterEntry Key="{x:Static local:EliminatorPhase.Phase_4}" Value="Collapsed"/>
            </local:MappingConverter>

            <Style x:Key="A_ContentControl_TemplateSelectionTriggers" TargetType="ContentControl">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding EliminatorPhase, Converter={StaticResource A_Converter_EliminatorPhase_Active}}" Value="{StaticResource A_Boolean_True}">
                        <Setter Property="Template" Value="{StaticResource A_ControlTemplate_ContentControl_InProgress}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_GlassHudItem_Eliminator" TargetType="local:FZMaterial" BasedOn="{StaticResource A_Style_FZMaterial_GlassHudItem}">
                <Setter Property="Color" Value="{StaticResource A_Color_HUD_Glass_Eliminator}"/>
            </Style>
            <System:Double x:Key="A_Double_EliminatorItem_Width">258</System:Double>
            <DataTemplate x:Key="A_DataTemplate_ListItemTemplate">
                <local:FZMaterial x:Name="ItemBorder" Style="{StaticResource A_Style_FZMaterial_GlassHudItem_Eliminator}" Margin="0,0,0,2" Height="32" Width="{StaticResource A_Double_EliminatorItem_Width}">
                    <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="165" />
                        <local:FZTextBlock Text="{Binding Value}" Style="{StaticResource A_Style_FZTextBlock_HudMedium}" VerticalAlignment="Center" MaxWidth="106" DockPanel.Dock="Right" />
                    </DockPanel>
                </local:FZMaterial>
            </DataTemplate>

            <Style x:Key="A_Style_FZMaterial_HighlightHudItem_Eliminator" TargetType="local:FZMaterial" BasedOn="{StaticResource A_Style_FZMaterial_HighlightHudItem}">
                <Setter Property="Color" Value="{StaticResource A_Color_White}"/>
                <Setter Property="Preset">
                    <Setter.Value>
                        <local:FZMaterialPresetRoundtangle BasedOn="{StaticResource A_FZMaterialPresetRoundtangle_GradientHighlight_InnerAll}"
                                                           GradientColorA="{StaticResource A_Color_Eliminator_GradientA}"
                                                           GradientColorB="{StaticResource A_Color_Eliminator_GradientB}"/>
                    </Setter.Value>
                </Setter>
            </Style>

	    <System:Int32 x:Key="A_Int32_Zero">0</System:Int32>
            <local:MultiConverter x:Key="A_Converter_VisibleIfGreaterThanZero">
                <local:MultiConverterEntry Converter="{StaticResource A_CompareConverter}" Parameter="{StaticResource A_Int32_Zero}"/>
                <local:MultiConverterEntry Converter="{StaticResource A_Converter_VisibleIfGreaterThan}"/>
            </local:MultiConverter>
			
            <System:Int32 x:Key="A_Int32_Hundred">100</System:Int32>
            <System:Int32 x:Key="A_Int32_Ninty">90</System:Int32>
            <System:Int32 x:Key="A_Int32_SeventyFive">75</System:Int32>
            <System:Int32 x:Key="A_Int32_Fifty">50</System:Int32>
            <System:Int32 x:Key="A_Int32_TwentyFive">25</System:Int32>
            <System:Int32 x:Key="A_Int32_Ten">10</System:Int32>
            <System:Int32 x:Key="A_Int32_Five">5</System:Int32>

            <Style x:Key="A_Style_FrameworkElement_TimeoutScreenReader"
                   TargetType="FrameworkElement">
                <Setter Property="local:ScreenReader.LineType" Value="ItemState"/>
                <Setter Property="local:ScreenReader.Event" Value="OnChange"/>
                <Setter Property="local:ScreenReader.Line" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"/>
                <Setter Property="local:MultiStringFormatter.Format" Value="{local:Loc InGame.IDS_Eliminator_ScreenReader_PercentTimeRemaining}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.001}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_Hundred}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.1}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_Ninty}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.25}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_SeventyFive}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.5}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_Fifty}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.75}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_TwentyFive}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.9}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_Ten}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding TimeOut, Converter={StaticResource A_CompareConverter}, ConverterParameter=0.95}"
                                 Value="{x:Static local:CompareResult.GreaterThan}">
                        <Setter Property="local:MultiStringFormatter.Param0"
                                Value="{Binding Source={StaticResource A_Int32_Five}, Converter={StaticResource A_NumUnitConverter_Percent}}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <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_Timeout">
                <local:FZMaterial x:Name="Damage" Visibility="{Binding TimeOut, Converter={StaticResource A_Converter_VisibleIfGreaterThanZero}, FallbackValue=Collapsed}"
                              Style="{StaticResource A_Style_FZMaterial_HighlightHudItem_Eliminator}"
                              Width="{StaticResource A_Double_EliminatorItem_Width}"
                              Height="32"  HorizontalAlignment="Left">
                    <Grid Style="{StaticResource A_Style_FrameworkElement_TimeoutScreenReader}">
                        <Grid Margin="0,0,0,0" 
                            RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}"
                            RenderTransformOrigin="0.5,0.5">
                            <local:FZTextBlock HorizontalAlignment="Left" Text="{local:Loc InGame.IDS_Eliminator_Progress_TimeOut}" 
                                               Style="{StaticResource A_Style_FZTextBlock_HudMedium}" VerticalAlignment="Center" MaxWidth="80" 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 TimeOut, 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>

    <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}" 
                                 Visibility="{Binding EliminatorPhase, Converter={StaticResource A_Converter_EliminatorPhase_Collapsed_No_New_Changes}}"
                                 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 Visibility="{Binding Enabled, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:CommonListBox.ItemContainerStyle>
            </local:CommonListBox>

            <Control Template="{StaticResource A_ControlTemplate_Control_Timeout}" Visibility="{Binding EliminatorPhase, Converter={StaticResource A_Converter_EliminatorPhase_Collapsed_In_LastRace}}"/>
        </StackPanel>
    </Grid>
</UserControl>