<UserControl
    x:Class="Bili.App.Controls.Community.RelationPageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:account="using:Bili.ViewModels.Interfaces.Account"
    xmlns:app="using:Bili.App.Controls.App"
    xmlns:behaviors="using:Bili.App.Behaviors"
    xmlns:controls="using:Bili.App.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:user="using:Bili.App.Controls.User"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">

    <interactivity:Interaction.Behaviors>
        <behaviors:InitializeBehavior />
    </interactivity:Interaction.Behaviors>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <app:PageHeader RefreshCommand="{x:Bind ViewModel.ReloadCommand}">
            <app:PageHeader.Title>
                <TextBlock
                    Margin="0,0,0,8"
                    HorizontalAlignment="Left"
                    TextTrimming="CharacterEllipsis">
                    <Run
                        FontWeight="Bold"
                        Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
                        Text="{x:Bind ViewModel.Profile.Name, Mode=OneWay}" />
                    <Run Text="{x:Bind ViewModel.TitleSuffix, Mode=OneWay}" />
                </TextBlock>
            </app:PageHeader.Title>
        </app:PageHeader>

        <ScrollViewer
            x:Name="ContentScrollViewer"
            Grid.Row="1"
            Padding="{x:Bind _appViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            VerticalScrollBarVisibility="Auto">
            <controls:VerticalRepeaterView
                Margin="0,0,0,12"
                HeaderVisibility="Collapsed"
                ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                MinWideItemHeight="200"
                MinWideItemWidth="180">
                <interactivity:Interaction.Behaviors>
                    <behaviors:IncrementalBehavior />
                </interactivity:Interaction.Behaviors>
                <controls:VerticalRepeaterView.ItemTemplate>
                    <DataTemplate x:DataType="account:IUserItemViewModel">
                        <user:UserItem ViewModel="{x:Bind}" />
                    </DataTemplate>
                </controls:VerticalRepeaterView.ItemTemplate>
            </controls:VerticalRepeaterView>
        </ScrollViewer>

        <controls:OverlayLoadingPanel
            Grid.Row="1"
            IsBarActive="{x:Bind ViewModel.IsIncrementalLoading, Mode=OneWay}"
            IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
        <controls:ErrorPanel
            Grid.Row="1"
            ActionContent="{loc:Locale Name=Refresh}"
            Text="{x:Bind ViewModel.ErrorText, Mode=OneWay}"
            Visibility="{x:Bind ViewModel.IsError, Mode=OneWay}">
            <interactivity:Interaction.Behaviors>
                <behaviors:ReloadBehavior />
            </interactivity:Interaction.Behaviors>
        </controls:ErrorPanel>
        <controls:ErrorPanel
            Grid.Row="1"
            Text="{loc:Locale Name=NoFans}"
            Visibility="{x:Bind ViewModel.IsEmpty, Mode=OneWay}" />
    </Grid>
</UserControl>
