<?xml version="1.0" encoding="utf-8" ?>
<local:CommentMainPanelBase
    x:Class="BiliCopilot.UI.Controls.Comment.CommentMainPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:components="using:BiliCopilot.UI.Controls.Components"
    xmlns:components1="using:BiliCopilot.UI.ViewModels.Components"
    xmlns:converters="using:BiliCopilot.UI.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:local="using:BiliCopilot.UI.Controls.Comment"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:models="using:Richasy.BiliKernel.Models"
    mc:Ignorable="d">

    <Grid Padding="0,12" RowSpacing="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid Padding="12,0" Visibility="{x:Bind ViewModel.SelectedItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityReverseConverter}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBlock
                Margin="12,0,0,0"
                HorizontalAlignment="Left"
                VerticalAlignment="Center"
                FontSize="14"
                Style="{StaticResource SubtitleTextBlockStyle}"
                Text="{ext:Locale Name=Comments}" />
            <ComboBox
                x:Name="SortTypeComboBox"
                Grid.Column="1"
                MinWidth="100"
                VerticalAlignment="Center"
                IsEnabled="{x:Bind ViewModel.IsLoading, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
                ItemsSource="{x:Bind ViewModel.Sorts, Mode=OneWay}"
                SelectedItem="{x:Bind ViewModel.SortType, Mode=OneWay}"
                SelectionChanged="OnSortChanged">
                <ComboBox.ItemTemplate>
                    <DataTemplate x:DataType="models:CommentSortType">
                        <TextBlock Text="{x:Bind Converter={StaticResource SortTypeTextConverter}}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </Grid>
        <HyperlinkButton
            Margin="12,0"
            HorizontalAlignment="Left"
            Command="{x:Bind ViewModel.BackToMainCommand, Mode=OneWay}"
            Content="{ext:Locale Name=BackToPrevious}"
            Visibility="{x:Bind ViewModel.SelectedItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
        <Grid Grid.Row="1" Visibility="{x:Bind ViewModel.SelectedItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityReverseConverter}}">
            <ScrollViewer
                x:Name="CommentScrollView"
                Padding="0"
                Style="{StaticResource PageScrollViewerStyle}">
                <StackPanel Margin="12,0">
                    <local:CommentItemControl
                        Margin="0,0,0,4"
                        ShowMoreCommand="{x:Bind ViewModel.TopItem.ShowMoreCommand, Mode=OneWay}"
                        ViewModel="{x:Bind ViewModel.TopItem.Data, Mode=OneWay}"
                        Visibility="{x:Bind ViewModel.TopItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
                    <ItemsControl ItemsSource="{x:Bind ViewModel.Comments, Mode=OneWay}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate x:DataType="components1:CommentDetailViewModel">
                                <local:CommentItemControl
                                    Margin="0,2"
                                    ShowMoreCommand="{x:Bind ShowMoreCommand}"
                                    ViewModel="{x:Bind Data}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>
            </ScrollViewer>
            <base:EmptyHolder
                Description="{ext:Locale Name=NoReply}"
                Emoji="&#x1FAE2;"
                Visibility="{x:Bind ViewModel.IsEmpty, Mode=OneWay}">
                <base:EmptyHolder.ActionElement>
                    <HyperlinkButton Command="{x:Bind ViewModel.RefreshCommand, Mode=OneWay}" Content="{ext:Locale Name=Refresh}" />
                </base:EmptyHolder.ActionElement>
            </base:EmptyHolder>
            <base:LoadingWidget Text="{ext:Locale Name=LoadingAndWait}" Visibility="{x:Bind ViewModel.IsLoading, Mode=OneWay}" />
        </Grid>
        <local:CommentDetailPanel
            Grid.Row="1"
            Grid.RowSpan="2"
            ViewModel="{x:Bind ViewModel.SelectedItem, Mode=OneWay}"
            Visibility="{x:Bind ViewModel.SelectedItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}" />
        <local:CommentTextBox
            Grid.Row="2"
            Margin="12,0"
            IsEnabled="{x:Bind ViewModel.IsReplying, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
            ReplyTip="{x:Bind ViewModel.ReplyTarget, Mode=OneWay}"
            ResetSelectedCommand="{x:Bind ViewModel.ResetReplyTargetCommand, Mode=OneWay}"
            SendCommand="{x:Bind ViewModel.SendReplyCommand, Mode=OneWay}"
            Visibility="{x:Bind ViewModel.SelectedItem, Mode=OneWay, Converter={StaticResource ObjectToVisibilityReverseConverter}}" />
    </Grid>
</local:CommentMainPanelBase>
