// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Dashboard.Model;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace Aspire.Dashboard.Components.Dialogs;
/// <summary>
/// The keyboard shortcuts the dashboard offers, grouped by category. Shown in a tab of <see cref="HelpDialog"/>.
/// </summary>
public partial class KeyboardShortcutsHelp
{
[Inject]
public required IStringLocalizer<Resources.Dialogs> Loc { get; init; }
[Inject]
public required ShortcutManager ShortcutManager { get; init; }
private List<KeyboardShortcutCategory> GetShortcutsByCategory()
{
List<KeyboardShortcutCategory> categories =
[
new(Loc[nameof(Resources.Dialogs.HelpDialogCategoryPageNavigation)],
[
new KeyboardShortcut(AspireKeyboardShortcut.GoToResources, ["r"], Loc[nameof(Resources.Dialogs.HelpDialogGoToResources)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToParameters, ["p"], Loc[nameof(Resources.Dialogs.HelpDialogGoToParameters)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToGraph, ["g"], Loc[nameof(Resources.Dialogs.HelpDialogGoToGraph)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToTerminals, ["e"], Loc[nameof(Resources.Dialogs.HelpDialogGoToTerminals)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToExtensions, ["x"], Loc[nameof(Resources.Dialogs.HelpDialogGoToExtensions)]),
]),
new(Loc[nameof(Resources.Dialogs.HelpDialogCategoryTelemetry)],
[
new KeyboardShortcut(AspireKeyboardShortcut.GoToTelemetrySources, ["o"], Loc[nameof(Resources.Dialogs.HelpDialogGoToTelemetrySources)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToConsoleLogs, ["c"], Loc[nameof(Resources.Dialogs.HelpDialogGoToConsoleLogs)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToStructuredLogs, ["s"], Loc[nameof(Resources.Dialogs.HelpDialogGoToStructuredLogs)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToTraces, ["t"], Loc[nameof(Resources.Dialogs.HelpDialogGoToTraces)]),
new KeyboardShortcut(AspireKeyboardShortcut.GoToMetrics, ["m"], Loc[nameof(Resources.Dialogs.HelpDialogGoToMetrics)]),
]),
new(Loc[nameof(Resources.Dialogs.HelpDialogCategoryResourceGraph)],
[
// Handled by the graph rather than ShortcutManager, so it has no shortcut of its own. It's available wherever
// the graph is, which is what GoToGraph's availability says.
new KeyboardShortcut(AspireKeyboardShortcut.GoToGraph, ["o"], Loc[nameof(Resources.Dialogs.HelpDialogPlayGame)]),
]),
new(Loc[nameof(Resources.Dialogs.HelpDialogCategoryPanels)],
[
new KeyboardShortcut(AspireKeyboardShortcut.IncreasePanelSize, ["+"], Loc[nameof(Resources.Dialogs.HelpDialogIncreasePanelSize)]),
new KeyboardShortcut(AspireKeyboardShortcut.DecreasePanelSize, ["-"], Loc[nameof(Resources.Dialogs.HelpDialogDecreasePanelSize)]),
new KeyboardShortcut(AspireKeyboardShortcut.ResetPanelSize, ["Shift", "R"], Loc[nameof(Resources.Dialogs.HelpDialogResetPanelSize)]),
new KeyboardShortcut(AspireKeyboardShortcut.ToggleOrientation, ["Shift", "T"], Loc[nameof(Resources.Dialogs.HelpDialogTogglePanelOrientation)]),
new KeyboardShortcut(AspireKeyboardShortcut.ClosePanel, ["Shift", "X"], Loc[nameof(Resources.Dialogs.HelpDialogTogglePanelOpen)]),
]),
new(Loc[nameof(Resources.Dialogs.HelpDialogCategoryNavigation)],
[
new KeyboardShortcut(AspireKeyboardShortcut.Help, ["?"], Loc[nameof(Resources.Dialogs.HelpDialogGoToHelp)]),
new KeyboardShortcut(AspireKeyboardShortcut.Settings, ["Shift", "S"], Loc[nameof(Resources.Dialogs.HelpDialogGoToSettings)]),
new KeyboardShortcut(AspireKeyboardShortcut.ToggleTerminalDock, ["`"], Loc[nameof(Resources.Dialogs.HelpDialogToggleTerminalDock)]),
])
];
foreach (var category in categories)
{
category.Shortcuts.RemoveAll(shortcut => !ShortcutManager.IsShortcutAvailable(shortcut.Shortcut));
}
categories.RemoveAll(category => category.Shortcuts.Count == 0);
return categories;
}
}