<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Bili.App.Controls"
    xmlns:icons="using:Richasy.FluentIcon.Uwp"
    xmlns:loc="using:Bili.App.Resources.Extension"
    xmlns:local="using:Bili.App.Controls.Live"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls">
    <Style x:Key="VerticalLiveItemStyle" TargetType="local:LiveItem">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:LiveItem">
                    <controls:CardPanel
                        x:Name="RootCard"
                        AutomationProperties.Name="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCommand}"
                        IsEnableCheck="False">

                        <controls:CardPanel.ContextFlyout>
                            <MenuFlyout x:Name="LiveFlyout">
                                <MenuFlyoutItem
                                    x:Name="OpenInBroswerItem"
                                    AutomationProperties.Name="{loc:Locale Name=OpenInBroswer}"
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.OpenInBroswerCommand}"
                                    Text="{loc:Locale Name=OpenInBroswer}">
                                    <MenuFlyoutItem.Icon>
                                        <icons:RegularFluentIcon Symbol="Globe16" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </controls:CardPanel.ContextFlyout>

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="Row1" Height="Auto" />
                                <RowDefinition x:Name="Row2" Height="*" />
                            </Grid.RowDefinitions>
                            <Grid.Resources>
                                <Style TargetType="controls:IconTextBlock">
                                    <Setter Property="Spacing" Value="4" />
                                    <Setter Property="IconFontSize" Value="12" />
                                    <Setter Property="FontSize" Value="12" />
                                </Style>
                            </Grid.Resources>
                            <Grid
                                x:Name="CoverContainer"
                                Height="124"
                                Margin="1,1,1,0"
                                VerticalAlignment="Center"
                                CornerRadius="4,4,0,0">
                                <controls:CommonImageEx
                                    x:Name="CoverImage"
                                    VerticalAlignment="Center"
                                    ImageUrl="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Cover.Uri}"
                                    Stretch="UniformToFill" />
                            </Grid>

                            <Grid
                                Margin="0,0,12,-18"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Bottom"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User, Converter={StaticResource ObjectToVisibilityConverter}}">
                                <Ellipse
                                    Width="40"
                                    Height="40"
                                    Fill="{ThemeResource ControlOnImageFillColorDefaultBrush}" />
                                <controls:UserAvatar
                                    x:Name="VerticalAvatar"
                                    Width="36"
                                    Height="36"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Avatar="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Avatar.Uri}"
                                    UserName="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Name}" />
                            </Grid>

                            <Grid
                                x:Name="ContentContainer"
                                Grid.Row="1"
                                Padding="12,8,12,8"
                                RowSpacing="8">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBlock
                                    x:Name="SubtitleBlock"
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    VerticalAlignment="Center"
                                    Opacity="0.6"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Subtitle}" />

                                <TextBlock
                                    x:Name="TitleBlock"
                                    Grid.Row="1"
                                    VerticalAlignment="Top"
                                    MaxLines="1"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                                    TextTrimming="CharacterEllipsis"
                                    TextWrapping="Wrap">
                                    <ToolTipService.ToolTip>
                                        <ToolTip Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}" IsEnabled="{Binding ElementName=TitleBlock, Path=IsTextTrimmed}" />
                                    </ToolTipService.ToolTip>
                                </TextBlock>

                                <StackPanel Grid.Row="2" Orientation="Horizontal">
                                    <controls:IconTextBlock
                                        Margin="0,0,12,0"
                                        Opacity="0.6"
                                        Symbol="People16"
                                        Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ViewerCountText}"
                                        ToolTipService.ToolTip="{loc:Locale Name=Viewer}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ViewerCountText, Converter={StaticResource ObjectToVisibilityConverter}}" />
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="HorizontalLiveItemStyle" TargetType="local:LiveItem">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:LiveItem">
                    <controls:CardPanel
                        x:Name="RootCard"
                        AutomationProperties.Name="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                        MaxHeight="124"
                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCommand}"
                        IsEnableCheck="False"
                        IsEnableHoverAnimation="False">

                        <controls:CardPanel.ContextFlyout>
                            <MenuFlyout x:Name="LiveFlyout">
                                <MenuFlyoutItem
                                    x:Name="OpenInBroswerItem"
                                    AutomationProperties.Name="{loc:Locale Name=OpenInBroswer}"
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.OpenInBroswerCommand}"
                                    Text="{loc:Locale Name=OpenInBroswer}">
                                    <MenuFlyoutItem.Icon>
                                        <icons:RegularFluentIcon Symbol="Globe16" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </controls:CardPanel.ContextFlyout>

                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="controls:IconTextBlock">
                                    <Setter Property="Spacing" Value="4" />
                                    <Setter Property="IconFontSize" Value="12" />
                                    <Setter Property="FontSize" Value="12" />
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid
                                x:Name="CoverContainer"
                                Margin="8"
                                VerticalAlignment="Stretch"
                                CornerRadius="{StaticResource ControlCornerRadius}">
                                <controls:CommonImageEx
                                    x:Name="CoverImage"
                                    Width="180"
                                    VerticalAlignment="Center"
                                    ImageUrl="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Cover.Uri}"
                                    Stretch="UniformToFill" />
                            </Grid>
                            <Grid
                                x:Name="ContentContainer"
                                Grid.Column="1"
                                Padding="8"
                                RowSpacing="8">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <TextBlock
                                    x:Name="SubtitleBlock"
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    VerticalAlignment="Center"
                                    Opacity="0.6"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Subtitle}" />

                                <TextBlock
                                    x:Name="TitleBlock"
                                    Grid.Row="1"
                                    VerticalAlignment="Top"
                                    MaxLines="2"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                                    TextTrimming="CharacterEllipsis"
                                    TextWrapping="Wrap">
                                    <ToolTipService.ToolTip>
                                        <ToolTip Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}" IsEnabled="{Binding ElementName=TitleBlock, Path=IsTextTrimmed}" />
                                    </ToolTipService.ToolTip>
                                </TextBlock>

                                <StackPanel
                                    x:Name="InlineUserContainer"
                                    Grid.Row="2"
                                    Orientation="Horizontal"
                                    Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User, Converter={StaticResource ObjectToVisibilityConverter}}">
                                    <controls:UserAvatar
                                        x:Name="InlineAvatar"
                                        Width="24"
                                        Height="24"
                                        Margin="0,0,8,0"
                                        VerticalAlignment="Center"
                                        Avatar="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Avatar.Uri}"
                                        UserName="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Name}" />
                                    <TextBlock
                                        Style="{StaticResource CaptionTextBlockStyle}"
                                        VerticalAlignment="Center"
                                        Opacity="0.6"
                                        Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Name}" />
                                </StackPanel>

                                <StackPanel Grid.Row="3" Orientation="Horizontal">
                                    <controls:IconTextBlock
                                        Margin="0,0,12,0"
                                        Opacity="0.6"
                                        Symbol="People16"
                                        Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ViewerCountText}"
                                        ToolTipService.ToolTip="{loc:Locale Name=Viewer}"
                                        Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ViewerCountText, Converter={StaticResource ObjectToVisibilityConverter}}" />
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SlimLiveItemStyle" TargetType="local:LiveItem">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:LiveItem">
                    <controls:CardPanel
                        AutomationProperties.Name="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                        Width="120"
                        Height="176"
                        Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCommand}"
                        IsEnableCheck="False"
                        IsEnableHoverAnimation="False">

                        <controls:CardPanel.ContextFlyout>
                            <MenuFlyout x:Name="LiveFlyout">
                                <MenuFlyoutItem
                                    x:Name="OpenInBroswerItem"
                                    AutomationProperties.Name="{loc:Locale Name=OpenInBroswer}"
                                    Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.OpenInBroswerCommand}"
                                    Text="{loc:Locale Name=OpenInBroswer}">
                                    <MenuFlyoutItem.Icon>
                                        <icons:RegularFluentIcon Symbol="Globe16" />
                                    </MenuFlyoutItem.Icon>
                                </MenuFlyoutItem>
                            </MenuFlyout>
                        </controls:CardPanel.ContextFlyout>

                        <Grid Padding="12" RowSpacing="12">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <controls:UserAvatar
                                Width="52"
                                Height="52"
                                HorizontalAlignment="Center"
                                Avatar="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Avatar.Uri}"
                                Command="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCommand}"
                                DecodeSize="40"
                                UserName="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Name}" />
                            <StackPanel Grid.Row="1" Spacing="8">
                                <TextBlock
                                    Style="{StaticResource BodyTextBlockStyle}"
                                    HorizontalAlignment="Center"
                                    FontWeight="Bold"
                                    MaxLines="1"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.User.Name}"
                                    TextAlignment="Center"
                                    TextTrimming="CharacterEllipsis" />
                                <TextBlock
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    HorizontalAlignment="Center"
                                    MaxLines="2"
                                    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Data.Identifier.Title}"
                                    TextAlignment="Center"
                                    TextTrimming="CharacterEllipsis" />
                            </StackPanel>
                            <controls:IconTextBlock
                                Grid.Row="2"
                                HorizontalAlignment="Center"
                                FontSize="12"
                                Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                IconFontSize="12"
                                Spacing="4"
                                Symbol="People16"
                                Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.ViewerCountText, Mode=OneWay}" />
                        </Grid>
                    </controls:CardPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource VerticalLiveItemStyle}" TargetType="local:LiveItem" />
</ResourceDictionary>
