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

namespace YMhut.Box.WinUI.Views.Tools;

public abstract partial class AdaptiveToolPage
{
    private Border BuildCompactGalleryHeader(IToolModule module)
    {
        var back = ModernUi.IconButton("\uE72B", AppLocalizer.T("返回工具箱", "Back to toolbox"), () => _goBack?.Invoke());
        back.VerticalAlignment = VerticalAlignment.Center;

        var metaRow = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 8,
            Children =
            {
                ModernUi.SmallBadge(ToolText.CategoryLabel(module.Metadata.Category), ModernUi.Accent, ModernUi.AccentSoft),
                ModernUi.SmallBadge(InteractionLabel(_spec.InteractionMode), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(_spec.AutoRunOnOpen ? AppLocalizer.T("自动加载", "Auto load") : AppLocalizer.T("手动执行", "Manual run"), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(module.Metadata.OfflineCapable ? AppLocalizer.T("本地处理", "Local") : AppLocalizer.T("联网数据", "Online"), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(ResultLabel(_spec.Result), ModernUi.TextSecondary, ModernUi.SurfaceAlt)
            }
        };

        var titlePanel = new StackPanel
        {
            Spacing = 7,
            VerticalAlignment = VerticalAlignment.Center,
            Children =
            {
                ModernUi.Text(ToolText.Name(module), 26, FontWeights.SemiBold, maxLines: 1),
                metaRow
            }
        };

        var grid = new Grid { ColumnSpacing = 14 };
        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);

        var icon = ModernUi.IconTile(module.Metadata.IconGlyph, 48, ModernUi.AccentSoft, ModernUi.Accent, 21);
        Grid.SetColumn(icon, 1);
        grid.Children.Add(icon);

        Grid.SetColumn(titlePanel, 2);
        grid.Children.Add(titlePanel);

        Grid.SetColumn(_progressRing, 3);
        grid.Children.Add(_progressRing);

        grid.SizeChanged += (_, e) =>
        {
            metaRow.MaxWidth = Math.Max(260, e.NewSize.Width - 160);
        };

        return ModernUi.Card(grid, new Thickness(16), new Thickness(32, 24, 32, 12), radius: 8);
    }

    private Border BuildGalleryHeader(IToolModule module)
    {
        var back = ModernUi.IconButton("\uE72B", AppLocalizer.T("返回工具箱", "Back to toolbox"), () => _goBack?.Invoke());
        back.VerticalAlignment = VerticalAlignment.Top;

        var metaRow = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 8,
            Children =
            {
                ModernUi.SmallBadge(ToolText.CategoryLabel(module.Metadata.Category), ModernUi.Accent, ModernUi.AccentSoft),
                ModernUi.SmallBadge(InteractionLabel(_spec.InteractionMode), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(_spec.AutoRunOnOpen ? AppLocalizer.T("自动加载", "Auto load") : AppLocalizer.T("手动执行", "Manual run"), ModernUi.TextSecondary, ModernUi.SurfaceAlt)
            }
        };

        var titlePanel = new StackPanel
        {
            Spacing = 8,
            Children =
            {
                metaRow,
                ModernUi.Text(ToolText.Name(module), 28, FontWeights.SemiBold, maxLines: 1),
                ModernUi.Text(ToolText.Description(module), 14, foreground: ModernUi.TextSecondary, maxLines: 2)
            }
        };

        var statusPanel = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 10,
            VerticalAlignment = VerticalAlignment.Center,
            Children =
            {
                _progressRing,
                ModernUi.SmallBadge(LayoutLabel(_spec.Layout), ModernUi.TextSecondary, ModernUi.SurfaceAlt),
                ModernUi.SmallBadge(ResultLabel(_spec.Result), ModernUi.TextSecondary, ModernUi.SurfaceAlt)
            }
        };

        var grid = new Grid { ColumnSpacing = 14, RowSpacing = 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);
        var icon = ModernUi.IconTile(module.Metadata.IconGlyph, 54, ModernUi.AccentSoft, ModernUi.Accent, 23);
        Grid.SetColumn(icon, 1);
        grid.Children.Add(icon);
        Grid.SetColumn(titlePanel, 2);
        grid.Children.Add(titlePanel);
        Grid.SetColumn(statusPanel, 3);
        grid.Children.Add(statusPanel);

        grid.SizeChanged += (_, e) =>
        {
            var narrow = e.NewSize.Width < 760;
            grid.ColumnDefinitions.Clear();
            grid.RowDefinitions.Clear();
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            grid.ColumnDefinitions.Add(new ColumnDefinition());

            Grid.SetColumn(back, 0);
            Grid.SetRow(back, 0);
            Grid.SetColumn(icon, 1);
            Grid.SetRow(icon, 0);
            Grid.SetColumn(titlePanel, 2);
            Grid.SetRow(titlePanel, 0);

            if (narrow)
            {
                grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
                grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
                Grid.SetColumn(statusPanel, 1);
                Grid.SetColumnSpan(statusPanel, 2);
                Grid.SetRow(statusPanel, 1);
            }
            else
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
                Grid.SetColumn(statusPanel, 3);
                Grid.SetRow(statusPanel, 0);
            }
        };

