<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_UpgradeBasket"
      mc:Ignorable="d"
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      >

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

    <Page.Resources>
        <ResourceDictionary>
            <local:LinearTransformConverter x:Key="A_LinearTransformConverter_ItemIndexOffset" Add="1" />
            
            <Double x:Key="A_Double_ItemIndex_BoxWidth">50</Double>
            <Double x:Key="A_Double_ItemText_BoxWidth">1000</Double>
            <Thickness x:Key="A_Margin_Index_BoxSpacing">5,0,0,0</Thickness>
            <Double x:Key="A_Double_ListBox_Height">656</Double>

            <Style x:Key="A_Style_ListBoxItem_TextMenu_Container" TargetType="{Type ListBoxItem}"
                BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_NoGaps}">
                <Setter Property="Margin" Value="0,2,0,0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type 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>
                                </ResourceDictionary>
                            </ControlTemplate.Resources>
                            <Grid>
                                <StackPanel>
                                    <Grid x:Name="Background">
                                        <RoutedEventCommand
                                            x:Name="MouseLeftButtonUpCommand"
                                            RoutedEvent="UIElement.MouseLeftButtonUp"
                                            Style="{StaticResource A_Style_RoutedEventCommand_MouseLeftButtonUp}" />
                                        <StackPanel Orientation="Horizontal">
                                            <FZMaterial x:Name="RowBoxBackgroundMaterial"
                                                        Style="{StaticResource A_Style_FZMaterial_GlassPanel_Pill_NonInteractive}"
                                                        RoutedEventCommand.Action="{Binding ElementName=MouseLeftButtonUpCommand}"
                                                        Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll2px}" 
                                                        Color="{StaticResource H_Color_Glass_Purple_60pc}" 
                                                        Width="{StaticResource A_Double_ItemIndex_BoxWidth}"/>      
                                            <FZMaterial x:Name="BackgroundMaterial"
                                                        Width="{StaticResource A_Double_ItemText_BoxWidth}"
                                                        RoutedEventCommand.Action="{Binding ElementName=MouseLeftButtonUpCommand}"
                                                        Style="{StaticResource A_Style_FZMaterial_FlatPanel_Tile}"
                                                        Preset="{StaticResource H_Roundtangle_Outer_1px}"
                                                        Color="{StaticResource H_Color_Primary_White}" 
                                                        Margin="{StaticResource A_Margin_Index_BoxSpacing}">

                                                <StrokeHighlightControl Style="{StaticResource H_Style_StrokeHighlight_Instant_TextMenu}"
                                                                        ZPanel.DisableClipping="True"
                                                                        InnerThickness="3"
                                                                        OuterThickness="3"
                                                                        IsEnabled="{TemplateBinding IsKeyboardFocusWithin}"/>
                                            </FZMaterial>
                                        </StackPanel>
                                        <ContentPresenter
                                            Focusable="{Binding Focusable, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                            x:Name="Presenter"
                                            PropertySetter.Value="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Self}}"
                                            PropertySetter.Property="Content.(FocusSelf.WhenTrue)"/>
                                    </Grid>
                                </StackPanel>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger
                                    Property="IsKeyboardFocused"
                                    Value="True">
                                    <Setter
                                        TargetName="Presenter"
                                        Property="FocusSelf.WhenTrue"
                                        Value="True" />
                                </Trigger>
                                <Trigger
                                    Property="IsKeyboardFocusWithin"
                                    Value="True">
                                    <Setter
                                        Property="Color"
                                        TargetName="BackgroundMaterial"
                                        Value="{StaticResource H_Color_HighlightedItemBg}" />
                                    <Setter
                                        Property="Color"
                                        TargetName="RowBoxBackgroundMaterial" 
                                        Value="{StaticResource H_Color_Primary_White}" />
                                </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>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="A_Style_Control_EmptyItemStyle" TargetType="Control">
                <Setter Property="Focusable"
                        Value="False"/>
                <Setter Property="Height"
                        Value="50"/>
                <Setter
                    Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Control">
                            <Grid>
                                <StackPanel Orientation="Horizontal">
                                    <Grid Width="{StaticResource A_Double_ItemIndex_BoxWidth}">
                                        <FZMaterial
                                            Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll2px}"
                                            Color="{StaticResource H_Color_Glass_Purple_60pc}" />
                                    </Grid>
                                    <Grid Width="{StaticResource A_Double_ItemText_BoxWidth}"
                                        Margin="{StaticResource A_Margin_Index_BoxSpacing}">
                                        <FZMaterial
                                            Preset="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll2px}"
                                            Color="{StaticResource H_Color_Glass_Purple_60pc}" />
                                    </Grid>
                                </StackPanel>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <DataTemplate x:Key="A_DataTemplate_ListBoxItem_BasketItem">
                <Grid>
                    <StackPanel Orientation="Horizontal">
                        <Grid Width="{StaticResource A_Double_ItemIndex_BoxWidth}">
                            <FZTextBlock x:Name="Index"
                                         Tag="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource FindAncestor, AncestorType=ListBoxItem}, Converter={StaticResource A_LinearTransformConverter_ItemIndexOffset}}"
                                         Text="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource A_NumUnitConverter_Min2Digits_0dp}}"
                                         FontFamily="Horizon_A"
                                         CapHeight="22"
                                         Margin="0,14"
                                         HorizontalAlignment="Center">
                                <FZTextBlock.Style>
                                    <Style TargetType="{x:Type FZTextBlock}" BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}">
                                        <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}"/>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                                                         Value="True">
                                                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Black}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </FZTextBlock.Style>
                            </FZTextBlock>
                        </Grid>
                        <Grid x:Name="TextGrid" 
                              Width="{StaticResource A_Double_ItemText_BoxWidth}"
                              Margin="{StaticResource A_Margin_Index_BoxSpacing}">
                            <local:FZTextBlock
                                Text="{Binding Text}"
                                Style="{StaticResource A_Style_FZTextBlock_OptionText}"
                                FontFamily="Horizon_B"
                                CapHeight="18"
                                HorizontalAlignment="Left"/>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <Control Style="{StaticResource H_Style_Control_CreditsIcon}" Margin="10, 10, -18, 10"/>
                                <local:FZTextBlock CapHeight="18">
                                    <local:FZTextBlock.Style>
                                        <Style TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}">
                                            <Setter Property="Text" Value="{Binding CreditCost, ConverterParameter=money, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}, FallbackValue=0}"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding CreditCost}" Value="0">
                                                    <Setter Property="Text" Value="{local:Loc InGameMarketplace.IDS_Free}" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </local:FZTextBlock.Style>
                                </local:FZTextBlock>
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </Grid>
            </DataTemplate>

            <ControlTemplate x:Key="A_ControlTemplate_Row"
                             TargetType="ListBoxItem">
                <Grid>
                    <ContentControl Style="{StaticResource A_Style_ContentControl_SelectableRow}">
                        <ContentPresenter />
                    </ContentControl>
                </Grid>
            </ControlTemplate>

            <Style x:Key="A_Style_FZTextBlock_BasketSummary"
                   BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}"
                   TargetType="local:FZTextBlock">
                <Setter Property="Margin"
                        Value="25,0" />
                <Setter Property="Color"
                        Value="{StaticResource H_Color_Primary_Black}" />
            </Style>
        </ResourceDictionary>
    </Page.Resources>

    <Grid>
        <Grid>
            <!-- Background Blur -->
            <local:FZMaterialGlassCapture />
            <local:FZMaterial Style="{StaticResource A_Style_FZMaterial_Popup_Background}"/>

            <!-- Help Button Bar -->
            <ContentControl x:Name="BottomBar"
                            Style="{StaticResource A_Style_ButtonBar}">
                <ContentControl x:Name="PART_DefaultHelpPanel"
                                local:ControllerButtonPanel.ADescription="{local:Loc HelpButtons.IDS_Goto}"
                                local:ControllerButtonPanel.BDescription="{local:Loc HelpButtons.IDS_Back}"
                                local:ControllerButtonPanel.StartDescription="{local:Loc HelpButtons.IDS_CheckOutNow}"
                                Style="{StaticResource A_Style_ContentControl_DefaultButtonBar}" />
            </ContentControl>
        </Grid>

        <Grid Style="{StaticResource A_Style_FrameworkElement_LayoutRoot}"
              Focusable="False">
            <StackPanel x:Name="MainContent"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        Style="{StaticResource A_Style_FrameworkElement_DefaultTransition_0}">

                <ContentControl Content="{Binding ScreenTitle}"
                                Style="{StaticResource A_Style_ContentControl_ScreenTitleBlock}"
                                local:BindingProxy.A="/ForzaUI;component/Textures/Anthem/Icons/Garage/Basket.png"
                                HorizontalAlignment="Left" 
                                Margin="55,0,0,0"/>
                <DockPanel>
                    <StackPanel
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        DockPanel.Dock="Left">
                        <ContentControl Style="{StaticResource A_Style_ContentControl_Header_Custom}"
                                        HorizontalAlignment="Right"
                                        Width="{StaticResource A_Double_ItemText_BoxWidth}"
                                        Height="50"
                                        Margin="0,10,0,5"
                                        HorizontalContentAlignment="Stretch">
                            <DockPanel>
                                <FZTextBlock Style="{StaticResource A_Style_FZTextBlock_BasketSummary}"
                                             Text="{Loc Upgrades_flow.IDS_BasketItemName}"
                                             DockPanel.Dock="Left"/>
                                <FZTextBlock Style="{StaticResource A_Style_FZTextBlock_BasketSummary}"
                                             Text="{local:Loc Upgrades_flow.IDS_BasketCost}"
                                             DockPanel.Dock="Right"
                                             HorizontalAlignment="Right"
                                             TextAlignment="Right"/>
                            </DockPanel>
                        </ContentControl>
                        <StackPanel DataContext="{Binding Basket}">
                            <WrapListBox
                                x:Name="PART_Menu"
                                DockPanel.Dock="Left"
                                HorizontalAlignment="Right"
                                Width="1055"
                                Template="{StaticResource H_ControlTemplate_TextMenu_Default}"
                                ScrollOrientation="Vertical"
                                Height="{StaticResource A_Double_ListBox_Height}"
                                Margin="0"
                                ItemHeight="55"
                                ItemWidth="1055"
                                AlternationCount="10000"
                                ItemsSource="{Binding BasketItems}"
                                EmptyItemStyle="{StaticResource A_Style_Control_EmptyItemStyle}"
                                ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_Container}"
                                ItemTemplate="{StaticResource A_DataTemplate_ListBoxItem_BasketItem}" />

                                <ContentControl Style="{StaticResource A_Style_ContentControl_Header_Custom}"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Center"
                                        Width="{StaticResource A_Double_ItemText_BoxWidth}"
                                        Height="50"
                                        HorizontalContentAlignment="Stretch"
                                        Margin="0,5,0,0">
                                    <StackPanel Orientation="Horizontal"
                                        HorizontalAlignment="Right">
                                    <local:FZTextBlock Text="{local:Loc Upgrades_flow.IDS_BasketItemsTotal}"
                                                           Style="{StaticResource A_Style_FZTextBlock_BasketSummary}"
                                                           Margin="0,0,6,0"/>
                                    <Control Style="{StaticResource H_Style_Control_CreditsIcon}" Margin="-4,-4,6,-4"/>
                                    <local:FZTextBlock Margin="0,0,24,0">
                                            <local:FZTextBlock.Style>
                                                <Style TargetType="local:FZTextBlock" BasedOn="{StaticResource A_Style_FZTextBlock_BasketSummary}">
                                                    <Setter Property="Text" Value="{Binding TotalCreditCost, ConverterParameter=money, Converter={StaticResource A_NumUnitConverter_NoUnit_0dp}, FallbackValue=0}"/>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding TotalCreditCost}" Value="0">
                                                            <Setter Property="Text" Value="{local:Loc InGameMarketplace.IDS_Free}" />
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </local:FZTextBlock.Style>
                                        </local:FZTextBlock>
                                        <StackPanel Orientation="Horizontal"
                                            Visibility="{Binding AreTokensEnabled, Source={StaticResource PART_UISceneContext}, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                                            <local:FZTextBlock Text="/"
                                                       Style="{StaticResource A_Style_FZTextBlock_BasketSummary}"
                                                       Margin="6,0,6,0" />
                                            <local:FZTextBlock Text="{Binding TotalTokenCost, ConverterParameter=tokenmoney, Converter={StaticResource A_NumUnitConverter_ShowUnit_0dp}, FallbackValue=0}"
                                                       Style="{StaticResource A_Style_FZTextBlock_BasketSummary}" />
                                        </StackPanel>
                                    </StackPanel>
                                </ContentControl>
                        </StackPanel>
                    </StackPanel>
                    <ScrollBar
                            Margin="8,0,0,0"
                            Height="{StaticResource A_Double_ListBox_Height}"
                            Style="{StaticResource A_Style_ScrollBar_TextMenu}"
                            Minimum="{Binding ScrollWindowMin, ElementName=PART_Menu}"
                            Maximum="{Binding ScrollWindowMax, ElementName=PART_Menu}"
                            Value="{Binding ScrollWindowValue, ElementName=PART_Menu, Mode=TwoWay}"
                            ViewportSize="{Binding ScrollWindowSize, ElementName=PART_Menu}"
                            Visibility="{Binding ComputedVerticalScrollBarVisibility, ElementName=PART_Menu}"
                            DockPanel.Dock="Right" >
                            <DynamicData.Data>
                                <DynamicDataItem
                                    Name="ScrollBarHideWhenNotNeeded"
                                    DataType="Boolean"
                                    Value="True" />
                            </DynamicData.Data>            
                        </ScrollBar>
                </DockPanel>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
