<?xml version="1.0" encoding="utf-8" ?>
<local:UserSpacePageControlBase
    x:Class="BiliCopilot.UI.Controls.Moment.UserSpacePageHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:ic="using:FluentIcons.WinUI"
    xmlns:local="using:BiliCopilot.UI.Controls.Moment"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:winui="using:CommunityToolkit.Labs.WinUI"
    mc:Ignorable="d">

    <Grid Padding="16,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <StackPanel
            x:Name="LeftContainer"
            VerticalAlignment="Center"
            Orientation="Horizontal"
            Spacing="12">
            <Button
                Margin="-12,0,0,0"
                Padding="16,12"
                VerticalAlignment="Center"
                Background="Transparent"
                BorderThickness="0"
                Command="{x:Bind ViewModel.InitializeUserInformationCommand, Mode=OneWay}">
                <TextBlock Style="{StaticResource BodyStrongTextBlockStyle}">
                    <Run Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}" Text="{x:Bind ViewModel.UserName, Mode=OneWay}" />
                    <Run Text="{ext:Locale Name=UserSpaceTitle}" />
                </TextBlock>
                <Button.Flyout>
                    <Flyout Placement="Bottom" ShouldConstrainToRootBounds="False">
                        <Grid Width="320">
                            <StackPanel Spacing="12" Visibility="{x:Bind ViewModel.Card, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <Grid ColumnSpacing="12">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Grid>
                                        <PersonPicture
                                            Width="48"
                                            Height="48"
                                            VerticalAlignment="Top"
                                            ProfilePicture="{x:Bind ViewModel.Card.Profile.User.Avatar.SourceUri, Converter={StaticResource BitmapConverter}, Mode=OneWay}" />
                                        <Image
                                            Width="16"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Bottom"
                                            Source="ms-appx:///Assets/vip.png"
                                            Visibility="{x:Bind ViewModel.Card.Profile.IsVip, Mode=OneWay}" />
                                    </Grid>

                                    <Grid Grid.Column="1" ColumnSpacing="8">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <StackPanel HorizontalAlignment="Center" Spacing="4">
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                                Text="{x:Bind ViewModel.Card.Community.FansCount, Mode=OneWay, Converter={StaticResource CountConverter}}" />
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                                                Text="{ext:Locale Name=FansCount}" />
                                        </StackPanel>
                                        <StackPanel
                                            Grid.Column="1"
                                            HorizontalAlignment="Center"
                                            Spacing="4">
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                                Text="{x:Bind ViewModel.Card.Community.FollowCount, Mode=OneWay, Converter={StaticResource CountConverter}}" />
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                                                Text="{ext:Locale Name=FollowCount}" />
                                        </StackPanel>
                                        <StackPanel
                                            Grid.Column="2"
                                            HorizontalAlignment="Center"
                                            Spacing="4">
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Style="{StaticResource BodyStrongTextBlockStyle}"
                                                Text="{x:Bind ViewModel.Card.Community.LikeCount, Mode=OneWay, Converter={StaticResource CountConverter}}" />
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                                                Text="{ext:Locale Name=LikeCount}" />
                                        </StackPanel>
                                    </Grid>
                                </Grid>
                                <StackPanel Spacing="8">
                                    <StackPanel Orientation="Horizontal" Spacing="8">
                                        <TextBlock
                                            VerticalAlignment="Center"
                                            Style="{StaticResource BodyStrongTextBlockStyle}"
                                            Text="{x:Bind ViewModel.Card.Profile.User.Name, Mode=OneWay}" />
                                        <Image
                                            Height="12"
                                            VerticalAlignment="Center"
                                            Source="{x:Bind ViewModel.Card.Profile.Level, Mode=OneWay, Converter={StaticResource LevelImageConverter}}" />
                                        <Border
                                            Padding="4,2"
                                            VerticalAlignment="Center"
                                            Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                            CornerRadius="{StaticResource ControlCornerRadius}">
                                            <TextBlock
                                                Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                                                IsTextSelectionEnabled="True"
                                                Style="{StaticResource CaptionTextBlockStyle}"
                                                Text="{x:Bind ViewModel.Card.Profile.User.Id, Mode=OneWay}" />
                                        </Border>
                                    </StackPanel>
                                    <base:TrimTextBlock
                                        HorizontalAlignment="Left"
                                        FontSize="12"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        MaxLines="2"
                                        Text="{x:Bind ViewModel.Card.Profile.Introduce, Mode=OneWay}" />
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Spacing="12" Visibility="{x:Bind ViewModel.Card, Mode=OneWay, Converter={StaticResource ObjectToVisibilityReverseConverter}}">
                                <Grid ColumnSpacing="12">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <base:Shimmer
                                        Height="48"
                                        HorizontalAlignment="Stretch"
                                        CornerRadius="24"
                                        IsActive="{x:Bind ViewModel.Card, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" />
                                    <base:Shimmer
                                        Grid.Column="1"
                                        Height="48"
                                        HorizontalAlignment="Stretch"
                                        CornerRadius="{StaticResource ControlCornerRadius}"
                                        IsActive="{x:Bind ViewModel.Card, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" />
                                </Grid>

                                <base:Shimmer
                                    Height="48"
                                    HorizontalAlignment="Stretch"
                                    CornerRadius="{StaticResource ControlCornerRadius}"
                                    IsActive="{x:Bind ViewModel.Card, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" />
                            </StackPanel>
                        </Grid>
                    </Flyout>
                </Button.Flyout>
            </Button>

            <ToggleButton
                Width="32"
                Height="32"
                Padding="0"
                VerticalAlignment="Center"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center"
                Command="{x:Bind ViewModel.ToggleFollowCommand, Mode=OneWay}"
                CornerRadius="16"
                IsChecked="{x:Bind ViewModel.IsFollowed, Mode=OneWay}"
                ToolTipService.ToolTip="{ext:Locale Name=Follow}">
                <ic:SymbolIcon
                    FontSize="14"
                    IconVariant="{x:Bind ViewModel.IsFollowed, Mode=OneWay, Converter={StaticResource BoolToIconVariantConverter}}"
                    Symbol="Heart" />
            </ToggleButton>
        </StackPanel>

        <SelectorBar
            x:Name="Selector"
            Grid.Column="0"
            Grid.ColumnSpan="3"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Visibility="{x:Bind ViewModel.IsSearchMode, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}" />

        <StackPanel
            Grid.Column="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Orientation="Horizontal"
            Spacing="8"
            Visibility="{x:Bind ViewModel.IsSearchMode, Mode=OneWay}">
            <TextBlock VerticalAlignment="Center">
                <Run Foreground="{ThemeResource TextFillColorTertiaryBrush}" Text="{ext:Locale Name=Search}" />
                <Run
                    FontWeight="Bold"
                    Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                    Text="{x:Bind ViewModel.SearchKeyword, Mode=OneWay}" />
            </TextBlock>
            <Button
                VerticalAlignment="Center"
                Command="{x:Bind ViewModel.ExitSearchCommand}"
                Style="{StaticResource IconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=ExitSearch}">
                <ic:SymbolIcon FontSize="14" Symbol="Dismiss" />
            </Button>
        </StackPanel>

        <StackPanel
            x:Name="RightContainer"
            Grid.Column="2"
            VerticalAlignment="Center"
            Orientation="Horizontal"
            Spacing="8">
            <Button
                VerticalAlignment="Center"
                Command="{x:Bind ViewModel.PinCommand, Mode=OneWay}"
                Style="{StaticResource IconButtonStyle}"
                ToolTipService.ToolTip="{ext:Locale Name=FixedContent}">
                <ic:SymbolIcon FontSize="14" Symbol="Pin" />
            </Button>
            <Button
                VerticalAlignment="Center"
                AutomationProperties.Name="{ext:Locale Name=Refresh}"
                Command="{x:Bind ViewModel.RefreshCommand, Mode=OneWay}">
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <ic:SymbolIcon
                        VerticalAlignment="Center"
                        FontSize="12"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        Symbol="ArrowSync" />
                    <TextBlock VerticalAlignment="Center" Text="{ext:Locale Name=Refresh}" />
                </StackPanel>
            </Button>
        </StackPanel>
    </Grid>
</local:UserSpacePageControlBase>
