<base:LivePlayerPageBase
    x:Class="Bili.App.Pages.Desktop.Overlay.LivePlayerPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Bili.App.Pages.Base"
    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:player="using:Bili.App.Controls.Player"
    mc:Ignorable="d">

    <base:LivePlayerPageBase.Resources>
        <Style TargetType="controls:IconTextBlock">
            <Setter Property="IconFontSize" Value="20" />
            <Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
        </Style>
    </base:LivePlayerPageBase.Resources>

    <Grid>
        <player:PlayerPagePanel
            IsEnabled="{x:Bind ViewModel.IsError, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
            IsTabStop="{x:Bind ViewModel.IsError, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
            Opacity="{x:Bind ViewModel.IsError, Mode=OneWay, Converter={StaticResource ErrorOpacityConverter}}"
            SectionHeaderItemsSource="{x:Bind ViewModel.Sections}"
            SectionHeaderSelectedItem="{x:Bind ViewModel.CurrentSection, Mode=OneWay}"
            ViewModel="{x:Bind ViewModel}"
            Visibility="{x:Bind ViewModel.IsReloading, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
            <player:BiliMediaPlayer Style="{StaticResource LivePlayerStyle}" ViewModel="{x:Bind ViewModel.MediaPlayerViewModel, Mode=OneWay}" />
            <player:PlayerPagePanel.Descriptor>
                <StackPanel Spacing="8">
                    <StackPanel
                        Margin="0,0,0,12"
                        HorizontalAlignment="Left"
                        Orientation="Horizontal"
                        Spacing="12">
                        <controls:UserAvatar
                            Width="36"
                            Height="36"
                            Avatar="{x:Bind ViewModel.User.User.Avatar.Uri, Mode=OneWay}"
                            Command="{x:Bind ViewModel.User.ShowDetailCommand, Mode=OneWay}"
                            UserName="{x:Bind ViewModel.User.User.Name, Mode=OneWay}" />
                        <StackPanel Spacing="4">
                            <TextBlock
                                VerticalAlignment="Center"
                                IsTextSelectionEnabled="True"
                                Text="{x:Bind ViewModel.User.User.Name, Mode=OneWay}" />
                            <Button
                                Style="{x:Bind ViewModel.User.Relation, Converter={StaticResource RelationButtonStyleConverter}, Mode=OneWay}"
                                Padding="8,2"
                                HorizontalAlignment="Left"
                                Command="{x:Bind ViewModel.User.ToggleRelationCommand, Mode=OneWay}"
                                Content="{x:Bind ViewModel.User.Relation, Converter={StaticResource RelationTextConverter}, Mode=OneWay}"
                                FontSize="10"
                                Visibility="{x:Bind ViewModel.User.IsRelationButtonShown, Mode=OneWay}" />
                        </StackPanel>
                    </StackPanel>
                    <TextBlock
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                        IsTextSelectionEnabled="True"
                        Text="{x:Bind ViewModel.View.Partition, Mode=OneWay}" />
                    <TextBlock
                        x:Name="TitleBlock"
                        Style="{StaticResource SubtitleTextBlockStyle}"
                        HorizontalAlignment="Left"
                        IsTextSelectionEnabled="True"
                        MaxLines="2"
                        Text="{x:Bind ViewModel.View.Information.Identifier.Title, Mode=OneWay}"
                        TextWrapping="Wrap">
                        <ToolTipService.ToolTip>
                            <ToolTip Content="{x:Bind ViewModel.View.Information.Identifier.Title, Mode=OneWay}" IsEnabled="{Binding ElementName=TitleBlock, Mode=OneWay, Path=IsTextTrimmed}" />
                        </ToolTipService.ToolTip>
                    </TextBlock>
                    <controls:IconTextBlock
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        Symbol="EyeShow16"
                        Text="{x:Bind ViewModel.WatchingCountText, Mode=OneWay}"
                        ToolTipService.ToolTip="{loc:Locale Name=Viewer}"
                        Visibility="{x:Bind ViewModel.WatchingCountText, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
                    <controls:TrimTextBlock
                        x:Name="DescriptionBlock"
                        MaxWidth="600"
                        HorizontalAlignment="Left"
                        FontSize="13"
                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                        MaxLines="3"
                        Text="{x:Bind ViewModel.View.Information.Description, Mode=OneWay}" />
                </StackPanel>
            </player:PlayerPagePanel.Descriptor>
            <player:PlayerPagePanel.Dashboard>
                <Grid RowSpacing="20">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <ToggleSwitch
                        x:Name="LiveAudioOnlySwitch"
                        Header="{loc:Locale Name=OnlyAudio}"
                        IsOn="{x:Bind ViewModel.MediaPlayerViewModel.IsLiveAudioOnly, Mode=OneWay}"
                        Toggled="OnLiveOnlyAudioToggledAsync">
                        <ToggleSwitch.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock
                                    Style="{StaticResource CaptionTextBlockStyle}"
                                    Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                    Text="{Binding}" />
                            </DataTemplate>
                        </ToggleSwitch.HeaderTemplate>
                    </ToggleSwitch>
                    <StackPanel Grid.Row="1">
                        <Grid Margin="0,0,0,8" ColumnSpacing="8">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Button
                                x:Name="ShareButton"
                                HorizontalAlignment="Stretch"
                                Command="{x:Bind ViewModel.ShareCommand}">
                                <controls:IconTextBlock
                                    Foreground="{ThemeResource TextFillColorPrimaryBrush}"
                                    Symbol="Share16"
                                    Text="{loc:Locale Name=Share}" />
                            </Button>
                            <Button
                                Grid.Column="1"
                                Padding="8"
                                HorizontalAlignment="Stretch"
                                Command="{x:Bind ViewModel.FixedCommand}"
                                Content="{x:Bind ViewModel.IsLiveFixed, Mode=OneWay, Converter={StaticResource FixedContentConverter}}" />
                        </Grid>
                        <Button
                            x:Name="OpenInBroswerButton"
                            HorizontalAlignment="Stretch"
                            Command="{x:Bind ViewModel.OpenInBroswerCommand}">
                            <controls:IconTextBlock
                                Foreground="{ThemeResource TextFillColorPrimaryBrush}"
                                Symbol="Globe16"
                                Text="{loc:Locale Name=OpenInBroswer}" />
                        </Button>
                    </StackPanel>
                </Grid>
            </player:PlayerPagePanel.Dashboard>
            <player:PlayerPagePanel.SectionContent>
                <player:LiveMessageView x:Name="MessageView" />
            </player:PlayerPagePanel.SectionContent>
        </player:PlayerPagePanel>
        <controls:ErrorPanel
            x:Name="ErrorPanel"
            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:OverlayLoadingPanel IsBarActive="False" IsRingActive="{x:Bind ViewModel.IsReloading, Mode=OneWay}" />
    </Grid>
</base:LivePlayerPageBase>
