import '../../../../base/browser/ui/codicons/codicon/codicon.css.js';
import '../../../../base/browser/ui/codicons/codicon/codicon-modifiers.css.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { CodeActionKind } from '../common/types.js';
import '../../symbolIcons/browser/symbolIcons.js';
import { localizeWithPath } from '../../../../nls.js';
import { ActionListItemKind } from '../../../../platform/actionWidget/browser/actionList.js';
import { HierarchicalKind } from '../../../../base/common/hierarchicalKind.js';
const _moduleId = "vs/editor/contrib/codeAction/browser/codeActionMenu";
const uncategorizedCodeActionGroup = ( (Object.freeze({ kind: HierarchicalKind.Empty, title: ( localizeWithPath(_moduleId, 0, 'More Actions...')) })));
const codeActionGroups = ( (Object.freeze([
    { kind: CodeActionKind.QuickFix, title: ( localizeWithPath(_moduleId, 1, 'Quick Fix')) },
    { kind: CodeActionKind.RefactorExtract, title: ( localizeWithPath(_moduleId, 2, 'Extract')), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorInline, title: ( localizeWithPath(_moduleId, 3, 'Inline')), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorRewrite, title: ( localizeWithPath(_moduleId, 4, 'Rewrite')), icon: Codicon.wrench },
    { kind: CodeActionKind.RefactorMove, title: ( localizeWithPath(_moduleId, 5, 'Move')), icon: Codicon.wrench },
    { kind: CodeActionKind.SurroundWith, title: ( localizeWithPath(_moduleId, 6, 'Surround With')), icon: Codicon.surroundWith },
    { kind: CodeActionKind.Source, title: ( localizeWithPath(_moduleId, 7, 'Source Action')), icon: Codicon.symbolFile },
    uncategorizedCodeActionGroup,
])));
function toMenuItems(inputCodeActions, showHeaders, keybindingResolver) {
    if (!showHeaders) {
        return (
             (inputCodeActions.map((action) => {
                return {
                    kind: ActionListItemKind.Action,
                    item: action,
                    group: uncategorizedCodeActionGroup,
                    disabled: !!action.action.disabled,
                    label: action.action.disabled || action.action.title,
                    canPreview: !!action.action.edit?.edits.length,
                };
            }))
        );
    }
    const menuEntries = ( (codeActionGroups.map(group => ({ group, actions: [] }))));
    for (const action of inputCodeActions) {
        const kind = action.action.kind ? ( (new HierarchicalKind(action.action.kind))) : HierarchicalKind.None;
        for (const menuEntry of menuEntries) {
            if (menuEntry.group.kind.contains(kind)) {
                menuEntry.actions.push(action);
                break;
            }
        }
    }
    const allMenuItems = [];
    for (const menuEntry of menuEntries) {
        if (menuEntry.actions.length) {
            allMenuItems.push({ kind: ActionListItemKind.Header, group: menuEntry.group });
            for (const action of menuEntry.actions) {
                const group = menuEntry.group;
                allMenuItems.push({
                    kind: ActionListItemKind.Action,
                    item: action,
                    group: action.action.isAI ? { title: group.title, kind: group.kind, icon: Codicon.sparkle } : group,
                    label: action.action.title,
                    disabled: !!action.action.disabled,
                    keybinding: keybindingResolver(action.action),
                });
            }
        }
    }
    return allMenuItems;
}
export { toMenuItems };