        return ModernUi.Card(grid, new Thickness(18), new Thickness(32, 28, 32, 16), radius: 8);
    }

    private Border BuildGalleryInputCard(IToolModule module)
    {
        var panel = new StackPanel { Spacing = _spec.PageDensity == ToolPageDensity.Compact ? 12 : 16 };
        panel.Children.Add(BuildGallerySectionHeader(
            AppLocalizer.T("输入", "Input"),
            InputTitle(module),
            _spec.ShowDescription ? InputDescription(module) : AppLocalizer.T("设置此工具所需的值，然后执行。", "Set the values for this tool and run it."),
            "\uE8D2"));

        if (_parameterBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_parameterBox);
        }

        if (_queryBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_queryBox);
        }

        if (_startDatePicker.Visibility == Visibility.Visible)
        {
            panel.Children.Add(BuildDatePanel());
        }

        if (UsesNumericPrimaryInput())
        {
            panel.Children.Add(BuildNumberInputPanel());
        }

        if (_inputBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_inputBox);
        }

        var actions = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 10,
            Margin = new Thickness(0, 4, 0, 0)
        };
        AddSemanticActions(actions);
        panel.Children.Add(new ScrollViewer
        {
            HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
            VerticalScrollBarVisibility = ScrollBarVisibility.Disabled,
            Content = actions
        });

        return ModernUi.Card(panel, new Thickness(18), radius: 8);
    }

    private Border BuildCompactGalleryInputCard(IToolModule module)
    {
        var panel = new StackPanel { Spacing = _spec.PageDensity == ToolPageDensity.Compact ? 10 : 14 };
        panel.Children.Add(BuildGallerySectionHeader(
            AppLocalizer.T("输入", "Input"),
            InputTitle(module),
            CompactInputDescription(module),
            "\uE8D2",
            compact: true));

        if (_parameterBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_parameterBox);
        }

        if (_queryBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_queryBox);
        }

        if (_startDatePicker.Visibility == Visibility.Visible)
        {
            panel.Children.Add(BuildDatePanel());
        }

        if (UsesNumericPrimaryInput())
        {
            panel.Children.Add(BuildNumberInputPanel());
        }

        if (_inputBox.Visibility == Visibility.Visible)
        {
            panel.Children.Add(_inputBox);
        }

        var actions = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 10,
            Margin = new Thickness(0, 2, 0, 0)
        };
        AddSemanticActions(actions);
        panel.Children.Add(new ScrollViewer
        {
            HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
            VerticalScrollBarVisibility = ScrollBarVisibility.Disabled,
            Content = actions
        });

        return ModernUi.Card(panel, new Thickness(16), radius: 8);
    }

    private Border? BuildGalleryAssistPanel(IToolModule module)
    {
        if (_spec.AssistPanelMode is ToolAssistPanelMode.Hidden or ToolAssistPanelMode.Custom)
        {
            return null;
        }

        var content = BuildAssistPanelContent(module);
        if (content.Children.Count == 0)
        {
            return null;
        }

        var expander = new Expander
        {
            Header = BuildGallerySectionHeader(
                AppLocalizer.T("选项", "Options"),
                AssistPanelTitle(),
                RuleDescription(module),
                "\uE713",
                compact: true),
            IsExpanded = _spec.AssistPanelMode != ToolAssistPanelMode.SourceOnly,
            Content = content
        };

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

    private Border? BuildCompactDescriptionPanel(IToolModule module)
    {
        if (!_spec.ShowDescription && module.Metadata.OfflineCapable)
        {
            return null;
        }

        var content = new StackPanel
        {
            Spacing = 10,
            Children =
            {
                ModernUi.Text(ToolText.Description(module), 13, foreground: ModernUi.TextSecondary, maxLines: 4),
                ModernUi.Text(RuleDescription(module), 13, foreground: ModernUi.TextSecondary, maxLines: 5)
            }
        };

        return ModernUi.Card(new Expander
        {
            Header = BuildGallerySectionHeader(
                AppLocalizer.T("说明", "Info"),
                AppLocalizer.T("工具说明", "Tool info"),
                AppLocalizer.T("默认折叠，避免占用操作区。", "Collapsed by default to keep the work area clear."),
                "\uE946",
                compact: true),
            IsExpanded = false,
            Content = content
        }, new Thickness(14), radius: 8);
    }

    private Border BuildGalleryResultCard()
    {
        if (_resultCards.Children.Count == 0)
        {
            _resultCards.Children.Add(BuildGalleryEmptyResult());
        }

        var header = new Grid { ColumnSpacing = 12 };
        header.ColumnDefinitions.Add(new ColumnDefinition());

        header.Children.Add(BuildGallerySectionHeader(
            AppLocalizer.T("输出", "Output"),
            AppLocalizer.T("结果", "Result"),
            EmptyStateText(),
            "\uE9D9",
            compact: true));

        var actions = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 8,
            Children =
            {
                BuildResultModeToggle(),
                ModernUi.PillButton(AppLocalizer.T("复制", "Copy"), "\uE8C8", CopyResult),
                ModernUi.PillButton(AppLocalizer.T("导出", "Export"), "\uE74E", async () => await ExportResultAsync())
            }
        };

        var searchRow = new Grid { ColumnSpacing = 10 };
        searchRow.ColumnDefinitions.Add(new ColumnDefinition());
        searchRow.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        searchRow.Children.Add(_resultSearchBox);
        Grid.SetColumn(_resultSearchStatus, 1);
        searchRow.Children.Add(_resultSearchStatus);

        var actionScroll = new ScrollViewer
        {
            HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
            VerticalScrollBarVisibility = ScrollBarVisibility.Disabled,
            Content = actions
        };

        var resultHost = new Grid();
        resultHost.Children.Add(_resultWebView);
        resultHost.Children.Add(_renderedResultScroll);
        resultHost.Children.Add(_outputBox);

        return ModernUi.Card(new StackPanel
        {
            Spacing = 16,
            Children = { header, searchRow, actionScroll, resultHost }
        }, new Thickness(18), radius: 8);
    }

    private UIElement BuildResultModeToggle()
    {
        var row = new StackPanel
        {
            Orientation = Orientation.Horizontal,
            Spacing = 6
        };

        _renderedResultButton = ResultModeButton(
            AppLocalizer.T("结果", "Result"),
            "\uE9D9",
            () => SetResultViewMode(showRaw: false));
        _rawResultButton = ResultModeButton(
            AppLocalizer.T("原始输出", "Raw output"),
            "\uE8A5",
            () => SetResultViewMode(showRaw: true));

        row.Children.Add(_renderedResultButton);
        row.Children.Add(_rawResultButton);
        UpdateResultModeButtons();
        return row;
    }

    private static Button ResultModeButton(string text, string glyph, Action click)
    {
        var icon = new FontIcon
        {
            Glyph = glyph,
            FontSize = 13,
            Foreground = ModernUi.TextSecondary
        };
        var label = ModernUi.Text(text, 13, FontWeights.SemiBold, ModernUi.TextSecondary, maxLines: 1);
        var button = new Button
        {
            Padding = new Thickness(10, 6, 10, 7),
            CornerRadius = new CornerRadius(6),
            BorderThickness = new Thickness(1),
            Background = ModernUi.SurfaceAlt,
            BorderBrush = ModernUi.Stroke,
            Content = new StackPanel
            {
                Orientation = Orientation.Horizontal,
                Spacing = 6,
                Children = { icon, label }
            },
            Tag = Tuple.Create(icon, label)
        };

        button.Click += (_, _) => click();
        ToolTipService.SetToolTip(button, text);
        return button;
    }

    private void UpdateResultModeButtons()
    {
        UpdateResultModeButton(_renderedResultButton, !_showRawResult);
        UpdateResultModeButton(_rawResultButton, _showRawResult);
    }

    private static void UpdateResultModeButton(Button? button, bool selected)
    {
        if (button is null)
        {
            return;
        }

        button.Background = selected ? ModernUi.AccentSoft : ModernUi.SurfaceAlt;
        button.BorderBrush = selected ? ModernUi.Accent : ModernUi.Stroke;
        if (button.Tag is Tuple<FontIcon, TextBlock> parts)
        {
            parts.Item1.Foreground = selected ? ModernUi.Accent : ModernUi.TextSecondary;
            parts.Item2.Foreground = selected ? ModernUi.Accent : ModernUi.TextSecondary;
        }
    }

    private Button BuildResultMoreButton()
    {
        var button = ModernUi.PillButton(AppLocalizer.T("更多", "More"), "\uE712");
        var flyout = new MenuFlyout();
        var resultMode = new MenuFlyoutItem
        {
            Text = ResultModeText(),
            Icon = new FontIcon { Glyph = ResultModeGlyph() }
        };
        resultMode.Click += (_, _) => SetResultViewMode(!_showRawResult);
        flyout.Opening += (_, _) =>
        {
            resultMode.Text = ResultModeText();
            resultMode.Icon = new FontIcon { Glyph = ResultModeGlyph() };
        };
        flyout.Items.Add(resultMode);
        button.Flyout = flyout;
        return button;
    }

    private void ArrangeGalleryToolGrid()
    {
        UpdateAdaptiveWebViewHeights(ActualHeight);
        if (_uiPerformanceCoordinator.IsLightMode)
        {
            _arrangeDebounce.Stop();
            _arrangeDebounce.Start();
            return;
        }

        ArrangeGalleryToolGridCore();
    }

    private void ArrangeGalleryToolGridCore()
    {
        if (_toolGrid.Children.Count is < 2 or > 3)
        {
            return;
        }

        if (ActualWidth > 0)
        {
            _toolGrid.Width = Math.Max(420, ActualWidth - 72);
        }

        var hasAssistPanel = _toolGrid.Children.Count == 3;
        var oneColumn = ActualWidth < 1180;

        _toolGrid.ColumnDefinitions.Clear();
        _toolGrid.RowDefinitions.Clear();
        _toolGrid.ColumnDefinitions.Add(new ColumnDefinition());

        if (oneColumn)
        {
            for (var index = 0; index < _toolGrid.Children.Count; index++)
            {
                _toolGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
                var element = (FrameworkElement)_toolGrid.Children[index];
                Grid.SetColumn(element, 0);
                Grid.SetColumnSpan(element, 1);
                Grid.SetRow(element, index);
            }

            return;
        }

        _toolGrid.ColumnDefinitions.Clear();
        _toolGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(420) });
        _toolGrid.ColumnDefinitions.Add(new ColumnDefinition());
        _toolGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });

        var input = (FrameworkElement)_toolGrid.Children[0];
        var result = (FrameworkElement)_toolGrid.Children[^1];

        Grid.SetColumn(input, 0);
        Grid.SetRow(input, 0);
        Grid.SetColumnSpan(input, 1);

        if (hasAssistPanel)
        {
            _toolGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            var assist = (FrameworkElement)_toolGrid.Children[1];
            Grid.SetColumn(assist, 0);
            Grid.SetRow(assist, 1);
            Grid.SetColumnSpan(assist, 1);

            Grid.SetRowSpan(result, 2);
        }
        else
        {
            Grid.SetRowSpan(result, 1);
        }

        Grid.SetColumn(result, 1);
        Grid.SetColumnSpan(result, 1);
        Grid.SetRow(result, 0);
    }

    private static Grid BuildGallerySectionHeader(string eyebrow, string title, string description, string glyph, bool compact = false)
    {
        var grid = new Grid { ColumnSpacing = 12 };
        grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        grid.ColumnDefinitions.Add(new ColumnDefinition());

        grid.Children.Add(ModernUi.IconTile(glyph, compact ? 34 : 40, ModernUi.AccentSoft, ModernUi.Accent, compact ? 15 : 18));
        var text = new StackPanel
        {
            Spacing = compact ? 1 : 3,
            Children =
            {
                ModernUi.Text(eyebrow, 12, FontWeights.SemiBold, ModernUi.Accent, maxLines: 1),
                ModernUi.Text(title, compact ? 16 : 18, FontWeights.SemiBold, maxLines: 1),
                ModernUi.Text(description, 12.5, foreground: ModernUi.TextSecondary, maxLines: compact ? 2 : 3)
            }
        };
        Grid.SetColumn(text, 1);
        grid.Children.Add(text);
        return grid;
    }

    private static Border BuildGalleryEmptyResult()
    {
        var row = new Grid { ColumnSpacing = 12 };
        row.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
        row.ColumnDefinitions.Add(new ColumnDefinition());
        row.Children.Add(ModernUi.IconTile("\uE946", 38, ModernUi.SurfaceAlt, ModernUi.TextSecondary, 17));
        var text = new StackPanel
        {
            Spacing = 2,
            Children =
            {
                ModernUi.Text(AppLocalizer.T("等待执行", "Ready"), 13, FontWeights.SemiBold),
                ModernUi.Text(AppLocalizer.T("执行工具后，这里会显示结构化结果。", "Run the tool to render structured results here."), 12, foreground: ModernUi.TextSecondary, maxLines: 2)
            }
        };
        Grid.SetColumn(text, 1);
        row.Children.Add(text);
        return ModernUi.Card(row, new Thickness(12), radius: 8, background: ModernUi.SurfaceAlt);
    }

    private static string EmptyStateText()
    {
        return AppLocalizer.T("执行后显示结构化结果。", "Structured results appear after running.");
    }

    private string CompactInputDescription(IToolModule module)
    {
        if (_spec.AutoRunOnOpen || _spec.PrimaryInput == ToolPrimaryInputKind.None)
        {
            return AppLocalizer.T("进入页面后自动载入，可按需重新加载。", "Loads on open and can be reloaded when needed.");
        }

        if (!module.Metadata.OfflineCapable)
        {
            return AppLocalizer.T("输入查询条件后获取公开数据源结果。", "Enter a query to fetch public source results.");
        }

        return AppLocalizer.T("填写参数后执行。", "Set values, then run.");
    }

    private static string InteractionLabel(ToolInteractionMode mode)
    {
        return mode switch
        {
            ToolInteractionMode.AutoLoad => AppLocalizer.T("自动加载", "Auto load"),
            ToolInteractionMode.LivePreview => AppLocalizer.T("实时预览", "Live preview"),
            ToolInteractionMode.NativeLauncher => AppLocalizer.T("原生窗口", "Native window"),
            ToolInteractionMode.MediaViewer => AppLocalizer.T("媒体视图", "Media viewer"),
            ToolInteractionMode.ReferenceBrowser => AppLocalizer.T("参考浏览", "Reference browser"),
            _ => AppLocalizer.T("手动执行", "Manual run")
        };
    }

    private static string LayoutLabel(ToolLayoutKind layout)
    {
        return layout switch
        {
            ToolLayoutKind.FormatterWorkbench => AppLocalizer.T("格式化", "Formatter"),
            ToolLayoutKind.CodecWorkbench => AppLocalizer.T("编解码", "Codec"),
            ToolLayoutKind.QueryDashboard => AppLocalizer.T("查询", "Query"),
            ToolLayoutKind.Dashboard => AppLocalizer.T("看板", "Dashboard"),
            ToolLayoutKind.CalculatorForm => AppLocalizer.T("计算", "Calculator"),
            ToolLayoutKind.UnitConverter => AppLocalizer.T("换算", "Converter"),
            ToolLayoutKind.ReferenceBrowser => AppLocalizer.T("速查", "Reference"),
            ToolLayoutKind.FileWorkflow => AppLocalizer.T("文件", "File"),
            ToolLayoutKind.MediaNative => AppLocalizer.T("媒体", "Media"),
            ToolLayoutKind.BrowserNative => AppLocalizer.T("浏览器", "Browser"),
            ToolLayoutKind.RandomCinema => AppLocalizer.T("远程媒体", "Remote media"),
            ToolLayoutKind.SystemLauncher => AppLocalizer.T("系统", "System"),
            ToolLayoutKind.SecurityWorkbench => AppLocalizer.T("安全", "Security"),
            _ => AppLocalizer.T("文本", "Text")
        };
    }

    private static string ResultLabel(ToolResultKind result)
    {
        return result switch
        {
            ToolResultKind.JsonTree => AppLocalizer.T("JSON 树", "JSON tree"),
            ToolResultKind.CodePreview => AppLocalizer.T("代码预览", "Code preview"),
            ToolResultKind.Table => AppLocalizer.T("表格", "Table"),
            ToolResultKind.RankedList => AppLocalizer.T("榜单", "Ranked list"),
            ToolResultKind.NewsCards => AppLocalizer.T("新闻卡片", "News cards"),
            ToolResultKind.ImagePreview => AppLocalizer.T("图片预览", "Image preview"),
            ToolResultKind.LinkCards => AppLocalizer.T("链接", "Links"),
            ToolResultKind.FileCards => AppLocalizer.T("文件", "Files"),
            ToolResultKind.Diff => AppLocalizer.T("差异", "Diff"),
            ToolResultKind.StatusList => AppLocalizer.T("状态", "Status"),
            ToolResultKind.ColorSwatch => AppLocalizer.T("颜色", "Color"),
            ToolResultKind.CalculatorTable => AppLocalizer.T("结果表", "Result table"),
            ToolResultKind.SystemCards => AppLocalizer.T("系统卡片", "System cards"),
            ToolResultKind.Media => AppLocalizer.T("媒体", "Media"),
            ToolResultKind.ReferenceRows => AppLocalizer.T("参考数据", "Reference"),
            _ => AppLocalizer.T("文本", "Text")
        };
    }
}
