<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"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:ForzaUI"
    mc:Ignorable="d"
    x:Class="ForzaUI.HUDPressButtonControl"
    Margin="0,0,0,14"
    VerticalAlignment="Bottom"
    HorizontalAlignment="Center"
    x:Name="UserControl">

    <UserControl.Resources>
        <ExponentialEase x:Key="A_EasingFunction_EaseIn" EasingMode="EaseIn"/>
        <CircleEase x:Key="A_EasingFunction_EaseOut" EasingMode="EaseOut"/>
        <CircleEase x:Key="A_EasingFunction_EaseInOut" EasingMode="EaseInOut"/>

        <Style x:Key="A_Style_FrameworkElement_CollapseIfControllerActive"
               TargetType="FrameworkElement">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_True}" >
                    <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type FrameworkElement}"
               x:Key="A_Style_FrameworkElement_PressButtonPromptFormat">
            <Setter Property="local:MultiStringFormatter.Param0" Value="{Binding LeftText}"/>
            <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding ScreenReaderName, ElementName=ButtonControl}"/>
            <Setter Property="local:MultiStringFormatter.Param2" Value="{Binding RightText}"/>
            <Setter Property="local:MultiStringFormatter.Format" Value="{local:Loc Main.IDS_ScreenReader_ButtonPrompt_Format}"/>
            <Setter Property="local:ScreenReader.LineType" Value="NotificationPrompt"/>
            <Setter Property="local:ScreenReader.Event" Value="OnChange"/>
            <Setter Property="local:ManualPassthroughProperty.Input" Value="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"/>
            <Setter Property="local:ManualPassthroughProperty.Allowed" Value="True"/>
            <Setter Property="local:ScreenReader.Line" Value="{Binding (local:ManualPassthroughProperty.Output), RelativeSource={RelativeSource Self}}"/>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_False}" />
                        <Condition Binding="{Binding IsKeyboardLinear, ElementName=ButtonControl}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="local:MultiStringFormatter.Param1" Value="{Binding ScreenReaderName, ElementName=ButtonControl_High}"/>
                </MultiDataTrigger>

                <DataTrigger Binding="{Binding LeftText}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param0" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding SilhouetteTexture}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param1" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding RightText}" Value="{x:Null}">
                    <Setter Property="local:MultiStringFormatter.Param2" Value="{local:Loc Main.IDS_ScreenReader_EmptyString}"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Opacity, ElementName=LayoutRoot}" Value="0">
                    <Setter Property="local:ManualPassthroughProperty.Allowed" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_FZTextBlock_PressButtonText" TargetType="{x:Type local:FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_HUDBase}">
            <Setter Property="CapHeight" Value="28" />
            <Setter Property="FontFamily" Value="Horizon_A" />
        </Style>

    </UserControl.Resources>

    <Grid x:Name="PART_LayoutRoot" ClipToBounds="True" Height="100">
        
        <VisualStateManager.VisualStateGroups>
            <UIVisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="PART_Hidden">
                    <UIStoryboard>
                        <UIStoryboard.TriggerAnimation>
                            <RaiseFzEvent TriggerAnimation.KeyTime="0:0:0.5"
                                          EventName="PART_HiddenComplete"/>
                        </UIStoryboard.TriggerAnimation>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PART_LayoutRoot">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.9"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="1"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.9"/>
                        </DoubleAnimationUsingKeyFrames>
                    </UIStoryboard>
                </VisualState>
                <VisualState x:Name="PART_Shown">
                    <UIStoryboard>
                        <UIStoryboard.TriggerAnimation>
                            <RaiseFzEvent EventName="Shine"
                                          TriggerAnimation.KeyTime="0:0:0.5"
                                          Storyboard.TargetName="ButtonControl"/>
                            <RaiseFzEvent EventName="Shine"
                                          TriggerAnimation.KeyTime="0:0:0.5"
                                          Storyboard.TargetName="ButtonControl_High"/>
                        </UIStoryboard.TriggerAnimation>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="DisplayPanel">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="-100"/>
                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" EasingFunction="{StaticResource A_EasingFunction_EaseOut}"/>
                        </DoubleAnimationUsingKeyFrames>
                    </UIStoryboard>
                </VisualState>
            </UIVisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid>
            <local:FZMaterial x:Name="BackgroundPill"
                              Style="{StaticResource A_Style_ControllerButton_Background}"
                              Preset="{StaticResource A_FZMaterialPresetRoundtangle_FlatPanel_OuterAll}"
                              Visibility="{StaticResource A_Visibility_ShowForHighContrastOnly}"
                              Margin="0,20,0,20" />
            <StackPanel x:Name="DisplayPanel" Orientation="Horizontal" RenderTransformOrigin="0.5,0.5" Margin="15,0,15,0">
                
                <StackPanel.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform />
                        <SkewTransform />
                        <RotateTransform />
                        <TranslateTransform />
                    </TransformGroup>
                </StackPanel.RenderTransform>

                <StackPanel x:Name="IconPanel"
                            Visibility="{Binding TopIconPath, Converter={StaticResource A_StringVisConverter}}">
                    <Grid>
                        <local:FZMaterial x:Name="TopIconBackground"
                              GetSizeFromTexture="True"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center"
                              ImageSource="{Binding TopIconBackgroundPath}"/>
                        <local:FZMaterial x:Name="TopIcon"
                                          GetSizeFromTexture="True"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          ImageSource="{Binding TopIconPath}"/>
                    </Grid>
                    <Decorator Height="20" />
                </StackPanel>

                
                <Decorator RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PressButtonText}" 
                                       Text="{Binding LeftText}" 
                                       VerticalAlignment="Center" 
                                       Color="{StaticResource A_Color_HUD_Text_NoBackground}"
                                       Visibility="{Binding LeftText, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                </Decorator>
                <Grid x:Name="ButtonIconContainer" Margin="10,0,10,0">
                    <local:ControllerButtonControl AllowMouseClick="False"
                                                   HideBackground="True"
                                                   UseLargeIcon="True"
                                                   Height="40"
                                                   Command="{Binding ActivateCommand}"
                                                   InputOverride="{Binding Input}"
                                                   RenderTransformOrigin="0.5,0.5"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Visibility="{Binding Input, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                                   x:Name="ButtonControl"
                                                   Opacity="1"/>
                </Grid>
                <Grid x:Name="ButtonIconContainer_LinearHigh" Style="{StaticResource A_Style_FrameworkElement_CollapseIfControllerActive}" Margin="2,0,0,0">
                    <local:ControllerButtonControl AllowMouseClick="False"
                                                   UseLargeIcon="True"
                                                   MinWidth="40"
                                                   Height="40"
                                                   Command="{Binding ActivateCommand}"
                                                   InputOverride="{Binding Input}"
                                                   RenderTransformOrigin="0.5,0.5"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Visibility="{Binding IsKeyboardLinear, ElementName=ButtonControl, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"
                                                   UseHighKeyIfLinearCommand="True"
                                                   x:Name="ButtonControl_High"/>
                </Grid>

                <Decorator RenderTransform="{StaticResource A_SkewTransform_HUD_Italics}" RenderTransformOrigin="0.5,0.5">
                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_PressButtonText}" 
                                       Text="{Binding RightText}" 
                                       VerticalAlignment="Center" 
                                       Color="{StaticResource A_Color_HUD_Text_NoBackground}"/>
                </Decorator>

                <FrameworkElement Style="{StaticResource A_Style_FrameworkElement_PressButtonPromptFormat}"/>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>