<Page x:Class="ForzaUI.A_FollowedPlayers"
      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"
      mc:Ignorable="d"
      xmlns:local="clr-namespace:ForzaUI;assembly="
      Style="{StaticResource A_Style_Page_Generic}"
      DataContext="{Binding RelativeSource={RelativeSource Self}}"
      xmlns:System="clr-namespace:System;assembly=mscorlib">
    <Page.Resources>
        <ResourceDictionary>
            <Size x:Key="A_Size_GamerPicSizeParams">64,64</Size>

            <ControlTemplate x:Key="A_Template_UserGamerPic">
                <local:FZMaterial x:Name="GamerPicMaterial"
                                  Stretch="UniformToFill"
                                  Height="32" Width="32"
                                  ImageSource="{Binding UserProfile, Converter={StaticResource A_GamerPicConverter}, ConverterParameter={StaticResource A_Size_GamerPicSizeParams}}">
                    <ProgressBar x:Name="IdleIndicator"
		                         IsIndeterminate="True"
                                 Height="26" Width="26"
                                 Visibility="{Binding Downloaded, ElementName=GamerPicMaterial, Converter={StaticResource A_FZBooleanToVisibilityConverter_Inverse}}"
		                         Style="{StaticResource A_Style_ProgressBar_WaitSpinnerDark}"/>           
                    <FZMaterial.Preset>
                        <FZMaterialPresetRoundtangle CornerRadius="16"/>
                    </FZMaterial.Preset>
                </local:FZMaterial>
            </ControlTemplate>
            
            <ControlTemplate x:Key="A_Template_UserGamerPic_Empty">
                <Grid>
                    <local:FZMaterial Height="32" Width="32"
                                  Color="{StaticResource H_Color_Glass_Purple_40pc}">
                        <FZMaterial.Preset>
                            <FZMaterialPresetRoundtangle CornerRadius="16"/>
                        </FZMaterial.Preset>
                    </local:FZMaterial>
                    <Border BorderBrush="White" BorderThickness="2.5" Width="32" Height="32" CornerRadius="16" />
                </Grid>
            </ControlTemplate>

            <DataTemplate x:Key="A_DataTemplate_UserItem">
                <DockPanel Margin="10">
                    <Control Template="{StaticResource A_Template_UserGamerPic}" />
                    <Decorator HorizontalAlignment="Right"
                               DockPanel.Dock="Right" 
                               Margin="0,0,24,0"
                               Visibility="{Binding IsSelected, Converter={StaticResource A_FZBooleanToVisibilityConverter}}">
                        <Control x:Name="CheckBox"
                                 VerticalAlignment="Center"
                                 Style="{StaticResource A_Style_Control_Checkbox}"
                                 Tag="{Binding IsSelected}" />
                    </Decorator>
                    <local:FZTextBlock DockPanel.Dock="Left"  
                                       Text="{Binding UserProfile.FormattedGamertag}" 
                                       Style="{StaticResource A_Style_FZTextBlock_OptionText}"
                                       HorizontalAlignment="Left" />
                </DockPanel>
            </DataTemplate>

            <DataTemplate x:Key="A_DataTemplate_SelectedUserItem">
                <Control Template="{StaticResource A_Template_UserGamerPic}" />
            </DataTemplate>

            <Style x:Key="A_Style_ContentControl_ButtonBar_UserPicker"
                   TargetType="ContentControl"
                   BasedOn="{StaticResource A_Style_ContentControl_DefaultButtonBar}">
                <Setter Property="local:ControllerButtonPanel.BDescription" Value="{local:Loc HelpButtons.IDS_Back}" />
                <Setter Property="local:ControllerButtonPanel.StartDescription" Value="{x:Null}" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSearching}" Value="True">
                        <Setter Property="local:ControllerButtonPanel.BDescription" Value="{local:Loc Main.IDS_ResetSearch}" />
                    </DataTrigger>
                    <DataTrigger LogicalOp="NotEquals" Binding="{Binding SelectedCollection.Count}" Value="0">
                        <Setter Property="local:ControllerButtonPanel.StartDescription" Value="{local:Loc Convoy.IDS_UserPickerPopup_Send}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FrameworkElement_HiddenWithEmptyCollection"
                   TargetType="{x:Type FrameworkElement}">
                <Setter Property="Visibility" Value="Visible"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Collection.Count}" Value="0">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_UserPickerText"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_OptionText}">
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_White}"/>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_UserPicker_SearchText"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_UserPickerText}">
                <Setter Property="Visibility" Value="Collapsed"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSearching}" Value="True">
                        <Setter Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="A_Style_FZTextBlock_NoResultText"
                   TargetType="local:FZTextBlock"
                   BasedOn="{StaticResource A_Style_FZTextBlock_UserPickerText}">
                <Setter Property="Visibility" Value="Collapsed"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Collection.Count}" Value="0"> 
                        <Setter Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                 </Style.Triggers> 
            </Style>

            <Style x:Key="A_Style_Background_NonInteractive" 
                   TargetType="FZMaterial">
                <Setter Property="Preset" Value="{StaticResource A_FZMaterialPresetGlassRoundtangle_GlassPanel_OuterAll2px}" />
                <Setter Property="Color" Value="{StaticResource H_Color_Primary_Black}" />
                <Setter Property="Opacity" Value="0.2" />
            </Style>

            <Style x:Key="A_Style_Control_EmptyItemStyle"
                   TargetType="Control">
                <Setter Property="Focusable" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Control">
                            <FZMaterial Style="{StaticResource A_Style_Background_NonInteractive}"
                                        Margin="0,2,0,2" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="A_Style_ListBoxItem_TextMenu_UserPicker"
                   BasedOn="{StaticResource A_Style_ListBoxItem_TextMenu_Default}"
                   TargetType="{Type ListBoxItem}">
                <Setter Property="local:FocusSelf.WhenTrue" Value="{Binding (Selector.IsSelected), Mode=OneWay, RelativeSource={RelativeSource Self}}" />
            </Style>
        </ResourceDictionary>
    </Page.Resources>

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

    <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_Select}"
                                local:ControllerButtonPanel.XDescription="{local:Loc HelpButtons.IDS_PlayerOptions}"
                                local:ControllerButtonPanel.YDescription="{local:Loc HelpButtons.IDS_Search}"
                                Style="{StaticResource A_Style_ContentControl_ButtonBar_UserPicker}" />
            </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 Title}"
                                Style="{StaticResource A_Style_ContentControl_PopupTitleBlock}"/>
                <ContentControl Style="{StaticResource A_Style_ContentControl_PopupContentBlock}">
                    <DockPanel Margin="12,24">
                        <local:FZTextBlock DockPanel.Dock="Top"
                                           Style="{StaticResource A_Style_FZTextBlock_UserPickerText}"
                                           HorizontalAlignment="Left"
                                           Margin="12,0,12,24"
                                           Text="{local:Loc Convoy.IDS_SendGameInvites}"/>
                        <Grid DockPanel.Dock="Top">
                            <UniformGrid Rows="1" Columns="11">
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                                <Control Template="{StaticResource A_Template_UserGamerPic_Empty}"/>
                            </UniformGrid>
                            <ItemsControl ItemsSource="{Binding SelectedCollection}" ItemTemplate="{StaticResource A_DataTemplate_SelectedUserItem}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <UniformGrid Rows="1" Columns="11"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </Grid>
                        <local:FZTextBlock Style="{StaticResource A_Style_FZTextBlock_UserPicker_SearchText}"
                                           HorizontalAlignment="Left"
                                           Margin="12,24,12,0"
                                           Text="{Binding (local:MultiStringFormatter.Output), RelativeSource={RelativeSource Self}}"
                                           local:MultiStringFormatter.Param0="{Binding DisplaySearchString}"
                                           local:MultiStringFormatter.Format="{local:Loc Convoy.IDS_SearchingFor}"/>
                    </DockPanel>
                </ContentControl>
                <Grid Margin="0,4,0,0">
                    <ScrollBar Style="{StaticResource A_Style_ScrollBar_Default}"
                               HorizontalAlignment="Right"
                               Margin="0,0,-16,0"
                               Minimum="{Binding ScrollWindowMin, ElementName=UserList}"
                               Maximum="{Binding ScrollWindowMax, ElementName=UserList}"
                               Value="{Binding ScrollWindowValue, ElementName=UserList, Mode=TwoWay}"
                               ViewportSize="{Binding ScrollWindowSize, ElementName=UserList}" />
                    <WrapListBox x:Name="UserList"
                                 Template="{StaticResource H_ControlTemplate_TextMenu_Default}"
                                 ScrollOrientation="Vertical"
                                 Margin="0,-2,0,0"
                                 MaxHeight="490"
                                 ItemHeight="70"
                                 ItemWidth="{StaticResource A_Double_Default_TitleBlock_Width}"
                                 Width="{StaticResource A_Double_Default_TitleBlock_Width}"
                                 AlternationCount="10000"
                                 ItemsSource="{Binding Collection}"
                                 SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                 ItemTemplate="{StaticResource A_DataTemplate_UserItem}"
                                 ItemContainerStyle="{StaticResource A_Style_ListBoxItem_TextMenu_UserPicker}"
                                 EmptyItemStyle="{StaticResource A_Style_Control_EmptyItemStyle}"
                                 local:FocusOnPageFocusGained.SelectorSelectedItem="True"
                                 local:ScreenReader.Line="{Binding SelectedItem.Text, RelativeSource={RelativeSource Self}}"
                                 local:ScreenReader.LineType="SelectedItem"
                                 local:ScreenReader.Event="OnChange"
                                 local:ScreenReader.SelectedNumber="{Binding SelectedItem.Index, RelativeSource={RelativeSource Self}, Converter={StaticResource A_IndexToNumberConverter}, FallbackValue=-1}"
                                 local:ScreenReader.SelectedCount="{Binding Collection.Count}">
                        <WrapListBox.Resources>
                            <Thickness x:Key="A_Margin_VirtualizingWrapPanel">0</Thickness>
                        </WrapListBox.Resources>
                    </WrapListBox>
                    <local:FZTextBlock Text="{local:Loc Convoy.IDS_NoResults}" 
                                       Style="{StaticResource A_Style_FZTextBlock_NoResultText}"
                                       HorizontalAlignment="Center"
                                       Margin="12,24"/>
                </Grid>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
