using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using YMhut.Box.Core.Tools;

namespace YMhut.Box.WinUI.Views;

public sealed partial class BuiltinReferenceToolPage
{
    private Border BuildModernHeader()
    {
        var definition = _module.Definition;
        var back = ModernUi.IconButton("\uE72B", AppLocalizer.T("返回工具箱", "Back to toolbox"), () => _goBack?.Invoke());
        var icon = ModernUi.IconTile(definition.Glyph, 42, ModernUi.AccentSoft, ModernUi.Accent, 19);
        var meta = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 8,
            Children =
            {
                ModernUi.SmallBadge(ToolText.CategoryLabel(definition.Category), ModernUi.Accent, ModernUi.AccentSoft),
                ModernUi.SmallBadge(definition.Kind.ToString(), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(RiskLabel(definition.RiskLevel), ModernUi.TextSecondary, ModernUi.SurfaceAlt)
            }
        };

        var title = new StackPanel
        {
            Spacing = 2,
            VerticalAlignment = VerticalAlignment.Center,
            Children =
            {
                ModernUi.Text(definition.Name, 22, FontWeights.SemiBold, maxLines: 1),
                meta
            }
        };
        ToolTipService.SetToolTip(title, definition.Description);

        var grid = new Grid { ColumnSpacing = 12 };
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        grid.ColumnDefinitions.Add(new ColumnDefinition());
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        grid.Children.Add(back);
        Grid.SetColumn(icon, 1);
        grid.Children.Add(icon);
        Grid.SetColumn(title, 2);
        grid.Children.Add(title);

        var run = ModernUi.PillButton(definition.PrimaryAction, "\uE768", RunAsync, primary: true);
        Grid.SetColumn(run, 3);
        grid.Children.Add(run);

        return ModernUi.Card(grid, new Thickness(14), radius: 8);
    }
}
