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

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

            <Style x:Key="A_Style_FZMaterial_RoundtangleStroke_ActivityPanel_Outline_HUD"
                   TargetType="{x:Type local:FZMaterial}"
                   BasedOn="{StaticResource A_Style_FZMaterial_RoundtangleStroke_ActivityPanel_Outline}">
                <Setter Property="Color" Value="{StaticResource A_Color_GlassPanel_Interactive}"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_GlassPanel_ActivityPanel_HUD"
                   TargetType="{x:Type local:FZMaterial}"
                   BasedOn="{StaticResource A_Style_FZMaterial_GlassPanel_ActivityPanel}">
                <Setter Property="Color" Value="{StaticResource A_Color_GlassPanel_Untinted}"/>
            </Style>

            <local:FZMaterialPresetRoundtangle x:Key="A_FZMaterialPreset_BreadCrumb_AlphaAdditive" BasedOn="{StaticResource A_FZMaterialPreset_BreadCrumb}" AlphaMode="Additive"/>

            <System:Double x:Key="A_Double_Activity_DefaultScale">1.0</System:Double>
            <System:Double x:Key="A_Double_Activity_PulseScale">1.06</System:Double>

            <DoubleAnimationUsingKeyFrames x:Key="A_AnimationUsingKeyFrames_ScaleX_Pulse"
                                            Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" Storyboard.TargetName="{x:Null}">
                <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.53" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.66" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.79" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.92" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                
                <DiscreteDoubleKeyFrame KeyTime="0:0:1.0" Value="{StaticResource A_Double_Activity_DefaultScale}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.4" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.53" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.66" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.79" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.92" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames x:Key="A_AnimationUsingKeyFrames_ScaleY_Pulse"
                                            Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" Storyboard.TargetName="{x:Null}">
                <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.53" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.66" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.79" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.92" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>

                <DiscreteDoubleKeyFrame KeyTime="0:0:1.0" Value="{StaticResource A_Double_Activity_DefaultScale}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.4" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.53" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.66" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.79" Value="{StaticResource A_Double_Activity_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1.92" Value="{StaticResource A_Double_Activity_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames  x:Key="A_AnimationUsingKeyFrames_Glow" Storyboard.TargetProperty="Opacity">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="1" />
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" EasingFunction="{local:ExponentialEasing EasingMode=EaseOut}"/>
            </DoubleAnimationUsingKeyFrames>


            <local:UIStoryboard x:Key="A_Storyboard_ActivityCountChanged_FirstIncrement" BeginTime="0:0:0.20">
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_ScaleX_Pulse"/>
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_ScaleY_Pulse"/>
            </local:UIStoryboard>

            <local:UIStoryboard x:Key="A_Storyboard_ActivityCountChanged_Increment">
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_ScaleX_Pulse"/>
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_ScaleY_Pulse"/>
            </local:UIStoryboard>

            <local:UIStoryboard x:Key="A_Storyboard_ActivityCountChanged_FirstIncrement_Glow" BeginTime="0:0:0.20">
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_Glow"/>
            </local:UIStoryboard>
            <local:UIStoryboard x:Key="A_Storyboard_ActivityCountChanged_Increment_Glow">
                <StaticResourceExtension ResourceKey="A_AnimationUsingKeyFrames_Glow"/>
            </local:UIStoryboard>
        </ResourceDictionary>
    </UserControl.Resources>

    <Decorator x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Container">
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Shown">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Container">
                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            
                <VisualStateGroup.Transitions>
                    <VisualTransition From="Shown" To="Hidden">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Container">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0" EasingFunction="{local:ExponentialEasing EasingMode=EaseOut}"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="Hidden" To="Shown">
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Container">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1" EasingFunction="{local:ExponentialEasing EasingMode=EaseIn}"/>
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid x:Name="Container">
            <local:FZMaterial Width="48" Height="80" Style="{StaticResource A_Style_FZMaterial_GlassPanel_ActivityPanel_HUD}">
                <StackPanel MaxWidth="48" MaxHeight="80" VerticalAlignment="Center" Margin="0,-2,0,0">
                    <Grid>
                        <local:ControllerButtonControl Height="32"
                                                   x:Name="ActivateButton"
                                                   Margin="0,0,0,0"
                                                   Visibility="{Binding IsValid, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden}, RelativeSource={RelativeSource Self}}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_ActivationButton}"
                                                   InputOverride="{local:Input Command=INPUTCMD_OPEN_ACTIVITY_PANEL, Context=INPUTCONTEXT_RACING}"
                                                   UseLargeIcon="True"/>
                        <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/ActivityPanel/Mini_Social.png"
                                      Visibility="{Binding Path=IsValid, ElementName=ActivateButton, Converter={StaticResource A_FZBooleanToVisibilityConverter_UseHidden_Inverse}}"
                                      Width="50"
                                      Height="25"
                                      Margin="0,4,0,3" />
                    </Grid>
                    <Grid Height="32"
                          Width="32"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Bottom"
                          Margin="0,2,0,0.5">
                        <local:FZMaterial x:Name="EventCountBreadCrumb" Style="{StaticResource A_Style_FZMaterial_ActivityBreadCrumb}"
                                  RenderTransformOrigin="0.5,0.5">
                            <local:FZMaterial.RenderTransform>
                                <ScaleTransform/>
                            </local:FZMaterial.RenderTransform>
                        </local:FZMaterial>
                        <local:FZTextBlock Text="{Binding ActivityCount, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}}"
                                    Style="{StaticResource A_Style_FZTextBlock_HorizonA}"
                                    Color="{StaticResource A_Color_NotificationBadge_Text}"
                                    FontSize="19"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"/>

                        <local:FZMaterial x:Name="Glow"
                                  Opacity="0"
                                  Style="{StaticResource A_Style_FZMaterial_ActivityBreadCrumb}"
                                  Preset="{StaticResource A_FZMaterialPreset_BreadCrumb_AlphaAdditive}"/>
                    </Grid>
                </StackPanel>
            </local:FZMaterial>
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_RoundtangleStroke_ActivityPanel_Outline}"/>
        </Grid>
    </Decorator>

    <local:EventFire.FzTriggers>
        <BeginStoryboard local:EventFireTrigger.Event="ShowFirstActivity"
                         local:EventFireTrigger.TargetName="EventCountBreadCrumb"
                         Storyboard="{StaticResource A_Storyboard_ActivityCountChanged_FirstIncrement}"/>
        <BeginStoryboard local:EventFireTrigger.Event="ShowFirstActivity"
                         local:EventFireTrigger.TargetName="Glow"
                         Storyboard="{StaticResource A_Storyboard_ActivityCountChanged_FirstIncrement_Glow}"/>

        <BeginStoryboard local:EventFireTrigger.Event="IncrementActivity"
                         local:EventFireTrigger.TargetName="EventCountBreadCrumb"
                         Storyboard="{StaticResource A_Storyboard_ActivityCountChanged_Increment}"/>
        <BeginStoryboard local:EventFireTrigger.Event="IncrementActivity"
                         local:EventFireTrigger.TargetName="Glow"
                         Storyboard="{StaticResource A_Storyboard_ActivityCountChanged_Increment_Glow}"/>
    </local:EventFire.FzTriggers>
</UserControl>
