
import { Action, Separator, SubmenuAction } from '../../../../base/common/actions.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { Schemas } from '../../../../base/common/network.js';
import { localize, localize2 } from '../../../../nls.js';
import { MenuRegistry, MenuId } from '../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { TerminalSettingId, TerminalLocation } from '../../../../platform/terminal/common/terminal.js';
import { ResourceContextKey } from '../../../common/contextkeys.js';
import { TaskExecutionSupportedContext } from '../../tasks/common/taskService.js';
import { TerminalCommandId, TERMINAL_VIEW_ID } from '../common/terminal.js';
import { TerminalContextKeys, TerminalContextKeyStrings } from '../common/terminalContextKey.js';
import { terminalStrings } from '../common/terminalStrings.js';
import { ACTIVE_GROUP, SIDE_GROUP, AUX_WINDOW_GROUP } from '../../../services/editor/common/editorService.js';
import { HasSpeechProvider } from '../../speech/common/speechService.js';
import { hasKey } from '../../../../base/common/types.js';
import { TerminalContribContextKeyStrings } from '../terminalContribExports.js';

var TerminalContextMenuGroup;
(function(TerminalContextMenuGroup) {
    TerminalContextMenuGroup["Chat"] = "0_chat";
    TerminalContextMenuGroup["Create"] = "1_create";
    TerminalContextMenuGroup["Edit"] = "3_edit";
    TerminalContextMenuGroup["Clear"] = "5_clear";
    TerminalContextMenuGroup["Kill"] = "7_kill";
    TerminalContextMenuGroup["Config"] = "9_config";
})(TerminalContextMenuGroup || (TerminalContextMenuGroup = {}));
var TerminalMenuBarGroup;
(function(TerminalMenuBarGroup) {
    TerminalMenuBarGroup["Create"] = "1_create";
    TerminalMenuBarGroup["Run"] = "3_run";
    TerminalMenuBarGroup["Manage"] = "5_manage";
    TerminalMenuBarGroup["Configure"] = "7_configure";
})(TerminalMenuBarGroup || (TerminalMenuBarGroup = {}));
function setupTerminalMenus() {
    MenuRegistry.appendMenuItems([{
        id: MenuId.MenubarTerminalMenu,
        item: {
            group: TerminalMenuBarGroup.Create,
            command: {
                id: TerminalCommandId.New,
                title: ( localize(14217, "&&New Terminal"))
            },
            order: 1
        }
    }, {
        id: MenuId.MenubarTerminalMenu,
        item: {
            group: TerminalMenuBarGroup.Create,
            command: {
                id: TerminalCommandId.NewInNewWindow,
                title: ( localize(14218, "New Terminal &&Window")),
                precondition: ( ContextKeyExpr.has(TerminalContextKeyStrings.IsOpen))
            },
            order: 2,
            when: TerminalContextKeys.processSupported
        }
    }, {
        id: MenuId.MenubarTerminalMenu,
        item: {
            group: TerminalMenuBarGroup.Create,
            command: {
                id: TerminalCommandId.Split,
                title: ( localize(14219, "&&Split Terminal")),
                precondition: ( ContextKeyExpr.has(TerminalContextKeyStrings.IsOpen))
            },
            order: 2,
            when: TerminalContextKeys.processSupported
        }
    }, {
        id: MenuId.MenubarTerminalMenu,
        item: {
            group: TerminalMenuBarGroup.Run,
            command: {
                id: TerminalCommandId.RunActiveFile,
                title: ( localize(14220, "Run &&Active File"))
            },
            order: 3,
            when: TerminalContextKeys.processSupported
        }
    }, {
        id: MenuId.MenubarTerminalMenu,
        item: {
            group: TerminalMenuBarGroup.Run,
            command: {
                id: TerminalCommandId.RunSelectedText,
                title: ( localize(14221, "Run &&Selected Text"))
            },
            order: 4,
            when: TerminalContextKeys.processSupported
        }
    }]);
    MenuRegistry.appendMenuItems([{
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.KillViewOrEditor,
                title: terminalStrings.kill.value
            },
            group: TerminalContextMenuGroup.Kill
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.CopySelection,
                title: ( localize(14222, "Copy"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 1
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.CopySelectionAsHtml,
                title: ( localize(14223, "Copy as HTML"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 2
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.Paste,
                title: ( localize(14224, "Paste"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 3
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.Clear,
                title: ( localize(14225, "Clear"))
            },
            group: TerminalContextMenuGroup.Clear
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.SizeToContentWidth,
                title: terminalStrings.toggleSizeToContentWidth
            },
            group: TerminalContextMenuGroup.Config
        }
    }, {
        id: MenuId.TerminalInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.SelectAll,
                title: ( localize(14226, "Select All"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 3
        }
    }]);
    MenuRegistry.appendMenuItem(MenuId.EditorTabsBarContext, {
        command: {
            id: TerminalCommandId.CreateTerminalEditorSameGroup,
            title: terminalStrings.new
        },
        group: "1_zzz_file",
        order: 30,
        when: TerminalContextKeys.processSupported
    });
    MenuRegistry.appendMenuItem(MenuId.EmptyEditorGroupContext, {
        command: {
            id: TerminalCommandId.CreateTerminalEditorSameGroup,
            title: terminalStrings.new
        },
        group: "1_zzz_file",
        order: 30,
        when: TerminalContextKeys.processSupported
    });
    MenuRegistry.appendMenuItems([{
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            group: TerminalContextMenuGroup.Create,
            command: {
                id: TerminalCommandId.Split,
                title: terminalStrings.split.value
            }
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.New,
                title: terminalStrings.new
            },
            group: TerminalContextMenuGroup.Create
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.KillEditor,
                title: terminalStrings.kill.value
            },
            group: TerminalContextMenuGroup.Kill
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.CopySelection,
                title: ( localize(14222, "Copy"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 1
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.CopySelectionAsHtml,
                title: ( localize(14223, "Copy as HTML"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 2
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.Paste,
                title: ( localize(14224, "Paste"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 3
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.Clear,
                title: ( localize(14225, "Clear"))
            },
            group: TerminalContextMenuGroup.Clear
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.SelectAll,
                title: ( localize(14226, "Select All"))
            },
            group: TerminalContextMenuGroup.Edit,
            order: 3
        }
    }, {
        id: MenuId.TerminalEditorInstanceContext,
        item: {
            command: {
                id: TerminalCommandId.SizeToContentWidth,
                title: terminalStrings.toggleSizeToContentWidth
            },
            group: TerminalContextMenuGroup.Config
        }
    }]);
    MenuRegistry.appendMenuItems([{
        id: MenuId.TerminalTabEmptyAreaContext,
        item: {
            command: {
                id: TerminalCommandId.NewWithProfile,
                title: ( localize(14227, "New Terminal With Profile..."))
            },
            group: TerminalContextMenuGroup.Create
        }
    }, {
        id: MenuId.TerminalTabEmptyAreaContext,
        item: {
            command: {
                id: TerminalCommandId.New,
                title: terminalStrings.new
            },
            group: TerminalContextMenuGroup.Create
        }
    }]);
    MenuRegistry.appendMenuItems([{
        id: MenuId.TerminalNewDropdownContext,
        item: {
            command: {
                id: TerminalCommandId.SelectDefaultProfile,
                title: ( localize2(14228, "Select Default Profile"))
            },
            group: "3_configure"
        }
    }, {
        id: MenuId.TerminalNewDropdownContext,
        item: {
            command: {
                id: TerminalCommandId.ConfigureTerminalSettings,
                title: ( localize(14229, "Configure Terminal Settings"))
            },
            group: "3_configure"
        }
    }, {
        id: MenuId.TerminalNewDropdownContext,
        item: {
            command: {
                id: "workbench.action.tasks.runTask",
                title: ( localize(14230, "Run Task..."))
            },
            when: TaskExecutionSupportedContext,
            group: "4_tasks",
            order: 1
        }
    }, {
        id: MenuId.TerminalNewDropdownContext,
        item: {
            command: {
                id: "workbench.action.tasks.configureTaskRunner",
                title: ( localize(14231, "Configure Tasks..."))
            },
            when: TaskExecutionSupportedContext,
            group: "4_tasks",
            order: 2
        }
    }]);
    MenuRegistry.appendMenuItems([{
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.SwitchTerminal,
                title: ( localize2(14232, "Switch Terminal"))
            },
            group: "navigation",
            order: 0,
            when: ( ContextKeyExpr.and(( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)), ContextKeyExpr.not(`config.${TerminalSettingId.TabsEnabled}`)))
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.Focus,
                title: terminalStrings.focus
            },
            alt: {
                id: TerminalCommandId.Split,
                title: terminalStrings.split.value,
                icon: Codicon.splitHorizontal
            },
            group: "navigation",
            order: 0,
            when: ( ContextKeyExpr.and(
                ContextKeyExpr.not(TerminalContribContextKeyStrings.ChatHasHiddenTerminals),
                ( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)),
                ( ContextKeyExpr.has(`config.${TerminalSettingId.TabsEnabled}`)),
                ( ContextKeyExpr.or(( ContextKeyExpr.and(( ContextKeyExpr.equals(`config.${TerminalSettingId.TabsShowActiveTerminal}`, "singleTerminal")), ( ContextKeyExpr.equals(TerminalContextKeyStrings.GroupCount, 1)))), ( ContextKeyExpr.and(( ContextKeyExpr.equals(
                    `config.${TerminalSettingId.TabsShowActiveTerminal}`,
                    "singleTerminalOrNarrow"
                )), ( ContextKeyExpr.or(( ContextKeyExpr.equals(TerminalContextKeyStrings.GroupCount, 1)), ( ContextKeyExpr.has(TerminalContextKeyStrings.TabsNarrow)))))), ( ContextKeyExpr.and(( ContextKeyExpr.equals(`config.${TerminalSettingId.TabsShowActiveTerminal}`, "singleGroup")), ( ContextKeyExpr.equals(TerminalContextKeyStrings.GroupCount, 1)))), ( ContextKeyExpr.equals(`config.${TerminalSettingId.TabsShowActiveTerminal}`, "always"))))
            ))
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.Split,
                title: terminalStrings.split,
                icon: Codicon.splitHorizontal
            },
            group: "navigation",
            order: 2,
            when: TerminalContextKeys.shouldShowViewInlineActions
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.Kill,
                title: terminalStrings.kill,
                icon: Codicon.trash
            },
            group: "navigation",
            order: 3,
            when: TerminalContextKeys.shouldShowViewInlineActions
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.New,
                title: terminalStrings.new,
                icon: Codicon.plus
            },
            alt: {
                id: TerminalCommandId.Split,
                title: terminalStrings.split.value,
                icon: Codicon.splitHorizontal
            },
            group: "navigation",
            order: 0,
            when: ( ContextKeyExpr.and(( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)), ( ContextKeyExpr.or(
                TerminalContextKeys.webExtensionContributedProfile,
                TerminalContextKeys.processSupported
            ))))
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.Clear,
                title: ( localize(14233, "Clear Terminal")),
                icon: Codicon.clearAll
            },
            group: "navigation",
            order: 6,
            when: ( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)),
            isHiddenByDefault: true
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.RunActiveFile,
                title: ( localize(14234, "Run Active File")),
                icon: Codicon.run
            },
            group: "navigation",
            order: 7,
            when: ( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)),
            isHiddenByDefault: true
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.RunSelectedText,
                title: ( localize(14235, "Run Selected Text")),
                icon: Codicon.selection
            },
            group: "navigation",
            order: 8,
            when: ( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)),
            isHiddenByDefault: true
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.StartVoice,
                title: ( localize(14236, "Start Dictation"))
            },
            group: "navigation",
            order: 9,
            when: ( ContextKeyExpr.and(( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)), ( TerminalContextKeys.terminalDictationInProgress.toNegated()))),
            isHiddenByDefault: true
        }
    }, {
        id: MenuId.ViewTitle,
        item: {
            command: {
                id: TerminalCommandId.StopVoice,
                title: ( localize(14237, "Stop Dictation"))
            },
            group: "navigation",
            order: 9,
            when: ( ContextKeyExpr.and(( ContextKeyExpr.equals("view", TERMINAL_VIEW_ID)), TerminalContextKeys.terminalDictationInProgress)),
            isHiddenByDefault: true
        }
    }]);
    MenuRegistry.appendMenuItems([{
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.SplitActiveTab,
                title: terminalStrings.split.value
            },
            group: TerminalContextMenuGroup.Create,
            order: 1
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.MoveToEditor,
                title: terminalStrings.moveToEditor.value
            },
            group: TerminalContextMenuGroup.Create,
            order: 2
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.MoveIntoNewWindow,
                title: terminalStrings.moveIntoNewWindow.value
            },
            group: TerminalContextMenuGroup.Create,
            order: 2
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.RenameActiveTab,
                title: ( localize(14238, "Rename..."))
            },
            group: TerminalContextMenuGroup.Edit
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.ChangeIconActiveTab,
                title: ( localize(14239, "Change Icon..."))
            },
            group: TerminalContextMenuGroup.Edit
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.ChangeColorActiveTab,
                title: ( localize(14240, "Change Color..."))
            },
            group: TerminalContextMenuGroup.Edit
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.SizeToContentWidth,
                title: terminalStrings.toggleSizeToContentWidth
            },
            group: TerminalContextMenuGroup.Edit
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.JoinActiveTab,
                title: ( localize(14241, "Join Terminals"))
            },
            when: ( TerminalContextKeys.tabsSingularSelection.toNegated()),
            group: TerminalContextMenuGroup.Config
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.Unsplit,
                title: terminalStrings.unsplit.value
            },
            when: ( ContextKeyExpr.and(
                TerminalContextKeys.tabsSingularSelection,
                TerminalContextKeys.splitTerminalTabFocused
            )),
            group: TerminalContextMenuGroup.Config
        }
    }, {
        id: MenuId.TerminalTabContext,
        item: {
            command: {
                id: TerminalCommandId.KillActiveTab,
                title: terminalStrings.kill.value
            },
            group: TerminalContextMenuGroup.Kill
        }
    }]);
    MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
        command: {
            id: TerminalCommandId.MoveToTerminalPanel,
            title: terminalStrings.moveToTerminalPanel
        },
        when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
        group: "2_files"
    });
    MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
        command: {
            id: TerminalCommandId.Rename,
            title: terminalStrings.rename
        },
        when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
        group: "2_files"
    });
    MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
        command: {
            id: TerminalCommandId.ChangeColor,
            title: terminalStrings.changeColor
        },
        when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
        group: "2_files"
    });
    MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
        command: {
            id: TerminalCommandId.ChangeIcon,
            title: terminalStrings.changeIcon
        },
        when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
        group: "2_files"
    });
    MenuRegistry.appendMenuItem(MenuId.EditorTitleContext, {
        command: {
            id: TerminalCommandId.SizeToContentWidth,
            title: terminalStrings.toggleSizeToContentWidth
        },
        when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
        group: "2_files"
    });
    for (const menuId of [MenuId.EditorTitle, MenuId.CompactWindowEditorTitle]) {
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.CreateTerminalEditorSameGroup,
                title: terminalStrings.new,
                icon: Codicon.plus
            },
            alt: {
                id: TerminalCommandId.Split,
                title: terminalStrings.split.value,
                icon: Codicon.splitHorizontal
            },
            group: "navigation",
            order: 0,
            when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal))
        });
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.Clear,
                title: ( localize(14233, "Clear Terminal")),
                icon: Codicon.clearAll
            },
            group: "navigation",
            order: 6,
            when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
            isHiddenByDefault: true
        });
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.RunActiveFile,
                title: ( localize(14234, "Run Active File")),
                icon: Codicon.run
            },
            group: "navigation",
            order: 7,
            when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
            isHiddenByDefault: true
        });
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.RunSelectedText,
                title: ( localize(14235, "Run Selected Text")),
                icon: Codicon.selection
            },
            group: "navigation",
            order: 8,
            when: ( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)),
            isHiddenByDefault: true
        });
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.StartVoice,
                title: ( localize(14242, "Start Dictation")),
                icon: Codicon.mic
            },
            group: "navigation",
            order: 9,
            when: ( ContextKeyExpr.and(( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)), ( TerminalContextKeys.terminalDictationInProgress.negate()))),
            isHiddenByDefault: true
        });
        MenuRegistry.appendMenuItem(menuId, {
            command: {
                id: TerminalCommandId.StopVoice,
                title: ( localize(14243, "Stop Dictation")),
                icon: Codicon.run
            },
            group: "navigation",
            order: 10,
            when: ( ContextKeyExpr.and(( ResourceContextKey.Scheme.isEqualTo(Schemas.vscodeTerminal)), HasSpeechProvider, TerminalContextKeys.terminalDictationInProgress)),
            isHiddenByDefault: true
        });
    }
}
function getTerminalActionBarArgs(
    location,
    profiles,
    defaultProfileName,
    contributedProfiles,
    terminalService,
    dropdownMenu,
    disposableStore
) {
    profiles = profiles.filter(e => !e.isAutoDetected);
    const [aiProfiles, otherProfiles] = splitProfiles(profiles);
    const [aiContributedProfiles, otherContributedProfiles] = splitContributedProfiles(contributedProfiles);
    const dropdownActions = [];
    const submenuActions = [];
    const splitLocation = (location === TerminalLocation.Editor || (typeof location === "object" && hasKey(location, {
        viewColumn: true
    }) && location.viewColumn === ACTIVE_GROUP)) ? {
        viewColumn: SIDE_GROUP
    } : {
        splitActiveTerminal: true
    };
    if (location === TerminalLocation.Editor) {
        location = {
            viewColumn: ACTIVE_GROUP
        };
    }
    dropdownActions.push(disposableStore.add(( new Action(
        TerminalCommandId.New,
        terminalStrings.new,
        undefined,
        true,
        () => terminalService.createAndFocusTerminal()
    ))));
    dropdownActions.push(disposableStore.add(( new Action(
        TerminalCommandId.NewInNewWindow,
        terminalStrings.newInNewWindow.value,
        undefined,
        true,
        () => terminalService.createAndFocusTerminal({
            location: {
                viewColumn: AUX_WINDOW_GROUP,
                auxiliary: {
                    compact: true
                }
            }
        })
    ))));
    dropdownActions.push(disposableStore.add(( new Action(
        TerminalCommandId.Split,
        terminalStrings.split.value,
        undefined,
        true,
        () => terminalService.createAndFocusTerminal({
            location: splitLocation
        })
    ))));
    dropdownActions.push(( new Separator()));
    for (const p of aiProfiles) {
        addProfileActions(
            p,
            defaultProfileName,
            location,
            splitLocation,
            terminalService,
            dropdownActions,
            submenuActions,
            disposableStore
        );
    }
    for (const contributed of aiContributedProfiles) {
        addContributedProfileActions(
            contributed,
            defaultProfileName,
            location,
            splitLocation,
            terminalService,
            dropdownActions,
            submenuActions,
            disposableStore
        );
    }
    if ((aiProfiles.length > 0 || aiContributedProfiles.length > 0) && (otherProfiles.length > 0 || otherContributedProfiles.length > 0)) {
        dropdownActions.push(( new Separator()));
    }
    for (const p of otherProfiles) {
        addProfileActions(
            p,
            defaultProfileName,
            location,
            splitLocation,
            terminalService,
            dropdownActions,
            submenuActions,
            disposableStore
        );
    }
    for (const contributed of otherContributedProfiles) {
        addContributedProfileActions(
            contributed,
            defaultProfileName,
            location,
            splitLocation,
            terminalService,
            dropdownActions,
            submenuActions,
            disposableStore
        );
    }
    if (dropdownActions.length > 0) {
        dropdownActions.push(( new SubmenuAction("split.profile", ( localize(14244, "Split Terminal with Profile")), submenuActions)));
        dropdownActions.push(( new Separator()));
    }
    const actions = dropdownMenu.getActions();
    dropdownActions.push(...Separator.join(...( actions.map(a => a[1]))));
    const dropdownAction = disposableStore.add(( new Action("refresh profiles", ( localize(14245, "Launch Profile...")), "codicon-chevron-down", true)));
    return {
        dropdownAction,
        dropdownMenuActions: dropdownActions,
        className: `terminal-tab-actions-${terminalService.resolveLocation(location)}`
    };
}
function splitProfiles(profiles) {
    const aiProfiles = [];
    const otherProfiles = [];
    for (const profile of profiles) {
        if (isAiProfileName(profile.profileName)) {
            aiProfiles.push(profile);
        } else {
            otherProfiles.push(profile);
        }
    }
    return [aiProfiles, otherProfiles];
}
function splitContributedProfiles(contributedProfiles) {
    const aiContributedProfiles = [];
    const otherContributedProfiles = [];
    for (const profile of contributedProfiles) {
        if (isAiContributedProfile(profile)) {
            aiContributedProfiles.push(profile);
        } else {
            otherContributedProfiles.push(profile);
        }
    }
    return [aiContributedProfiles, otherContributedProfiles];
}
function isAiContributedProfile(profile) {
    const extensionIdentifier = profile.extensionIdentifier.toLowerCase();
    if (extensionIdentifier === "github.copilot-chat" || extensionIdentifier === "anthropic.claude-code") {
        return true;
    }
    return isAiProfileName(profile.title);
}
function isAiProfileName(name) {
    const lowerCaseName = name.toLowerCase();
    return lowerCaseName.includes("copilot") || lowerCaseName.includes("claude");
}
function addProfileActions(
    profile,
    defaultProfileName,
    location,
    splitLocation,
    terminalService,
    dropdownActions,
    submenuActions,
    disposableStore
) {
    const isDefault = profile.profileName === defaultProfileName;
    const options = {
        config: profile,
        location
    };
    const splitOptions = {
        config: profile,
        location: splitLocation
    };
    const sanitizedProfileName = profile.profileName.replace(/[\n\r\t]/g, "");
    dropdownActions.push(disposableStore.add(( new Action(TerminalCommandId.NewWithProfile, isDefault ? ( localize(14246, "{0} (Default)", sanitizedProfileName)) : sanitizedProfileName, undefined, true, async () => {
        await terminalService.createAndFocusTerminal(options);
    }))));
    submenuActions.push(disposableStore.add(( new Action(TerminalCommandId.Split, isDefault ? ( localize(14246, "{0} (Default)", sanitizedProfileName)) : sanitizedProfileName, undefined, true, async () => {
        await terminalService.createAndFocusTerminal(splitOptions);
    }))));
}
function addContributedProfileActions(
    contributed,
    defaultProfileName,
    location,
    splitLocation,
    terminalService,
    dropdownActions,
    submenuActions,
    disposableStore
) {
    const isDefault = contributed.title === defaultProfileName;
    const title = isDefault ? ( localize(14246, "{0} (Default)", contributed.title.replace(/[\n\r\t]/g, ""))) : contributed.title.replace(/[\n\r\t]/g, "");
    dropdownActions.push(disposableStore.add(( new Action(
        "contributed",
        title,
        undefined,
        true,
        () => terminalService.createAndFocusTerminal({
            config: {
                extensionIdentifier: contributed.extensionIdentifier,
                id: contributed.id,
                title
            },
            location
        })
    ))));
    submenuActions.push(disposableStore.add(( new Action(
        "contributed-split",
        title,
        undefined,
        true,
        () => terminalService.createAndFocusTerminal({
            config: {
                extensionIdentifier: contributed.extensionIdentifier,
                id: contributed.id,
                title
            },
            location: splitLocation
        })
    ))));
}

export { TerminalContextMenuGroup, TerminalMenuBarGroup, getTerminalActionBarArgs, setupTerminalMenus };
