<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ForzaUI.Scenes.Anthem.A_MessageBox"
    Style="{StaticResource A_Style_Page_Generic}"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <UIPageTransitionManager.TransitionManager>
        <UIPageTransitionManager
            Preset="{StaticResource A_UIPageTransitionManagerPreset_Popup}" />
    </UIPageTransitionManager.TransitionManager>
    <Page.Resources>
        <ResourceDictionary>
            <Style
                x:Key="A_Style_FZTextBlock_MessageBox_Text"
                BasedOn="{StaticResource A_Style_FZTextBlock_PopupText}"
                TargetType="local:FZTextBlock">
                <Setter
                    Property="Width"
                    Value="Auto" />
                <Setter
                    Property="Margin"
                    Value="0,0,0,12" />
                <Style.Triggers>
                    <Trigger
                        Property="Text"
                        Value="{Null}">
                        <Setter
                            Property="Visibility"
                            Value="Collapsed" />
                    </Trigger>
                    <Trigger
                        Property="Text"
                        Value="">
                        <Setter
                            Property="Visibility"
                            Value="Collapsed" />
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_ContentControl_MessageBoxPopupContentBlock"
                   TargetType="ContentControl"
                   BasedOn="{StaticResource A_Style_ContentControl_PopupContentBlock}">
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding HasImage}" Value="False" />
                            <Condition Binding="{Binding HasMessage}" Value="False" />
                        </MultiDataTrigger.Conditions>
                        <MultiDataTrigger.Setters>
                            <Setter Property="Visibility" Value="Collapsed" />
                        </MultiDataTrigger.Setters>
                    </MultiDataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZMaterial_Image"
                   TargetType="FZMaterial">
                <Setter Property="Height" Value="240" />
                <Setter Property="Width" Value="240" />
                <Setter Property="Margin" Value="{Binding ImageMargin}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsCarThumbnail}" Value="True">
                        <Setter Property="Height" Value="300" />
                        <Setter Property="Width" Value="534" />
                        <Setter Property="Margin" Value="0,-40,0,0" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding LargeImage}" Value="True">
                        <Setter Property="Height" Value="auto" />
                        <Setter Property="Width" Value="auto" />
                        <Setter Property="Stretch" Value="Uniform" />
                        <Setter Property="GreedyMeasure" Value="True" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style
                x:Key="A_Style_ListBoxItem_TextMenu_Default_MessageBox"
                BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_Default}"
                TargetType="{Type ListBoxItem}">
                <Setter
                    Property="Template">
                    <Setter.Value>
                        <ControlTemplate
                            TargetType="ListBoxItem">
                            <ControlTemplate.Resources>
                                <ResourceDictionary>
                                    <Style
                                        x:Key="A_Style_RoutedEventCommand_MouseLeftButtonUp"
                                        TargetType="local:RoutedEventCommand">
                                        <Setter
                                            Property="Command"
                                            Value="{Binding ItemFuncCommand}" />
                                        <Style.Triggers>
                                            <DataTrigger
                                                Binding="{Binding ItemFuncCommand}"
                                                Value="{Null}">
                                                <Setter
                                                    Property="Command"
                                                    Value="{Binding SelectCommand, RelativeSource={RelativeSource AncestorType={Type Page}}}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                    <Style
                                        x:Key="H_Style_Selected_Shadow_MessageBox"
                                        BasedOn="{StaticResource H_Style_Selected_Shadow}"
                                        TargetType="{Type FZMaterial}">
                                        <Setter Property="Color" Value="#66000000" />
                                    </Style>
                                </ResourceDictionary>
                            </ControlTemplate.Resources>
                            <Grid>
                                <FZMaterial x:Name="SelectedShadow"
                                            Style="{StaticResource H_Style_Selected_Shadow_MessageBox}" />
                                <Grid
                                    x:Name="Background"
                                    RenderTransformOrigin="0.5,0.5">
                                    <Grid.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform />
                                        </TransformGroup>
                                    </Grid.RenderTransform>
                                    <RoutedEventCommand
                                        x:Name="MouseLeftButtonUpCommand"
                                        RoutedEvent="UIElement.MouseLeftButtonUp"
                                        Style="{StaticResource A_Style_RoutedEventCommand_MouseLeftButtonUp}" />
                                    <FZMaterial
                                        x:Name="BackgroundMaterial"
                                        RoutedEventCommand.Action="{Binding ElementName=MouseLeftButtonUpCommand}"
                                        Style="{StaticResource A_Style_FZMaterial_FlatPanel_Tile}"
                                        Preset="{StaticResource H_Roundtangle_Outer_2px}"
                                        Color="{StaticResource H_Color_Primary_White}" />
                                    <ContentPresenter
                                        Focusable="{Binding Focusable, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                        x:Name="Presenter"
                                        PropertySetter.Value="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}"
                                        PropertySetter.Property="Content.(FocusSelf.WhenTrue)"/>
                                    <StrokeHighlightControl Style="{StaticResource H_Style_StrokeHighlight_Instant_TextMenu}"
                                                            ContentRadius="2"
                                                            IsEnabled="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource TemplatedParent}}"/>
                                </Grid>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger
                                    Property="IsKeyboardFocused"
                                    Value="True">
                                    <Setter
                                        TargetName="Presenter"
                                        Property="FocusSelf.WhenTrue"
                                        Value="True" />
                                </Trigger>
                                <Trigger
                                    Property="Tag"
                                    Value="GroupHeader">
                                    <Setter
                                        Property="Visibility"
                                        TargetName="BackgroundMaterial"
                                        Value="Collapsed" />
                                </Trigger>
                                <Trigger
                                    Property="Tag"
                                    Value="Inactive">
                                    <Setter
                                        TargetName="BackgroundMaterial"
                                        Property="Preset"
                                        Value="{StaticResource H_GlassRoundtangle_1px}" />
                                    <Setter
                                        TargetName="BackgroundMaterial"
                                        Property="Color"
                                        Value="{StaticResource H_Color_Glass_Purple_20pc}" />
                                </Trigger>
                                <Trigger
                                    Property="IsEnabled"
                                    Value="False">
                                    <Setter
                                        TargetName="BackgroundMaterial"
                                        Property="Preset"
                                        Value="{StaticResource H_GlassRoundtangle_1px}" />
                                    <Setter
                                        TargetName="BackgroundMaterial"
                                        Property="Color"
                                        Value="{StaticResource H_Color_Glass_Purple_20pc}" />
                                </Trigger>
                                <Trigger
                                    Property="IsSelected"
                                    Value="True">
                                    <Trigger.EnterActions>
                                        <BeginStoryboard
                                            x:Name="ShowSelected_BeginStoryboard1"
                                            Storyboard="{StaticResource A_StoryBoard_TextMenu_Focus}" />
                                    </Trigger.EnterActions>
                                    <Trigger.ExitActions>
                                        <BeginStoryboard
                                            x:Name="ShowSelected_BeginStoryboard2"
                                            Storyboard="{StaticResource A_StoryBoard_TextMenu_Blur}" />
                                    </Trigger.ExitActions>
                                    <Setter
                                        Property="Color"
                                        TargetName="BackgroundMaterial"
                                        Value="{StaticResource H_Color_HighlightedItemBg}" />
                                    <Setter
                                        Property="Opacity"
                                        TargetName="SelectedShadow"
                                        Value="1"/>
                                </Trigger>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition
                                            Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}"
                                            Value="True" />
                                        <Condition
                                            Binding="{Binding (ItemContainerGenerator.ItemForItemContainer), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_IsNotNull}}"
                                            Value="True" />
                                    </MultiDataTrigger.Conditions>
                                    <Setter
                                        Property="IsSelected"
                                        Value="True" />
                                </MultiDataTrigger>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition
                                            Binding="{Binding Focusable, RelativeSource={RelativeSource Self}}"
                                            Value="False" />
                                        <Condition
                                            Binding="{Binding Tag, RelativeSource={RelativeSource Self}}"
                                            Value="{Null}" />
                                    </MultiDataTrigger.Conditions>
                                    <Setter
                                        TargetName="BackgroundMaterial"
                                        Property="Visibility"
                                        Value="Collapsed" />
                                </MultiDataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>   
            </Style>
            <AutoScrollSettings x:Key="A_AutoScrollSettings_OptionText"
                ScrollSeparation="50"
                InitialPause="0:0:0.5"
                Speed="40"
                ScrollOrientation="Horizontal"/>

            <Style x:Key="A_Style_FZTextBlock_AutoScroll"
                BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}"
                TargetType="FZTextBlock">
                <Setter Property="MaxWidth" Value="630" />
                <Setter Property="TextWrapping" Value="NoWrap" />
                <Setter Property="Stretch" Value="None" />
                <Setter Property="TextAlignment" Value="Center" />
                <Setter Property="AutoScroll.AllowScrolling" Value="True" />
                <Setter Property="AutoScroll" Value="{StaticResource A_AutoScrollSettings_OptionText}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorLevel=2, AncestorType=ListBoxItem}}" Value="True">
                        <Setter Property="Color" Value="{StaticResource A_Color_ListItemText_Focused}" />
                        <Setter Property="MaxWidth" Value="infinity"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
            <AutoScrollSettings x:Key="A_AutoScrollSettings_MessageText" 
                ScrollSeparation="50"
                InitialPause="0"
                Speed="20"
                ScrollOrientation="Vertical"/>
            <Style x:Key="A_Style_FZTextBlock_AutoScroll_Message"
                BasedOn="{StaticResource H_Style_Text_Description_Body_16px_Scrolling}"
                TargetType="FZTextBlock">
            </Style>
            <DataTemplate
                x:Key="A_DataTemplate_TextMenu_Default_MessageBox">
                <StackPanel
                    x:Name="ButtonContent"
                    HorizontalAlignment="Center"
                    Orientation="Horizontal"
                    VerticalAlignment="Center"
                    IsHitTestVisible="False"
                    Height="{StaticResource A_Double_TextMenu_Height_Default}">
                        <FZMaterial x:Name="Icon"
                                    ImageSourceNoPreload="{Binding IconPath}"
                                    Width="40"
                                    Height="40"
                                    Margin="20,0,0,0"
                                    HorizontalAlignment="Left"
                                    Color="{StaticResource H_Color_Primary_Black}"
                                    Visibility="{Binding IconPath, Converter={StaticResource A_StringVisConverter}, FallbackValue=Collapsed}"/>
                        <FZTextBlock 
                            x:Name="AutoScrollTextBlock"
                            Style="{StaticResource A_Style_FZTextBlock_AutoScroll}"
                            Text="{Binding Text}"
                            ScreenReader.Event="OnChange"
                            ScreenReader.ControlType="Button"
                            ScreenReader.LineType="SelectedItem"
                            ScreenReader.SelectedNumber="{Binding (ItemsControl.AlternationIndex), FallbackValue=0, RelativeSource={RelativeSource AncestorType={Type ListBoxItem}}, Converter={StaticResource A_IndexToNumberConverter}}"
                            ScreenReader.SelectedCount="{Binding Items.Count, FallbackValue=0, RelativeSource={RelativeSource AncestorType={Type Selector}}}"
                            MarkupConverter="{StaticResource A_MappingConverter_TextMenu}"/>
                </StackPanel>
                <DataTemplate.Triggers>
                    <DataTrigger
                        Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                        Value="True">
                        <Setter
                            TargetName="AutoScrollTextBlock"
                            Property="local:ScreenReader.Line"
                            Value="{Binding Text, Converter={StaticResource A_Converter_TrimInlineMarkup}}" />
                        <Setter
                            TargetName="Icon"
                            Property="Color"
                            Value="{StaticResource H_Color_Primary_White}"/>
                    </DataTrigger>
                    <DataTrigger
                        Binding="{Binding ElementName=Icon, Path=Visibility}"
                        Value="{x:Static Visibility.Visible}">
                        <Setter
                            TargetName="ButtonContent"
                            Property="HorizontalAlignment"
                            Value="Left"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </Page.Resources>
    <Grid>
        <FZMaterialGlassCapture />
        <FZMaterial
            Style="{StaticResource A_Style_FZMaterial_Popup_Background}" />
        <FZMaterialGlassCapture />
        <ContentControl
            x:Name="BottomBar"
            Style="{StaticResource A_Style_ButtonBar}">
            <ControllerButtonPanel
                x:Name="PART_HelpPanel"
                Layout="RightToLeft"
                HorizontalAlignment="Left"
                VerticalAlignment="Bottom"
                Background="{Null}" />
        </ContentControl>
        <Grid
            Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}">
            <DockPanel
                x:Name="MainContent"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}"
                Width="{StaticResource H_Width_PopUp}">
                <ContentControl DockPanel.Dock="Top"
                    Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"
                    Content="{Binding Title}" />
                <ContentControl  DockPanel.Dock="Top"
                    Style="{StaticResource A_Style_ContentControl_MessageBoxPopupContentBlock}"
                    Margin="0">
                    <StackPanel>
                        <Decorator Height="24" Visibility="{Binding HasMessage, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}" />
                        <Grid>
                            <FZMaterial ImageSource="/ForzaUI;component/Textures/Anthem/DotPatternA.png"
                                        GetSizeFromTexture="True"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        Visibility="{Binding IsCarThumbnail, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
                            <FZMaterial x:Name="Image"
                                        Style="{StaticResource A_Style_FZMaterial_Image}"
                                        ImageSource="{Binding Image}" 
                                        Visibility="{Binding HasImage, Converter={StaticResource A_FZBooleanToVisibilityConverter}, FallbackValue=Collapsed}" />
                        </Grid>
                        <Grid>
                            <ItemsControl ItemsSource="{Binding PossibleMessages}">
                                <ItemsControl.Template>
                                    <ControlTemplate TargetType="ItemsControl">
                                        <Grid IsItemsHost="True" Visibility="Hidden"/>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <FZTextBlock 
                                            Style="{StaticResource A_Style_FZTextBlock_AutoScroll_Message}"
                                            Margin="24"
                                            Text="{Binding}"
                                            MarkupConverter="{StaticResource A_MappingConverter_Popup}"/>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                            <FZTextBlock 
                                Visibility="{Binding HasMessage, Converter={StaticResource A_FZBooleanToVisibilityConverter}}"
                                Style="{StaticResource A_Style_FZTextBlock_AutoScroll_Message}"
                                Margin="24"
                                MultiStringFormatter.Format="{Binding ScreenReaderMessage, Converter={StaticResource A_Converter_PopupMarkupSubstitution}}"
                                ScreenReader.Line="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}, Converter={StaticResource A_Converter_TrimInlineMarkup}}"
                                ScreenReader.Event="OnChange"
                                ScreenReader.LineType="ScreenDescription"
                                Text="{Binding Message}"
                                MarkupConverter="{StaticResource A_MappingConverter_Popup}"/>
                        </Grid>
                        <Decorator Height="24" Visibility="{Binding HasMessage, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}" />
                    </StackPanel>
                </ContentControl>
                <CommonListBox x:Name="PART_Menu"
                               MaxHeight="676"
                               Style="{StaticResource A_Style_ListBox_TextMenu_Default}"
                               ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_Default_MessageBox}"
                               ItemTemplate="{StaticResource A_DataTemplate_TextMenu_Default_MessageBox}"
                               ItemsSource="{Binding Options}" />
            </DockPanel>
        </Grid>
    </Grid>
</Page>