<UserControl
    x:Class="DouYin.DownLoader.Views.Search" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:fl="clr-namespace:FlyleafLib.Controls.WPF;assembly=FlyleafLib" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:vm="clr-namespace:DouYin.DownLoader.ViewModels"
    d:DataContext="{d:DesignInstance Type=vm:SearchViewModel}"
    d:DesignHeight="960" d:DesignWidth="1080" mc:Ignorable="d">


    <Grid Margin="0,10">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="350" />
        </Grid.ColumnDefinitions>

        <DockPanel
            Grid.ColumnSpan="2" Margin="0,10" HorizontalAlignment="Left"
            LastChildFill="True">
            <TextBlock
                Width="60" Margin="10,0" VerticalAlignment="Center"
                Text="关键词" />
            <TextBox
                Width="320" Margin="10,0" md:HintAssist.Hint="请输入关键词"
                Text="{Binding KeyWord}" />
            <Button
                Width="100" Margin="10,0" VerticalContentAlignment="Center"
                Command="{Binding GetDataCommand}"
                Content="获取数据" />
            <Button
                Width="120" Margin="10,0" VerticalContentAlignment="Center"
                Command="{Binding DownloadCommand}"
                Content="下载当前数据" />
        </DockPanel>
        <ScrollViewer x:Name="videoScrollViewer" Grid.Row="2">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="ScrollChanged">
                    <i:InvokeCommandAction Command="{Binding ScrollToBottomCommand}" CommandParameter="{Binding ElementName=videoScrollViewer}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <ItemsControl
                x:Name="videoListBox" Grid.Row="1" HorizontalAlignment="Center"
                ItemsSource="{Binding VideoItems}"
                ScrollViewer.VerticalScrollBarVisibility="Hidden">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <md:Card Margin="10,10,0,0">
                            <Grid Width="210" Height="260">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="50" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="auto" />
                                </Grid.RowDefinitions>

                                <TextBlock
                                    Width="160" Margin="10" HorizontalAlignment="Left"
                                    Panel.ZIndex="1" FontSize="10" FontWeight="Bold"
                                    Foreground="Red"
                                    Text="{Binding Title}" />
                                <Border
                                    Name="tag" Width="40" Height="20"
                                    Margin="0,10,10,0" Padding="2" HorizontalAlignment="Right"
                                    VerticalAlignment="Top" Panel.ZIndex="1" Background="Gray"
                                    CornerRadius="5" Opacity="0.7" Visibility="Hidden">
                                    <TextBlock
                                        Height="30" HorizontalAlignment="Center" FontSize="15"
                                        FontWeight="Bold" Foreground="White" Text="图集" />
                                </Border>

                                <Image
                                    x:Name="image" Grid.Row="0" Grid.RowSpan="4"
                                    Width="210" Height="260"
                                    Source="{Binding VideoCover, Mode=TwoWay}"
                                    Stretch="Fill" />
                                <Button
                                    Grid.Row="0" Grid.RowSpan="4" Width="50"
                                    Height="50" Padding="0"
                                    Background="{x:Null}"
                                    BorderBrush="{x:Null}"
                                    Command="{Binding DataContext.MouseDownCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                    CommandParameter="{Binding}"
                                    ToolTip="播放">
                                    <md:PackIcon
                                        Width="50" Height="50" Kind="PlayCircle" />
                                </Button>

                                <DockPanel
                                    Grid.Row="3" Width="200" Height="25">
                                    <StackPanel
                                        Margin="0,5" DockPanel.Dock="Left" Orientation="Horizontal">
                                        <md:PackIcon Kind="Heart" />
                                        <TextBlock
                                            Width="40" Margin="2" FontSize="10"
                                            Foreground="Red"
                                            Text="{Binding Digg}" />

                                        <md:PackIcon Kind="Star" />
                                        <TextBlock
                                            Width="40" Margin="2" FontSize="10"
                                            Foreground="Red"
                                            Text="{Binding Collect}" />
                                    </StackPanel>
                                    <DockPanel Margin="-10,0" DockPanel.Dock="Right">
                                        <StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
                                            <Button
                                                Width="30" Height="20" Padding="0,2,0,0"
                                                Background="{x:Null}"
                                                BorderBrush="{x:Null}"
                                                Command="{Binding DataContext.ShowCommentCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                                CommandParameter="{Binding}">
                                                <md:PackIcon Kind="CommentProcessingOutline" />
                                            </Button>
                                            <TextBlock
                                                Width="40" Margin="0,6" FontSize="10"
                                                Foreground="Red"
                                                Text="{Binding Comment}" />
                                        </StackPanel>
                                        <Button
                                            Width="30" Height="20" Padding="0,2,0,0"
                                            HorizontalContentAlignment="Left"
                                            Background="{x:Null}"
                                            BorderBrush="{x:Null}"
                                            Command="{Binding DataContext.DownloadOneCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                            CommandParameter="{Binding}">
                                            <md:PackIcon Kind="Download" />
                                        </Button>
                                    </DockPanel>

                                </DockPanel>
                            </Grid>
                        </md:Card>
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding AwemeType}" Value="68">
                                <Setter TargetName="tag" Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>

                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
        <md:Card
            Grid.Row="2" Grid.Column="1" Margin="10,0">
            <DockPanel>
                <GroupBox
                    Height="350" Margin="2,5" DockPanel.Dock="Top"
                    Header="视频">
                    <fl:FlyleafHost
                        Height="350" AttachedDragMove="Both" Background="AliceBlue"
                        DockPanel.Dock="Top"
                        Player="{Binding FlPlayer, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
                </GroupBox>
                <GroupBox Margin="2,5" Header="热评">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <ProgressBar
                            Grid.RowSpan="2" Width="50" Height="50"
                            IsIndeterminate="True"
                            Style="{StaticResource MaterialDesignCircularProgressBar}"
                            Visibility="{Binding IsShowHotCommentCard}"
                            Value="50" />

                        <ListBox
                            Grid.Row="1" MinHeight="400"
                            ItemsSource="{Binding Comments, Mode=TwoWay}"
                            ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock
                                        Margin="2" OverridesDefaultStyle="False"
                                        Text="{Binding}"
                                        TextWrapping="NoWrap" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                </GroupBox>

            </DockPanel>
        </md:Card>
        <md:DialogHost
            x:Name="dg" Grid.Row="2" CloseOnClickAway="True"
            IsOpen="{Binding IsOpen}">

            <md:DialogHost.DialogContent>
                <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                    <DataGrid
                        Height="520" Margin="10" AutoGenerateColumns="False"
                        CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
                        DockPanel.Dock="Top" IsReadOnly="True"
                        ItemsSource="{Binding CommentList.CommentItems, Mode=TwoWay}"
                        ScrollViewer.VerticalScrollBarVisibility="Auto">

                        <DataGrid.Columns>
                            <DataGridTextColumn
                                MinWidth="300" MaxWidth="450"
                                Binding="{Binding Text}"
                                ClipboardContentBinding="{x:Null}"
                                Header="内容" />

                            <DataGridTextColumn
                                Width="100"
                                Binding="{Binding DiggCount}"
                                ClipboardContentBinding="{x:Null}"
                                Header="点赞" />

                            <DataGridTextColumn
                                Width="160"
                                Binding="{Binding NickName}"
                                ClipboardContentBinding="{x:Null}"
                                Header="用户昵称" />

                            <DataGridTextColumn
                                Width="160"
                                Binding="{Binding CreateTime}"
                                ClipboardContentBinding="{x:Null}"
                                Header="发布时间" />

                        </DataGrid.Columns>
                    </DataGrid>
                    <DockPanel
                        HorizontalAlignment="Center" DockPanel.Dock="Bottom" LastChildFill="False">

                        <Button
                            Margin="10"
                            Command="{Binding NextPageCommand}"
                            Content="加载更多"
                            IsEnabled="{Binding CommentList.HasMore, Mode=TwoWay}" />
                        <Button
                            Margin="10"
                            Command="{Binding ExportCommentsCommand}"
                            Content="导出评论" />
                    </DockPanel>
                </DockPanel>

            </md:DialogHost.DialogContent>
        </md:DialogHost>
    </Grid>




</UserControl>
