<Page xmlns:local="clr-namespace:ForzaUI"
      xmlns:System="clr-namespace:System;assembly=mscorlib"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      x:Class="ForzaUI.Scenes.Anthem.A_DestinationVote"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <local:UIPageTransitionManager.TransitionManager>
        <local:UIPageTransitionManager Preset="{StaticResource A_UIPageTransitionManagerPreset_Menu}"/>
    </local:UIPageTransitionManager.TransitionManager>

    <Page.Resources>
        <ResourceDictionary>
            <local:RaceModeConverter x:Key="A_Converter_RaceMode"/>

            <Style x:Key="A_Style_EventItem" TargetType="{x:Type ListBoxItem}">
                <Setter Property="Focusable" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Grid Margin="5,0" Visibility="{Binding IsValid, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                <local:FZMaterial Height="64"
                                              Width="64"
                                              ImageSource="{Binding RaceMode, Converter={StaticResource A_Converter_RaceMode}}"/>
                                <local:FZMaterial Height="22"
                                              Width="25"
                                              HorizontalAlignment="Left"
                                              Margin="-5,0,0,0"
                                              VerticalAlignment="Top"
                                              ImageSource="/ForzaUI;component/Textures/Data_Bound/Mountain/DestinationVote/BlizzardWarning.png"
                                              Visibility="{Binding IsBlizzardWarning, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="A_Style_ListBox_Events" TargetType="{x:Type local:CommonListBox}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type local:CommonListBox}">
                            <StackPanel IsItemsHost="True" Orientation="Horizontal" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="A_Style_Run_DestinationVoteMarkup_NUMBER"
                   TargetType="local:FZRun">
                <Setter Property="FontFamily" Value="Horizon_A" />
            </Style>

            <GridLength x:Key="A_GridLength_VoteFlyerBorder_Thickness">5</GridLength>

            <Style x:Key="A_Style_FZMaterial_VoteFlyerBorder"
                   TargetType="local:FZMaterial">
                <Setter Property="Color" Value="{StaticResource A_Color_Tile_Background}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding HasMostVotes}" Value="True">
                        <Setter Property="Color" Value="{StaticResource A_Color_Tile_AlternateBackground}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_BaseBanner"
                   TargetType="local:FZMaterial">
                <Setter Property="Color" Value="{StaticResource A_Color_Tile_AlternateBackground}"/>
                <Setter Property="Height" Value="42"/>
                <Setter Property="Width" Value="275"/>
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Visibility" Value="Collapsed"/>
            </Style>

            <Style x:Key="A_Style_FZMaterial_WinningBanner"
                   TargetType="local:FZMaterial"
                   BasedOn="{StaticResource A_Style_FZMaterial_BaseBanner}">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding HasMostVotes}" Value="True"/>
                            <Condition Binding="{Binding IsVoting, RelativeSource={RelativeSource AncestorType=Page}}" Value="True"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Visibility" Value="Visible" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_WinnerBanner"
                   TargetType="local:FZMaterial"
                   BasedOn="{StaticResource A_Style_FZMaterial_BaseBanner}">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding HasMostVotes}" Value="True"/>
                            <Condition Binding="{Binding IsVoting, RelativeSource={RelativeSource AncestorType=Page}}" Value="False"/>
                        </MultiDataTrigger.Conditions>
                        <Setter Property="Visibility" Value="Visible" />
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_BannerText"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_Heading_Small_Tight}">
                <Setter Property="FontSize" Value="27" />
                <Setter Property="Color" Value="{StaticResource A_Color_Tile_Text}" />
                <Setter Property="MaxWidth" Value="160" />
                <Setter Property="TrackingAdjust" Value="0.1" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>

            <ControlTemplate x:Key="A_ControlTemplate_DestinationVoteFlyer" TargetType="{x:Type local:FZButton}">
                <Grid Style="{StaticResource A_Style_FrameworkElement_DefaultTransition}"
                    local:UIPageTransitionManager.TransitionIndex="{Binding (local:UIPageTransitionManager.TransitionIndex), RelativeSource={RelativeSource TemplatedParent}}" >

                    <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_TileShadow}"/>
                    <local:FZMaterial x:Name="Background" ImageSource="{Binding BackgroundImagePath}"/>
                    <local:FZMaterial ImageSource="/ForzaUI;component/Textures/Data_Bound/OnlineChampionships/Footer.png"
                        VerticalAlignment="Bottom"
                        Height="46"
                        Width="475"/>

                    <Viewbox Stretch="Uniform"
                             StretchDirection="Both"
                             Height="25"
                             HorizontalAlignment="Center"
                             VerticalAlignment="Top"
                             Margin="0,39,0,0">
                        <Control Style="{StaticResource A_Style_Control_CarClassBadge_Small}"
                             Focusable="False"
                             local:BindingProxy.A="{Binding CarPI}" 
                             local:BindingProxy.B="{Binding CarClass}"/>
                    </Viewbox>

                    <local:FZTextBlock Text="{Binding Title}"
                                       Style="{StaticResource A_Style_FZTextBlock_Title_Large}"
                                       FontSize="74"
                                       Color="{StaticResource A_Color_Header_Text}"
                                       Margin="0,62,0,542"
                                       MaxWidth="430"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Center"/>

                    <local:FZTextBlock Text="{Binding SubTitle}"
                                       Style="{StaticResource A_Style_FZTextBlock_Heading_Minimum}"
                                       FontSize="{StaticResource A_Double_FontSize_Minimum}"
                                       Color="{StaticResource A_Color_Header_Text}"
                                       Margin="0,157,0,0"
                                       MaxWidth="430"
                                       TrackingAdjust="0.5"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Top"
                                       TextAlignment="Center"/>

                    <local:CommonListBox ItemsSource="{Binding Events}"
                                             Style="{StaticResource A_Style_ListBox_Events}"
                                             ItemContainerStyle="{StaticResource A_Style_EventItem}"
                                             Margin="0,194,0,0"
                                             VerticalAlignment="Top"
                                             HorizontalAlignment="Center"/>

                    <local:FZMaterial Color="{StaticResource A_Color_Opaque_Highlight}"
                                      VerticalAlignment="Bottom"
                                      HorizontalAlignment="Center"
                                      Margin="0,0,0,143"
                                      Height="44"
                                      MaxWidth="150"
                                      Visibility="{Binding IsVotedFor, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                        <local:FZTextBlock Text="{local:Loc Lobby.IDS_Destination_Voted_For}"
                                           Style="{StaticResource A_Style_FZTextBlock_Heading_Small_Tight}"
                                           FontSize="30"
                                           Color="{StaticResource A_Color_Tile_Text}"
                                           Margin="17,0,17,0"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Center"/>
                    </local:FZMaterial>

                    <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding VoteString}"
                                       local:TextBlockInlineMarkup.ResourceBaseName="A_Style_Run_DestinationVoteMarkup_"
                                       HorizontalAlignment="Center"
                                       VerticalAlignment="Bottom" 
                                       Margin="0,0,0,59"
                                       FontSize="65"
                                       Style="{StaticResource A_Style_FZTextBlock_Title_Large}"
                                       Color="{StaticResource A_Color_Tile_Text_Alternate}" />

                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="{StaticResource A_GridLength_VoteFlyerBorder_Thickness}"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="{StaticResource A_GridLength_VoteFlyerBorder_Thickness}"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="{StaticResource A_GridLength_VoteFlyerBorder_Thickness}"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="{StaticResource A_GridLength_VoteFlyerBorder_Thickness}"/>
                        </Grid.ColumnDefinitions>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="0" Grid.Column="0"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="0" Grid.Column="1"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="0" Grid.Column="2"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="1" Grid.Column="0"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="1" Grid.Column="2"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="2" Grid.Column="0"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="2" Grid.Column="1"/>
                        <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_VoteFlyerBorder}"
                                          Grid.Row="2" Grid.Column="2"/>
                    </Grid>


                    <Decorator ClipToBounds="True"
                               VerticalAlignment="Top"
                               HorizontalAlignment="Right"
                               Width="275"
                               Height="275">
                        <Grid VerticalAlignment="Top"
                                   HorizontalAlignment="Right"
                                   Margin="0,71,71,0"
                                   Height="0"
                                   Width="0"
                                   RenderTransformOrigin="0.5,0.5">
                            <Grid.RenderTransform>
                                <RotateTransform Angle="45"/>
                            </Grid.RenderTransform>
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_WinningBanner}">
                                <Grid>
                                    <local:FZTextBlock Text="{local:Loc Lobby.IDS_Destination_Winning}"
                                                       Style="{StaticResource A_Style_FZTextBlock_BannerText}"
                                                       Visibility="{Binding IsTied, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}"/>
                                    <local:FZTextBlock Text="{local:Loc Lobby.IDS_Destination_Tied}"
                                                       Style="{StaticResource A_Style_FZTextBlock_BannerText}"
                                                       Visibility="{Binding IsTied, RelativeSource={RelativeSource AncestorType=Page}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"/>
                                </Grid>
                            </local:FZMaterial>
                            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_WinnerBanner}">
                                <local:FZTextBlock Text="{local:Loc Lobby.IDS_Destination_Winner}"
                                                   Style="{StaticResource A_Style_FZTextBlock_BannerText}"/>
                            </local:FZMaterial>
                        </Grid>
                    </Decorator>
                </Grid>
            </ControlTemplate>

            <System:Double x:Key="A_Double_DestinationVoteFlyerWidth">475</System:Double>
            <System:Double x:Key="A_Double_DestinationVoteFlyerHeight">705</System:Double>

            <Style x:Key="A_Style_Button_DestinationVoteFlyer"
                   TargetType="{x:Type local:FZButton}"
                   BasedOn="{StaticResource A_Style_FrameworkElement_TransitionStyle}">
                <Setter Property="Width" Value="{StaticResource A_Double_DestinationVoteFlyerWidth}" />
                <Setter Property="Height" Value="{StaticResource A_Double_DestinationVoteFlyerHeight}" />
                <Setter Property="Margin" Value="15,0" />
                <Setter Property="Opacity" Value="1" />
                <Setter Property="local:FocusOnMouseOverBehaviour.Self" Value="True" />
                <Setter Property="Template" Value="{StaticResource A_ControlTemplate_DestinationVoteFlyer}" />
                <Setter Property="Panel.ZIndex" Value="0" />
                <Setter Property="local:ZPanel.ZOffset" Value="0" />
                <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding HasMostVotes}" Value="False" />
                            <Condition Binding="{Binding IsVoting, RelativeSource={RelativeSource AncestorType=Page}}" Value="False" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard>
                                <BeginStoryboard.Storyboard>
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" 
                                                                       Storyboard.TargetName="{x:Null}">
                                            <LinearDoubleKeyFrame KeyTime="0:0:0.2" Value="0.5"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard.Storyboard>
                            </BeginStoryboard>
                        </MultiDataTrigger.EnterActions>
                    </MultiDataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocused}" Value="True"/>
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <Int32AnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.ZIndex)">
                                        <DiscreteInt32KeyFrame KeyTime="0:0:0.0"
                                                                Value="3">
                                        </DiscreteInt32KeyFrame>
                                    </Int32AnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(local:ZPanel.ZOffset)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                                Value="{StaticResource A_Double_ZOffset_Acrylic}">
                                        </DiscreteDoubleKeyFrame>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                                Value="1.150">
                                        </DiscreteDoubleKeyFrame>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                                        <DiscreteDoubleKeyFrame KeyTime="0:0:0.0"
                                                                Value="1.150">
                                        </DiscreteDoubleKeyFrame>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </MultiDataTrigger.EnterActions>
                        <MultiDataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <Int32AnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.ZIndex)">
                                        <DiscreteInt32KeyFrame KeyTime="0:0:0.0"
                                                               Value="1">
                                        </DiscreteInt32KeyFrame>
                                        <DiscreteInt32KeyFrame KeyTime="0:0:0.36"
                                                               Value="0">
                                        </DiscreteInt32KeyFrame>
                                    </Int32AnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(local:ZPanel.ZOffset)">
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.36"
                                                              Value="0"
                                                              EasingFunction="{StaticResource A_EasingFunction_TileSelection}"/>
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.36"
                                                              Value="1.00"
                                                              EasingFunction="{StaticResource A_EasingFunction_TileSelection}" />
                                    </DoubleAnimationUsingKeyFrames>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.36"
                                                              Value="1.00"
                                                              EasingFunction="{StaticResource A_EasingFunction_TileSelection}" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </MultiDataTrigger.ExitActions>
                        <MultiDataTrigger.Setters>
                            <Setter Property="Opacity" Value="1"/>
                        </MultiDataTrigger.Setters>
                    </MultiDataTrigger>
                    <Trigger Property="IsKeyboardFocused" Value="False">
                        <Setter Property="Panel.ZIndex" Value="0"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <Grid>
        <ContentControl x:Name="BottomBar" Style="{StaticResource A_Style_ButtonBar}" Visibility="{Binding IsVoting, Converter={StaticResource A_Converter_BoolVisibility}}">
            <ContentControl x:Name="DefaultHelpPanel"
                            local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_VoteForDestination}"
                            Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
        </ContentControl>
        <local:NetworkCountdownControl Style="{StaticResource A_Style_NetworkCountdownControl_VoteEnds}" CountdownType="RoadTripDestinationVoting" AudioEnabled="True" WarningSeconds="3" Visibility="{Binding IsVoting, Converter={StaticResource A_Converter_BoolVisibility}}"/>
        
        <Border x:Name="LayoutRoot" Style="{StaticResource A_Style_Border_ScenePadding}" >
            <Grid Margin="0,9,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
                <StackPanel Orientation="Horizontal" Margin="0,0,0,0" KeyboardNavigation.DirectionalNavigation="Contained">
                    <local:FZButton x:Name="PART_Button_Destination0" 
                            DataContext="{Binding Destinations[0]}" 
                            local:UIPageTransitionManager.TransitionIndex="1" 
                            Style="{StaticResource A_Style_Button_DestinationVoteFlyer}" />
                    <local:FZButton x:Name="PART_Button_Destination1"
                            DataContext="{Binding Destinations[1]}" 
                            local:UIPageTransitionManager.TransitionIndex="2" 
                            Style="{StaticResource A_Style_Button_DestinationVoteFlyer}" />
                    <local:FZButton x:Name="PART_Button_Destination2" 
                            DataContext="{Binding Destinations[2]}" 
                            local:UIPageTransitionManager.TransitionIndex="3" 
                            Style="{StaticResource A_Style_Button_DestinationVoteFlyer}" />
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>