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

    <UserControl.Resources>
        <ResourceDictionary>
            <Color x:Key="A_Color_HUD_Radio_ErrorTitle">#FF00FFEA</Color>
            <Color x:Key="A_Color_HUD_Radio_ErrorMessage">#FFFFFFFF</Color>

            <local:MappingConverter x:Key="A_MappingConverter_FZMaterial_Icon_FromStationString" Default="">
                <local:MappingConverterEntry Key="StationOff" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/HUD_RadioIcon_Off.png" />
                <local:MappingConverterEntry Key="Horizon Pulse" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Horizon_Pulse.png" />
                <local:MappingConverterEntry Key="Horizon Bass Arena" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Horizon_BassArena.png" />
                <local:MappingConverterEntry Key="Horizon Block Party" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Horizon_BlockParty.png" />
                <local:MappingConverterEntry Key="Horizon XS" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Horizon_XS.png" />
                <local:MappingConverterEntry Key="Hospital Records" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Hospital_Records.png" />
                <local:MappingConverterEntry Key="Timeless FM" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Timeless.png" />
                <local:MappingConverterEntry Key="Streamer Mode" Value="/ForzaUI;component/Textures/Anthem/HUD/RadioLogos/Streamer_Mode.png" />
                <local:MappingConverterEntry Key="Radio Awesome" Value="/ForzaUI;component/Textures/Data_Bound/PDLC2/RadioStations/Radio_Awesome.png"/>
            </local:MappingConverter>

            <Style x:Key="A_Style_FZMaterial_StationIcon" TargetType="local:FZMaterial">
                <Setter Property="Height" Value="96" />
                <Setter Property="Width" Value="196" />
                <Setter Property="ImageSource" Value="{Binding StationName, Converter={StaticResource A_MappingConverter_FZMaterial_Icon_FromStationString}}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding StationName}" Value="Horizon Block Party">
                        <Setter Property="Height" Value="144" />
                        <Setter Property="Width" Value="185" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding StationName}" Value="Hospital Records">
                        <Setter Property="Height" Value="126" />
                        <Setter Property="Width" Value="185" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding StationName}" Value="Horizon Pulse">
                        <Setter Property="Height" Value="126" />
                        <Setter Property="Width" Value="185" />
                        <Setter Property="Margin" Value="-7,0,0,0" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding StationName}" Value="Radio Awesome">
                        <Setter Property="Height" Value="137.5" />
                        <Setter Property="Width" Value="196" />
                        <Setter Property="Margin" Value="-2,0,0,0" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding StationName}" Value="StationOff">
                        <Setter Property="Margin" Value="0,0,0,-30" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding StationName}" Value="E3">
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Color x:Key="A_Color_RadioDropShadow">#B7262626</Color>
            <DropShadowEffect x:Key="A_DropShadowEffect_RadioHud" Color="{StaticResource A_Color_RadioDropShadow}" BlurRadius="0" ShadowDepth="1"/>

            <Style x:Key="A_Style_FZTextBlock_RadioText" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_HudMedium}">
                <Setter Property="CapHeight" Value="16" />
                <Setter Property="Margin" Value="9,0" />
            </Style>

            <ExponentialEase x:Key="A_EasingFunction_EaseInOut" EasingMode="EaseInOut"/>
            <System:Double x:Key="A_Double_SkillSong_DefaultScale">1.0</System:Double>
            <System:Double x:Key="A_Double_SkillSong_PulseScale">1.1</System:Double>

            <Style x:Key="A_Style_FZMaterial_SkillSongIcon" TargetType="local:FZMaterial">
                <Setter Property="Width" Value="48" />
                <Setter Property="Height" Value="48" />
                <Setter Property="Margin" Value="4,-16,-8,-4" />
                <Setter Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/HUD/Skill_Song_Icon_Small.png" />
                <Setter Property="Visibility" Value="{Binding IsSkillSong, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue={x:Static Visibility.Collapsed}}"/>
                <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <TransformGroup>
                            <ScaleTransform ScaleX="{StaticResource A_Double_SkillSong_DefaultScale}"
                                            ScaleY="{StaticResource A_Double_SkillSong_DefaultScale}"/>
                        </TransformGroup>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Value="{x:Static HorizontalAlignment.Left}">
                        <Setter Property="DockPanel.Dock" Value="Left"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Value="{x:Static HorizontalAlignment.Right}">
                        <Setter Property="DockPanel.Dock" Value="Right"/>
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Visibility, RelativeSource={RelativeSource Self}}" Value="{x:Static Visibility.Visible}" />
                            <Condition Binding="{Binding IsInitialized, RelativeSource={RelativeSource AncestorType=Page}}" Value="{StaticResource A_Boolean_True}" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard x:Name="BeginPulseAnim">
                                <BeginStoryboard.Storyboard>
                                    <Storyboard RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="{x:Null}">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.53" Value="{StaticResource A_Double_SkillSong_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.66" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.79" Value="{StaticResource A_Double_SkillSong_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.92" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="{x:Null}">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.53" Value="{StaticResource A_Double_SkillSong_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.66" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.79" Value="{StaticResource A_Double_SkillSong_PulseScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.92" Value="{StaticResource A_Double_SkillSong_DefaultScale}" EasingFunction="{StaticResource A_EasingFunction_EaseInOut}"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard.Storyboard>
                            </BeginStoryboard>
                        </MultiDataTrigger.EnterActions>
                        <MultiDataTrigger.ExitActions>
                            <StopStoryboard BeginStoryboardName="BeginPulseAnim" />
                        </MultiDataTrigger.ExitActions>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_Progress_TrackLoadingSpinner"
                   TargetType="ProgressBar"
                   BasedOn="{StaticResource A_Style_ProgressBar_WaitSpinner}">
                <Setter Property="Visibility" Value="Hidden" />
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding IsLoading}" Value="True"/>
                            <Condition Binding="{Binding ShouldDisplayError}" Value="False"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Visibility" Value="Visible"/>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>
            
            <Style x:Key="A_Style_RadioTransitions" TargetType="ContentControl">
                <Style.Setters>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <StackPanel x:Name="MainStackPanel">
                                    <StackPanel.RenderTransform>
                                        <TranslateTransform X="0" Y="0" />
                                    </StackPanel.RenderTransform>
                                    <local:FZMaterial HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                      Style="{StaticResource A_Style_FZMaterial_StationIcon}" Stretch="Fill" StretchDirection="DownOnly"/>
                                    <StackPanel Visibility="{Binding ShouldDisplayError, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
                                        <local:FZMaterial HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                          Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" Height="36" Margin="0,12,0,6">
                                            <Grid VerticalAlignment="Center">
                                                <StackPanel x:Name="StackPanel_TrackName" VerticalAlignment="Center">
                                                    <StackPanel Orientation="Horizontal" Visibility="{Binding IsLoading, Converter={StaticResource A_FZBooleanToVisibilityConverter}}" VerticalAlignment="Center">
                                                        <ProgressBar IsIndeterminate="True"
                                                                     Style="{StaticResource A_Style_Progress_TrackLoadingSpinner}"
                                                                     Height="24"
                                                                     Width="24"
                                                                     VerticalAlignment="Center"
                                                                     HorizontalAlignment="Left"
                                                                     Margin="6,0,-2,0"/>
                                                        <local:FZTextBlock Text="{local:Loc InGame.IDS_RadioLoading}"
                                                                           Style="{StaticResource A_Style_FZTextBlock_RadioText}"
                                                                           Color="{StaticResource A_Color_HUD_RadioAlternateText}"
                                                                           HorizontalAlignment="Left"
                                                                           VerticalAlignment="Center"
                                                                           Stretch="None"/>
                                                    </StackPanel>
                                                    <StackPanel Visibility="{Binding IsLoading, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}" 
                                                                           VerticalAlignment="Center">
                                                        <local:FZTextBlock Text="{Binding TrackName}"
                                                                           HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
                                                                           VerticalAlignment="Center"
                                                                           Style="{StaticResource A_Style_FZTextBlock_RadioText}"
                                                                           Color="{StaticResource A_Color_HUD_RadioAlternateText}"
                                                                           Visibility="{Binding TrackName, Converter={StaticResource A_StringVisConverter}}" />
                                                    </StackPanel>
                                                </StackPanel>
                                            </Grid>
                                        </local:FZMaterial>
                                        <local:FZMaterial HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                          Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" Height="36"
                                                          VerticalAlignment="Center"
                                                      Visibility="{Binding ArtistName, Converter={StaticResource A_StringVisConverter_UseHidden}}">
                                            <DockPanel VerticalAlignment="Center">
                                                <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_SkillSongIcon}"/>
                                                <local:FZTextBlock x:Name="FZTextBlock_ArtistName"
                                                                   Text="{Binding ArtistName}"
                                                                   VerticalAlignment="Center"
                                                                   HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                                   Style="{StaticResource A_Style_FZTextBlock_RadioText}" 
                                                                   Visibility="{Binding ArtistName, Converter={StaticResource A_StringVisConverter}}"/>
                                            </DockPanel>
                                        </local:FZMaterial>
                                    </StackPanel>
                                    <StackPanel Visibility="{Binding ShouldDisplayError, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                        <local:FZMaterial HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                          Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" Height="Auto" Margin="0,12,0,6">
                                            <local:FZTextBlock x:Name="FZTextBlock_ErrorTitle"
                                                                    Text="{Binding ErrorTitle}" 
                                                                    HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                                    Style="{StaticResource A_Style_FZTextBlock_RadioText}"
                                                                    Color="{StaticResource A_Color_HUD_Radio_ErrorTitle}" 
                                                                    Visibility="{Binding ErrorTitle, Converter={StaticResource A_StringVisConverter}}"/>
                                        </local:FZMaterial>
                                        <local:FZMaterial HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Style="{StaticResource A_Style_FZMaterial_GlassHudItem}" Height="36">
                                            <Grid>
                                                <local:FZTextBlock x:Name="FZTextBlock_ErrorMessage"
                                                                   Text="{Binding ErrorMessage}" 
                                                                   HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" 
                                                                   Style="{StaticResource A_Style_FZTextBlock_RadioText}" 
                                                                    Color="{StaticResource A_Color_HUD_Radio_ErrorMessage}" 
                                                                   Visibility="{Binding ErrorMessage, Converter={StaticResource A_StringVisConverter}}"/>
                                            </Grid>
                                        </local:FZMaterial>
                                    </StackPanel>
                                    <local:EventFire x:Name="EventFire" />
                                </StackPanel>

                                <ControlTemplate.Triggers>
                                    <DataTrigger Binding="{Binding HasChangedStation}" Value="True">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard>
                                                <BeginStoryboard.Storyboard>
                                                    <Storyboard>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="MainStackPanel" Duration="0:0:2.5">
                                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0"/>
                                                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                                                        </DoubleAnimationUsingKeyFrames>
                                                        <StringAnimationUsingKeyFrames Storyboard.TargetName="EventFire" Storyboard.TargetProperty="EventName" Duration=" 0:0:3.9">
                                                            <DiscreteStringKeyFrame KeyTime="0:0:3.9" Value="Reset"/>
                                                        </StringAnimationUsingKeyFrames>
                                                        <StringAnimationUsingKeyFrames Storyboard.TargetName="EventFire" Storyboard.TargetProperty="EventName" Duration=" 0:0:4.0">
                                                            <DiscreteStringKeyFrame KeyTime="0:0:4" Value="ShownComplete"/>
                                                        </StringAnimationUsingKeyFrames>
                                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" 
                                                                                       Storyboard.TargetName="MainStackPanel" Duration="0:0:0.5">
                                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="-25"/>
                                                            <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0">
                                                                <EasingDoubleKeyFrame.EasingFunction>
                                                                    <BackEase Amplitude="0.5"/>
                                                                </EasingDoubleKeyFrame.EasingFunction>
                                                            </EasingDoubleKeyFrame>
                                                        </DoubleAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard.Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                    </DataTrigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style.Setters>
            </Style>

        </ResourceDictionary>
    </UserControl.Resources>

    <ContentControl  x:Name="LayoutRoot" Style="{StaticResource A_Style_RadioTransitions}">
        <VisualStateManager.VisualStateGroups   >
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Hidden">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="LayoutRoot" Duration="0:0:0.3">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <StringAnimationUsingKeyFrames Storyboard.TargetName="EventFire" Storyboard.TargetProperty="EventName" Duration=" 0:0:0.0">
                            <DiscreteStringKeyFrame KeyTime="0:0:0" Value="Reset"/>
                        </StringAnimationUsingKeyFrames>
                        <StringAnimationUsingKeyFrames Storyboard.TargetName="EventFire" Storyboard.TargetProperty="EventName" Duration=" 0:0:0.3">
                            <DiscreteStringKeyFrame KeyTime="0:0:0.3" Value="HiddenComplete"/>
                        </StringAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Shown"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid>
            <local:MappingConverterResourcePreloader Converter="{StaticResource A_MappingConverter_FZMaterial_Icon_FromStationString}" ValueType="BitmapImage" />
            <local:EventFire x:Name="EventFire" />
        </Grid>
    </ContentControl>

</UserControl>
