<Grid
    x:Class="Pixeval.Controls.DownloadItem"
    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:fluent="using:FluentIcons.WinUI"
    xmlns:local="using:Pixeval.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    ColumnSpacing="20"
    mc:Ignorable="d">
    <!--<ToolTipService.ToolTip>
        <ToolTip Content="{x:Bind ViewModel.Entry.Title, Mode=OneWay}" Placement="Mouse" />
    </ToolTipService.ToolTip>-->
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="3*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <local:LazyImage
        Grid.Column="0"
        Width="50"
        Height="50"
        Source="{x:Bind ViewModel.ThumbnailSource, Mode=OneWay}" />
    <StackPanel
        Grid.Column="1"
        HorizontalAlignment="Left"
        VerticalAlignment="Center"
        Spacing="1">
        <TextBlock
            Style="{StaticResource CaptionTextBlockStyle}"
            Text="{x:Bind ViewModel.Entry.Title, Mode=OneWay}"
            TextTrimming="CharacterEllipsis"
            TextWrapping="NoWrap" />
        <TextBlock
            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
            Style="{StaticResource CaptionTextBlockStyle}"
            Text="{x:Bind ViewModel.Entry.User.Name, Mode=OneWay}"
            TextTrimming="CharacterEllipsis"
            TextWrapping="NoWrap" />
    </StackPanel>
    <StackPanel
        Grid.Column="2"
        HorizontalAlignment="Stretch"
        VerticalAlignment="Center"
        Spacing="5">
        <ProgressBar
            HorizontalAlignment="Stretch"
            IsIndeterminate="{x:Bind ViewModel.IsPending(ViewModel.DownloadTask.CurrentState), Mode=OneWay}"
            ShowError="{x:Bind ViewModel.IsError(ViewModel.DownloadTask.CurrentState), Mode=OneWay}"
            ShowPaused="{x:Bind ViewModel.IsPaused(ViewModel.DownloadTask.CurrentState), Mode=OneWay}"
            Value="{x:Bind ViewModel.DownloadTask.ProgressPercentage, Mode=OneWay}" />
        <StackPanel
            Orientation="Horizontal"
            Spacing="5"
            Visibility="{x:Bind ViewModel.IsGroup(ViewModel.DownloadTask), Mode=OneWay}">
            <local:DigitalSignalItem
                Fill="{x:Bind ViewModel.CurrentStateBrush(ViewModel.DownloadTask.CurrentState), Mode=OneWay}"
                Text="{x:Bind ViewModel.DownloadTask.ActiveCount, Mode=OneWay}"
                Visibility="{x:Bind local:C.IsNotZeroToVisibility(ViewModel.DownloadTask.ActiveCount), Mode=OneWay}" />
            <local:DigitalSignalItem
                Fill="{ThemeResource SystemFillColorSuccessBrush}"
                Text="{x:Bind ViewModel.DownloadTask.CompletedCount, Mode=OneWay}"
                Visibility="{x:Bind local:C.IsNotZeroToVisibility(ViewModel.DownloadTask.CompletedCount), Mode=OneWay}" />
            <local:DigitalSignalItem
                Fill="{ThemeResource SystemFillColorCriticalBrush}"
                Text="{x:Bind ViewModel.DownloadTask.ErrorCount, Mode=OneWay}"
                Visibility="{x:Bind local:C.IsNotZeroToVisibility(ViewModel.DownloadTask.ErrorCount), Mode=OneWay}" />
        </StackPanel>
        <TextBlock
            Foreground="{ThemeResource TextFillColorSecondaryBrush}"
            Style="{StaticResource CaptionTextBlockStyle}"
            Text="{x:Bind ViewModel.ProgressMessage(ViewModel.DownloadTask.CurrentState, ViewModel.DownloadTask.ProgressPercentage, ViewModel.DownloadTask), Mode=OneWay}"
            TextTrimming="CharacterEllipsis"
            TextWrapping="NoWrap" />
    </StackPanel>
    <CommandBar
        Grid.Column="3"
        Width="125"
        VerticalAlignment="Center"
        DefaultLabelPosition="Right"
        OverflowButtonVisibility="Visible">
        <!--  Width="125" 是试出来刚好只显示一个按钮的宽度  -->
        <AppBarButton
            Click="ActionButton_OnClicked"
            IsEnabled="{x:Bind ViewModel.IsItemEnabled(ViewModel.DownloadTask.IsProcessing, ViewModel.DownloadTask.CurrentState), Mode=OneWay}"
            Label="{x:Bind ViewModel.ActionButtonContent(ViewModel.DownloadTask.CurrentState), Mode=OneWay}">
            <AppBarButton.Icon>
                <fluent:SymbolIcon Symbol="{x:Bind ViewModel.ActionButtonSymbol(ViewModel.DownloadTask.CurrentState), Mode=OneWay}" />
            </AppBarButton.Icon>
        </AppBarButton>
        <AppBarButton
            x:Uid="/DownloadItem/RedownloadItem"
            Click="RedownloadItem_OnClicked"
            Icon="{fluent:SymbolIcon Symbol=ArrowDownload}"
            IsEnabled="{x:Bind ViewModel.IsRedownloadItemEnabled(ViewModel.DownloadTask.IsProcessing, ViewModel.DownloadTask.CurrentState), Mode=OneWay}" />
        <AppBarButton
            x:Uid="/DownloadItem/CancelDownloadItem"
            Click="CancelDownloadItem_OnClicked"
            Icon="{fluent:SymbolIcon Symbol=Dismiss}"
            IsEnabled="{x:Bind ViewModel.IsCancelItemEnabled(ViewModel.DownloadTask.IsProcessing, ViewModel.DownloadTask.CurrentState), Mode=OneWay}" />
        <AppBarButton
            x:Uid="/DownloadItem/OpenDownloadLocationItem"
            Click="OpenDownloadLocationItem_OnClicked"
            Icon="{fluent:SymbolIcon Symbol=FolderArrowRight}" />
        <AppBarButton
            x:Uid="/DownloadItem/GoToPageItem"
            Click="GoToPageItem_OnClicked"
            Icon="{fluent:SymbolIcon Symbol=OpenFolder}" />
        <AppBarButton
            x:Uid="/DownloadItem/CheckErrorMessageInDetailItem"
            Click="CheckErrorMessageInDetail_OnClicked"
            Icon="{fluent:SymbolIcon Symbol=DocumentError}"
            IsEnabled="{x:Bind ViewModel.IsError(ViewModel.DownloadTask.CurrentState), Mode=OneWay}" />
    </CommandBar>
</Grid>
