<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">

    <!-- STAMINA BAR ASSETS -->
    <Image x:Key="StaminaBarIconDefault" Source="../Textures/HUD/StaminaBar/IconStaminaDefault.png" Stretch="UniformToFill"/>
    <Image x:Key="StaminaBarIconExhaust" Source="../Textures/HUD/StaminaBar/IconStaminaExhaust.png" Stretch="UniformToFill"/>
    <ImageBrush x:Key="StaminaBarBackground" ImageSource="../Textures/HUD/StaminaBar/StaminaBarBackground.png" TileMode="None" Stretch="None"/>
    <ImageBrush x:Key="StaminaBarFill" ImageSource="../Textures/HUD/StaminaBar/StaminaBarFill.png" TileMode="None" Stretch="None"/>
    <ImageBrush x:Key="StaminaBarBackgroundExhaust" ImageSource="../Textures/HUD/StaminaBar/StaminaBarExhaust.png" TileMode="None" Stretch="None"/>

    <!-- STAMINA BAR TEMPLATE -->
    <!--////////////////////////////////////////////////////////////////////-->

    <Style x:Key="StaminaBarStyle" TargetType="{x:Type ProgressBar}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ProgressBar}">
                    <Grid x:Name="StaminaBarLayout" SnapsToDevicePixels="True" Height="24">

                        <!-- STATE MANAGER -->
                        <!-- This part defines the stamina bar's states and the animations they trigger -->
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="StaminaBarStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.5" From="Exhaust" To="Normal">
                                            <!-- When we transition back to Normal state we trigger this storyboard -->
                                            <Storyboard Duration="0:0:0.5">

                                                <!-- These animations hide the exhaust state stamina bar icon and then display the default one  -->
                                                <DoubleAnimation
                                                        Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                        Storyboard.TargetProperty="Opacity"
                                                        To="0.0"
                                                        BeginTime="0:0:0"
                                                        Duration="0:0:0.1">

                                                    <DoubleAnimation.EasingFunction>
                                                        <PowerEase EasingMode="EaseOut" Power="3"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>

                                                <ObjectAnimationUsingKeyFrames
                                                        Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                        Storyboard.TargetProperty="Visibility"
                                                        BeginTime="0:0:0.1"
                                                        Duration="0:0:0.05">
                                                    <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Hidden</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>

                                                <ObjectAnimationUsingKeyFrames
                                                        Storyboard.TargetName="StaminaBarIconContent"
                                                        Storyboard.TargetProperty="Visibility"
                                                        BeginTime="0:0:0.1"
                                                        Duration="0:0:0.05">
                                                    <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>

                                                <DoubleAnimation
                                                        Storyboard.TargetName="StaminaBarIconContent"
                                                        Storyboard.TargetProperty="Opacity"
                                                        To="1.0"
                                                        BeginTime="0:0:0.15"
                                                        Duration="0:0:0.3">

                                                    <DoubleAnimation.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>

                                                <DoubleAnimation
                                                        Storyboard.TargetName="StaminaBarIconContent"
                                                        Storyboard.TargetProperty="(ContentControl.Width)"
                                                        AutoReverse="True"
                                                        From="24"
                                                        To="28"
                                                        BeginTime="0:0:0.15"
                                                        Duration="0:0:0.2">

                                                    <DoubleAnimation.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>

                                                <DoubleAnimation
                                                        Storyboard.TargetName="StaminaBarIconContent"
                                                        Storyboard.TargetProperty="(ContentControl.Height)"
                                                        AutoReverse="True"
                                                        From="24"
                                                        To="28"
                                                        BeginTime="0:0:0.15"
                                                        Duration="0:0:0.2">

                                                    <DoubleAnimation.EasingFunction>
                                                        <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                                    </DoubleAnimation.EasingFunction>
                                                </DoubleAnimation>
                                            </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>

                                <!-- NORMAL STATE -->
                                <VisualState Name="Normal"/>

                                <!-- EXHAUST STATE -->
                                <VisualState Name="Exhaust">
                                    <Storyboard Duration="0:0:0.7">

                                        <!-- These animations hide the default stamina bar icon and then display the exhaust state one -->
                                        <DoubleAnimation
                                                Storyboard.TargetName="StaminaBarIconContent"
                                                Storyboard.TargetProperty="Opacity"
                                                To="0.0"
                                                BeginTime="0:0:0"
                                                Duration="0:0:0.1">

                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>

                                        <ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetName="StaminaBarIconContent"
                                                Storyboard.TargetProperty="Visibility"
                                                BeginTime="0:0:0.1"
                                                Duration="0:0:0.05">
                                            <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Hidden</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>

                                        <ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                Storyboard.TargetProperty="Visibility"
                                                BeginTime="0:0:0.1"
                                                Duration="0:0:0.05">
                                            <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>

                                        <DoubleAnimation
                                                Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                Storyboard.TargetProperty="Opacity"
                                                To="1.0"
                                                BeginTime="0:0:0.15"
                                                Duration="0:0:0.3">

                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>

                                        <DoubleAnimation
                                                Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                Storyboard.TargetProperty="(ContentControl.Width)"
                                                To="24"
                                                BeginTime="0:0:0.15"
                                                Duration="0:0:0.3">

                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>

                                        <DoubleAnimation
                                                Storyboard.TargetName="StaminaBarIconExhaustContent"
                                                Storyboard.TargetProperty="(ContentControl.Height)"
                                                To="24"
                                                BeginTime="0:0:0.15"
                                                Duration="0:0:0.3">

                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase EasingMode="EaseOut" Exponent="5"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>

                                        <!-- These animations change the background of the stamina bar to its Exhaust variant -->
                                        <!-- They are triggered during the icon swap animations -->
                                        <ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetName="PART_Track.Normal"
                                                Storyboard.TargetProperty="Visibility"
                                                Duration="0:0:0.05"
                                                BeginTime="0:0:0.1">
                                            <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Hidden</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>

                                        <ObjectAnimationUsingKeyFrames
                                                Storyboard.TargetName="PART_Track.Exhaust"
                                                Storyboard.TargetProperty="Visibility"
                                                Duration="0:0:0.05"
                                                BeginTime="0:0:0.1">
                                            <DiscreteObjectKeyFrame KeyTime="Uniform">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>

                                        <DoubleAnimation
                                                Storyboard.TargetName="PART_Track.Exhaust"
                                                Storyboard.TargetProperty="Opacity"
                                                To="1.0"
                                                BeginTime="0:0:0.15"
                                                Duration="0:0:0.2">

                                            <DoubleAnimation.EasingFunction>
                                                <PowerEase EasingMode="EaseOut" Power="1"/>
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <!-- GRID LAYOUT -->
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="40"/>
                            <ColumnDefinition Width="264"/>
                        </Grid.ColumnDefinitions>

                        <!-- This is where we render the bar's icons -->
                        <ContentControl x:Name="StaminaBarIconContent"
                                        Content="{StaticResource StaminaBarIconDefault}"
                                        Grid.Column="0"
                                        Width="24"
                                        Height="24"
                                        Opacity="1.0"
                                        Visibility="Visible"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"/>

                        <ContentControl x:Name="StaminaBarIconExhaustContent"
                                        Content="{StaticResource StaminaBarIconExhaust}"
                                        Grid.Column="0"
                                        Width="32"
                                        Height="32"
                                        Opacity="0.0"
                                        Visibility="Hidden"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center">
                        </ContentControl>

                        <!-- BASE SECTION -->
                        <!-- This part serves as the backer for the progress bar. It is very important to conserve the PART_Track name or it will break -->
                        <Grid x:Name="PART_Track" HorizontalAlignment="Right" Grid.Column="1" Visibility="Visible">
                            <Viewbox x:Name="PART_Track.Normal" Stretch="None" Visibility="Visible">
                                <Path Fill="{StaticResource StaminaBarBackground}"
                                      Data="F1 M 0.000,0.000 L 258.000,0.000 L 264.000,8.000 L 165.000,8.000 L 0.000,8.000 L 0.000,0.000 Z"/>
                            </Viewbox>

                            <Viewbox x:Name="PART_Track.Exhaust" Stretch="None" Visibility="Hidden" Opacity="0.0">
                                <Path Fill="{StaticResource StaminaBarBackgroundExhaust}"
                                      Data="F1 M 0.000,0.000 L 258.000,0.000 L 264.000,8.000 L 165.000,8.000 L 0.000,8.000 L 0.000,0.000 Z"/>
                            </Viewbox>
                        </Grid>

                        <!-- FILL SECTION -->
                        <!-- This is the part that grows or shrinks based on the value. It is very important to conserve the PART_Indicator name or it will break -->
                        <Grid x:Name="PART_Indicator" HorizontalAlignment="Left" Grid.Column="1">
                            <Viewbox Stretch="None">
                                <Path Fill="{StaticResource StaminaBarFill}"
                                      Data="F1 M 0.000,0.000 L 258.000,0.000 L 264.000,8.000 L 165.000,8.000 L 0.000,8.000 L 0.000,0.000 Z"/>
                            </Viewbox>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- ANIMATION -->
    <!-- This animation is triggered when the value of the Stamina.CurrentFactor changes.
         It animates the fill of the bar to shrink and grow with a smooth linear interpolation for 400ms
         The trigger is defined in LocalPlayerCard.xaml in the StaminaBar element -->
    <Storyboard x:Key="StaminaBarAnimation">
        <DoubleAnimation
                Storyboard.TargetName="StaminaBar"
                Storyboard.TargetProperty="Value"
                To="{Binding LocalPlayerCard.Stamina.CurrentFactor}"
                BeginTime="0:0:0"
                Duration="0:0:0.4">
            <DoubleAnimation.EasingFunction>
                <QuarticEase EasingMode="EaseOut"/>
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>
    </Storyboard>

</ResourceDictionary>
