<UserControl
    x:Class="Bili.App.Controls.Dynamic.DynamicModule"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:behaviors="using:Bili.App.Behaviors"
    xmlns:community="using:Bili.ViewModels.Interfaces.Community"
    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:local="using:Bili.App.Controls.Dynamic"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">

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

    <Grid>

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="LayoutGroup">
                <VisualState x:Name="WideState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource MediumWindowThresholdWidth}" />
                    </VisualState.StateTriggers>
                </VisualState>
                <VisualState x:Name="NarrowState">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="VideoRepeaterView.IsStaggered" Value="False" />
                        <Setter Target="VideoRepeaterView.ItemOrientation" Value="Horizontal" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <ScrollViewer
            x:Name="VideoContentScrollViewer"
            Padding="{x:Bind CoreViewModel.PageHorizontalPadding, Converter={StaticResource HorizontalThicknessConverter}, Mode=OneWay}"
            HorizontalScrollMode="Disabled"
            VerticalScrollBarVisibility="Auto"
            Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <controls:VerticalRepeaterView
                x:Name="VideoRepeaterView"
                Margin="0,0,0,12"
                HeaderVisibility="Collapsed"
                IsStaggered="True"
                ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}"
                MinWideItemWidth="300">
                <interactivity:Interaction.Behaviors>
                    <behaviors:IncrementalBehavior />
                </interactivity:Interaction.Behaviors>
                <controls:VerticalRepeaterView.ItemTemplate>
                    <DataTemplate x:DataType="community:IDynamicItemViewModel">
                        <local:DynamicItem ViewModel="{x:Bind}" />
                    </DataTemplate>
                </controls:VerticalRepeaterView.ItemTemplate>
            </controls:VerticalRepeaterView>
        </ScrollViewer>

        <controls:ErrorPanel Text="{x:Bind ViewModel.ErrorText, Mode=OneWay}" Visibility="{x:Bind ViewModel.IsError, Mode=OneWay}" />
        <controls:ErrorPanel Text="{loc:Locale Name=NoSpecificData}" Visibility="{x:Bind ViewModel.IsEmpty, Mode=OneWay}" />
        <controls:OverlayLoadingPanel IsBarActive="{x:Bind ViewModel.IsIncrementalLoading, Mode=OneWay}" IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
    </Grid>
</UserControl>
