using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace YMhut.Box.WinUI.Views;

public sealed partial class ExternalToolDetailPage
{
    private Border BuildModernHeader()
    {
        var tool = _module.Tool;
        var back = ModernUi.IconButton("\uE72B", AppLocalizer.T("返回工具箱", "Back to toolbox"), () => _goBack?.Invoke());
        var icon = ModernUi.IconTile(_module.Metadata.IconGlyph, 42, ModernUi.AccentSoft, ModernUi.Accent, 19);
        var meta = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 8,
            Children =
            {
                ModernUi.SmallBadge(tool.CategoryName, ModernUi.Accent, ModernUi.AccentSoft),
                ModernUi.SmallBadge(tool.Extension, ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(tool.PrimaryArchitecture ?? AppLocalizer.T("默认架构", "Default architecture"), ModernUi.TextSecondary, ModernUi.SurfaceAlt)
            }
        };

        var title = new StackPanel
        {
            Spacing = 2,
            VerticalAlignment = VerticalAlignment.Center,
            Children =
            {
                ModernUi.Text(tool.Name, 22, FontWeights.SemiBold, maxLines: 1),
                meta
            }
        };
        ToolTipService.SetToolTip(title, tool.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(AppLocalizer.T("启动", "Launch"), "\uE768", () => RunAsync(admin: false), primary: true);
        Grid.SetColumn(run, 3);
        grid.Children.Add(run);

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