<Page 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;assembly="
      x:Class="ForzaUI.Scenes.Anthem.A_Rewind"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={x:Static RelativeSource.Self}}">

    <Page.Resources>
        <BooleanToVisibilityConverter x:Key="BoolVisConverter"/>
        
        <Storyboard x:Key="Outro">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_LayoutRoot">
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="OutroComplete">
                <DiscreteBooleanKeyFrame KeyTime="0:0:1.0" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
        </Storyboard>

        <Style x:Key="A_Style_FZTextBlock_Rewinding" TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_HeaderBlock}" >
            <Setter Property="Color"
                    Value="{StaticResource A_Color_SubHeader_Text}" />
            <Setter Property="FontSize" Value="36" />
            <Setter Property="Margin"
                    Value="0,0,8,0" />
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_KeyboardOnly"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_Default}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="True">
                    <Setter Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_ControllerOnly"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_Default}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsControllerActiveInput, RelativeSource={RelativeSource AncestorType=Page}}"
                             Value="False">
                    <Setter Property="Visibility"
                            Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_RewindButtonController"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_ControllerOnly}">
            <Setter Property="Visibility"
                    Value="{Binding CanRewindFurther, Converter={StaticResource BoolVisConverter}}" />
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_RewindButtonKeyboard"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_KeyboardOnly}">
            <Setter Property="Visibility"
                    Value="{Binding CanRewindFurther, Converter={StaticResource BoolVisConverter}}" />
            <Setter Property="InputOverride"
                    Value="{local:Input Command=INPUTCMD_MULLIGAN, Context=INPUTCONTEXT_UI}" />
            <Setter Property="SupportsControllerInput"
                    Value="False" />
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_ViewReplayButtonController"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_ControllerOnly}">
            <Setter Property="Visibility"
                    Value="{Binding EnableReplayButton, Converter={StaticResource BoolVisConverter}}" />
        </Style>

        <Style x:Key="A_Style_ControllerButtonControl_ViewReplayButtonKeyboard"
               TargetType="local:ControllerButtonControl"
               BasedOn="{StaticResource A_Style_ControllerButtonControl_KeyboardOnly}">
            <Setter Property="Visibility"
                    Value="{Binding EnableReplayButton, Converter={StaticResource BoolVisConverter}}" />
        </Style>
		
        <Style x:Key="A_Style_FrameworkElement_BusyIndicatorContainer"
               TargetType="FrameworkElement">
            <Setter Property="Visibility"
                    Value="Collapsed" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsRewinding}" Value="True">
					<Setter Property="Visibility"
                            Value="Visible" />
				</DataTrigger>
				<DataTrigger Binding="{Binding ShouldShowSpinner}" Value="True">
					<Setter Property="Visibility"
                            Value="Visible" />
				</DataTrigger>
            </Style.Triggers>
        </Style>

    </Page.Resources>

    <Grid x:Name="PART_LayoutRoot">
        <!-- Help Button Bar -->
        <ContentControl x:Name="HelpButtonBar" Style="{StaticResource A_Style_ButtonBar}" Visibility="{Binding IsRewinding, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}">
            <Grid>
                <local:RoutedEventCommand x:Name="RewindFurtherRoutedEventCommand"
                                          RoutedEvent="UIElement.MouseLeftButtonUp"
                                          Command="{Binding RewindCommand, RelativeSource={RelativeSource AncestorType=Page}}" />
                <local:ControllerButtonPanel x:Name="PART_HelpPanel">
                    <local:ControllerButtonControl Button="{Binding AcceptButton}"
                                                   Description="{local:Loc HelpButtons.IDS_Resume_From_Here}" />

                    <!-- Controller Group -->
                    <local:ControllerButtonControl Button="{Binding RewindButton}"
                                                   Description="{local:Loc HelpButtons.IDS_Rewind_Further}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_RewindButtonController}"/>
                    <local:ControllerButtonControl Button="{Binding CancelButton}"
                                                   Description="{local:Loc HelpButtons.IDS_Discard}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_ControllerOnly}" />
                    <local:ControllerButtonControl Button="{Binding ViewReplayButton}"
                                                   Description="{local:Loc InGame.IDS_ViewReplay}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_ViewReplayButtonController}"/>

                    <!-- Keyboard Group -->
                    <local:ControllerButtonControl Description="{local:Loc HelpButtons.IDS_Rewind_Further}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_RewindButtonKeyboard}"
                                                   local:RoutedEventCommand.Action="{Binding ElementName=RewindFurtherRoutedEventCommand}" />
                    <!-- Back is always B on keyboard -->
                    <local:ControllerButtonControl Button="B"
                                                   Description="{local:Loc HelpButtons.IDS_Discard}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_KeyboardOnly}" />
                    <local:ControllerButtonControl Button="{Binding ViewReplayButtonKeyboard}" Description="{local:Loc InGame.IDS_ViewReplay}"
                                                   Style="{StaticResource A_Style_ControllerButtonControl_ViewReplayButtonKeyboard}" />
                </local:ControllerButtonPanel>
            </Grid>
        </ContentControl>

        <!-- Rewinding Spinner -->
        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}" Margin="132,0,0,100">
            <StackPanel x:Name="StackPanel_WaitSpinner" Orientation="Horizontal"
                        HorizontalAlignment="Left" VerticalAlignment="Bottom" Opacity="1" Style="{StaticResource A_Style_FrameworkElement_BusyIndicatorContainer}">
                <ProgressBar x:Name="BusyIndicator"
                             IsIndeterminate="True"
                             Style="{StaticResource A_Style_ProgressBar_WaitSpinner_Reverse}"
                             Width="56"
                             Height="56"/>
                <local:FZTextBlock x:Name="TextBlock_Rewinding" Margin="12,0,0,0" Text="{local:Loc HelpButtons.IDS_Rewinding}" Style="{StaticResource A_Style_FZTextBlock_Rewinding}"/>
            </StackPanel>
        </Grid>
    </Grid>
    
    <local:EventFire.FzTriggers>
        <local:EventFireTrigger Event="Outro" Storyboard="{StaticResource Outro}"/>
    </local:EventFire.FzTriggers>
</Page>
