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

    <Page.Resources>
        <Style x:Key="A_Style_ListBoxItem_Event" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <ContentPresenter Margin="8,3"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <ControlTemplate x:Key="A_ControlTemplate_ChallengeList" TargetType="{x:Type local:CommonListBox}">
            <StackPanel IsItemsHost="True" Margin="0,6"/>
        </ControlTemplate>
        
        <Style x:Key="A_Style_FZMaterial_FadeInWhenDownloaded" TargetType="{x:Type local:FZMaterial}">
            <Style.Resources>
                <Storyboard x:Key="Storyboard1">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="{x:Null}">
                        <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </Style.Resources>
            <Style.Triggers>
                <Trigger Property="Downloaded" Value="True">
                    <Trigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
                    </Trigger.EnterActions>
                </Trigger>
            </Style.Triggers>
        </Style>

        <ControlTemplate x:Key="A_ControlTemplate_SidePanel_ForzaEvents" TargetType="ContentControl">
            <DockPanel>
                <ContentControl Style="{StaticResource A_Style_ContentControl_Header_Custom}" DockPanel.Dock="Top" Height="90" Focusable="False">
                    <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HeaderBlock}" Text="{TemplateBinding Tag, Converter={StaticResource A_StringToUpper}}" CapHeight="29" />
                </ContentControl>
                <ContentControl DockPanel.Dock="Top" Content="{TemplateBinding Content}" Template="{StaticResource A_ControlTemplate_SidePanelContent}"  Focusable="False"/>
            </DockPanel>
        </ControlTemplate>

        <ControlTemplate x:Key="A_ControlTemplate_ForzaEvents_BonusPanel" TargetType="Control">
            <DockPanel>
                <ContentControl Style="{StaticResource A_Style_ContentControl_Header_Custom}" DockPanel.Dock="Top" Height="72" Focusable="False">
                    <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="24,15">
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_HeaderBlock}" Text="{Binding Title, Converter={StaticResource A_StringToUpper}}" CapHeight="29" Margin="0"/>
                    </StackPanel>
                </ContentControl>
                <ContentControl DockPanel.Dock="Top" Template="{StaticResource A_ControlTemplate_SidePanelContent}" Focusable="False">
                    <DockPanel Margin="7">
                        <local:FZMaterial x:Name="ProgressContainer"  DockPanel.Dock="Bottom" Style="{StaticResource A_Style_FZMaterial_ForzaEvents_ChallengeState}" Height="32">
                            <DockPanel VerticalAlignment="Center" Margin="10,0">
                                <StackPanel DockPanel.Dock="Left" Orientation="Horizontal" VerticalAlignment="Center">
                                    <local:FZTextBlock x:Name="RewardText" Text="{Binding NumBonusEventPoints}" Style="{StaticResource A_Style_FZTextBlock_ForzaEvents_DailyChallenge_RewardText}" VerticalAlignment="Center"/>
                                    <local:FZMaterial x:Name="RewardIcon" Style="{StaticResource A_Style_FZMaterial_ForzaEventPoints_Small}" Margin="4,0"/>
                                </StackPanel>
                                <Viewbox StretchDirection="DownOnly"
                                         HorizontalAlignment="Right">
                                    <Grid>
                                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center">
                                            <local:FZTextBlock x:Name="ProgressTextDaily" Text="{Binding ProgressDaily, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_ForzaEvents_DailyChallenge_ProgressText}"/>
                                            <Decorator Width="15" />
                                            <local:FZTextBlock x:Name="ProgressTextWeekly" Text="{Binding ProgressStory, Converter={StaticResource A_StringToUpper}}" Style="{StaticResource A_Style_FZTextBlock_ForzaEvents_DailyChallenge_ProgressText}"/>
                                        </StackPanel>
                                        <StackPanel x:Name="StatePanel" Orientation="Horizontal" Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Center">
                                            <local:FZTextBlock x:Name="StateText" Style="{StaticResource A_Style_FZTextBlock_ForzaEvents_DailyChallenge_ProgressText}" VerticalAlignment="Center"/>
                                            <local:FZMaterial x:Name="StateIcon" 
                                                                      Visibility="Collapsed" 
                                                                      Height="32" 
                                                                      Width="32" 
                                                                      VerticalAlignment="Center"
                                                                      Margin="0,0,-9,0"/>
                                        </StackPanel>
                                    </Grid>
                                </Viewbox>
                            </DockPanel>
                        </local:FZMaterial>
                        <Decorator Height="16" DockPanel.Dock="Top"/>
                        <local:FZTextBlock local:TextBlockInlineMarkup.Markup="{Binding Detail}"
                                           local:TextBlockInlineMarkup.ResourceBaseName="A_Style_FZRun_ForzaEvents_Challenge_"
                                           CapHeight="15"
                                           FontFamily="Horizon_D"
                                           TextAlignment="Center"
                                           Color="#FFFFFFFF"/>
                    </DockPanel>
                </ContentControl>
            </DockPanel>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding State}" Value="{x:Static local:ForzaEventChallengeState.Complete}">
                    <Setter TargetName="StateIcon" Property="Visibility" Value="Visible" />
                    <Setter TargetName="StateIcon" Property="ImageSource" Value="/ForzaUI;component/Textures/Anthem/Icons/Tick.png" />
                    <Setter TargetName="ProgressContainer" Property="Color" Value="#FFFFFFFF" />
                    <Setter TargetName="ProgressContainer" Property="ImageSource" Value="/ForzaUI;component/Textures/Data_Bound\Forza_Events\CompletedBacking.png" />
                    <Setter TargetName="StateText" Property="Color" Value="{StaticResource A_Color_ForzaEvents_DailyChallenge_CompletedText}" />
                    <Setter TargetName="StateText" Property="Text" Value="{local:Loc ForzaEvents.IDS_Complete}" />
                    <Setter TargetName="StatePanel" Property="Visibility" Value="Visible" />
                    <Setter TargetName="RewardText" Property="Color" Value="{StaticResource A_Color_ForzaEvents_DailyChallenge_CompletedText}" />
                    <Setter TargetName="RewardIcon" Property="Color" Value="{StaticResource A_Color_ForzaEvents_DailyChallenge_CompletedText}" />
                    <Setter TargetName="ProgressTextDaily" Property="Visibility" Value="Collapsed" />
                    <Setter TargetName="ProgressTextWeekly" Property="Visibility" Value="Collapsed" />
                    <Setter TargetName="StateIcon" Property="Color" Value="{StaticResource A_Color_ForzaEvents_DailyChallenge_CompletedText}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding State}" Value="{x:Static local:ForzaEventChallengeState.Expired}">
                    <Setter TargetName="ProgressTextDaily" Property="Visibility" Value="Collapsed" />
                    <Setter TargetName="ProgressTextWeekly" Property="Visibility" Value="Collapsed" />
                    <Setter TargetName="StatePanel" Property="Visibility" Value="Visible"/>
                    <Setter TargetName="StateText" Property="Text" Value="{local:Loc ForzaEvents.IDS_BonusFailedText}" />
                    <Setter TargetName="StateIcon" Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Page.Resources>

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

    <Grid>
        <!-- Background Blur -->
       <Control Style="{StaticResource A_Style_Control_ScreenBackground}" />

        <local:PlayerBarControl Style="{StaticResource A_Style_PlayerBarControl}"
                        x:Name="TopBar" />
        <ContentControl Style="{StaticResource A_Style_ButtonBar}"
                        x:Name="BottomBar">
            <local:ControllerButtonPanel x:Name="HelpPanel"
                                         Style="{StaticResource A_Style_ControllerButtonPanel_Default}">
                <local:ControllerButtonControl Button="A" Description="{local:Loc HelpButtons.IDS_Select}"/>
                <local:ControllerButtonControl Button="B" Description="{local:Loc HelpButtons.IDS_Back}"/>
                <local:ControllerButtonControl Style="{StaticResource A_ControllerButtonControl_RS_ForzaEvents_Controller}" />
                <local:ControllerButtonControl Style="{StaticResource A_ControllerButtonControl_RS_ForzaEvents_Keyboard}" />
            </local:ControllerButtonPanel>
        </ContentControl>

        <Border Style="{StaticResource A_Style_Border_ScenePadding}"
            x:Name="LayoutRoot"
            DataContext="{Binding EventData}">

            <Grid Style="{StaticResource A_Style_FrameworkElement_ScreenTilt}">
                <StackPanel HorizontalAlignment="Center"
                    Orientation="Vertical"
                    VerticalAlignment="Center">

                    <!-- Title -->
                    <Decorator HorizontalAlignment="Left"
                        Margin="0,-60,0,0"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">
                        <ContentControl Content="{Binding ForzaEventTitle, Converter={StaticResource A_StringToUpper}}"
                            Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                            local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Titles/ForzaEvents.png"
                            Focusable="False"/>
                    </Decorator>

                    <StackPanel Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_2}" KeyboardNavigation.DirectionalNavigation="Contained" Orientation="Horizontal">
                        <local:MultiItemLiveTile x:Name="Weekly" 
                                                 Style="{StaticResource A_Style_Button_ForzaEvents}" 
                                                 Template="{StaticResource A_ControlTemplate_ForzaEvents_WeeklyMultiChallenge}" 
                                                 Items="{Binding ChildChallenges}" 
                                                 Height="715" 
                                                 Width="426" 
                                                 DataContext="{Binding CurrentWeeklyChallenge}"
                                                 Command="{Binding WeeklyEventsTransition, RelativeSource={RelativeSource FindAncestor, AncestorType=Page}}"
                                                 ClickMode="Press"
                                                 SelectedItemIndex="{Binding CurrentChallengeIndex, Mode=TwoWay}"
                                                 ShouldAutoCycle="False"
                                                 local:BindingProxy.A="OverviewWeeklyDescriptionOverride"
                                                 local:ControllerButtonPanel.RThumbLeftRightDescription="{local:Loc HelpButtons.IDS_CycleChapters}"
                                                 local:FocusOnPageFocusGained.Self="True"/>

                        <Decorator Width="5"/>

                        <ContentControl x:Name="Dailies" DockPanel.Dock="Right" Template="{StaticResource A_ControlTemplate_SidePanel_ForzaEvents}" Tag="{local:Loc ForzaEvents.IDS_DailyChallenges}" Focusable="False">
                            <local:CommonListBox ItemsSource="{Binding DailyChallenges}"
                                Template="{StaticResource A_ControlTemplate_ChallengeList}"
                                ItemContainerStyle="{StaticResource A_Style_ListBoxItem_Event}"
                                ItemTemplate="{StaticResource A_DataTemplate_ForzaEvents_DailyChallenge}"
                                Background="{x:Null}"
                                BorderThickness="0"
                                BorderBrush="{x:Null}"
                                Focusable="False"/>
                        </ContentControl>

                        <Decorator Width="5"/>

                        <StackPanel x:Name="OverviewDetails" DockPanel.Dock="Left" Width="426" Panel.ZIndex="2">
                            <local:FZButton x:Name="ShopTile" 
                                            Style="{StaticResource A_Style_FZButton_ForzaEvents_ShopTile_Overview}" 
                                            Height="428" 
                                            DataContext="{Binding EventShop.Car}"
                                            ClickMode="Press"/>
                            <Decorator Height="5" />
                            <Control Template="{StaticResource A_ControlTemplate_ForzaEvents_BonusPanel}" DataContext="{Binding Bonus}"  Height="211" Focusable="False"/>
                            <Decorator Height="5" />
                            <Control Template="{StaticResource A_ControlTemplate_ForzaEvents_ForzaEventPointTotal}" Height="66" Focusable="False"/>
                        </StackPanel>
                    </StackPanel>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Page>
