<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:app="using:Bili.Workspace.Controls.App"
    xmlns:community="using:Bili.Workspace.Controls.Community"
    xmlns:controls="using:Bili.Workspace.Controls"
    xmlns:ext="using:Bili.Workspace.Resources.Extension"
    xmlns:local="using:Bili.Workspace.Controls.Dynamic">

    <Style x:Key="DefaultDynamicItemStyle" TargetType="local:DynamicItem">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DynamicItem">
                    <controls:CardPanel x:Name="RootCard" Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ActiveCommand}">
                        <Grid Padding="12">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <!-- 头部信息 -->
                            <Grid
                                x:Name="HeaderContainer"
                                Margin="0,0,0,12"
                                ColumnSpacing="8">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <community:UserAvatar
                                    x:Name="UserAvatar"
                                    Width="32"
                                    Height="32"
                                    VerticalAlignment="Center"
                                    Avatar="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Publisher.User.Avatar.Uri}"
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ShowUserDetailCommand}"
                                    UserName="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Publisher.User.Name}" />
                                <StackPanel Grid.Column="1" Spacing="2">
                                    <TextBlock
                                        x:Name="UserNameBlock"
                                        HorizontalAlignment="Left"
                                        FontSize="14"
                                        FontWeight="Bold"
                                        Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Publisher.User.Name}"
                                        TextTrimming="CharacterEllipsis" />
                                    <TextBlock
                                        x:Name="DateBlock"
                                        HorizontalAlignment="Left"
                                        FontSize="12"
                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                        Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Tip}" />
                                </StackPanel>
                                <Button
                                    x:Name="MoreButton"
                                    Grid.Column="2"
                                    Width="32"
                                    Height="32"
                                    Padding="0"
                                    VerticalAlignment="Top"
                                    Background="Transparent"
                                    BorderThickness="0">
                                    <controls:FluentIcon FontSize="20" Symbol="MoreHorizontal" />
                                    <Button.Flyout>
                                        <MenuFlyout Placement="Bottom">
                                            <MenuFlyoutItem
                                                x:Name="AddViewLaterButton"
                                                Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.AddToViewLaterCommand}"
                                                IsEnabled="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.CanAddViewLater}"
                                                Text="{ext:Locale Name=AddToViewLater}">
                                                <MenuFlyoutItem.Icon>
                                                    <controls:FluentIcon Symbol="Add" />
                                                </MenuFlyoutItem.Icon>
                                            </MenuFlyoutItem>
                                        </MenuFlyout>
                                    </Button.Flyout>
                                </Button>
                            </Grid>

                            <!-- 描述文本 -->
                            <app:EmoteTextBlock
                                x:Name="DescriptionBlock"
                                Grid.Row="1"
                                Margin="0,0,0,12"
                                FontSize="13"
                                MaxLines="8"
                                Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Description}"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Description, Converter={StaticResource ObjectToVisibilityConverter}}" />

                            <!-- 主体内容，比如视频封面 -->
                            <Grid
                                x:Name="MainContainer"
                                Grid.Row="2"
                                Margin="0,0,0,12"
                                Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                CornerRadius="{ThemeResource ControlCornerRadius}"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Data, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <local:DynamicPresenter x:Name="Presenter" Data="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Data}" />
                            </Grid>

                            <!-- 操作 -->
                            <Grid
                                Grid.Row="3"
                                ColumnSpacing="12"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.IsShowCommunity}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ToggleButton
                                    x:Name="LikeButton"
                                    Height="28"
                                    Background="Transparent"
                                    BorderThickness="0"
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ToggleLikeCommand}">
                                    <StackPanel Orientation="Horizontal" Spacing="4">
                                        <controls:FluentIcon
                                            VerticalAlignment="Center"
                                            FontSize="12"
                                            Symbol="ThumbLike" />
                                        <TextBlock
                                            x:Name="LikeCountBlock"
                                            VerticalAlignment="Center"
                                            FontSize="12"
                                            Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.LikeCountText}"
                                            TextLineBounds="Tight" />
                                    </StackPanel>
                                </ToggleButton>
                                <app:IconTextBlock
                                    x:Name="ReplyCountBlock"
                                    Grid.Column="1"
                                    Margin="0,-3,0,0"
                                    VerticalAlignment="Center"
                                    FontSize="12"
                                    IconFontSize="12"
                                    Symbol="Comment"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.CommentCountText}" />
                            </Grid>
                        </Grid>
                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource DefaultDynamicItemStyle}" TargetType="local:DynamicItem" />
</ResourceDictionary>
