import { Codicon } from '../../../../base/common/codicons.js';
import { localize2WithPath, localizeWithPath } from '../../../../nls.js';
import { Action2, MenuId, registerAction2, MenuRegistry } from '../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
import { AuxiliaryBarVisibleContext } from '../../../common/contextkeys.js';
import { ViewContainerLocationToString } from '../../../common/views.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
import { IPaneCompositePartService } from '../../../services/panecomposite/browser/panecomposite.js';
const auxiliaryBarRightIcon = registerIcon('auxiliarybar-right-layout-icon', Codicon.layoutSidebarRight, ( localizeWithPath(
    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
    'toggleAuxiliaryIconRight',
    'Icon to toggle the auxiliary bar off in its right position.'
)));
const auxiliaryBarRightOffIcon = registerIcon('auxiliarybar-right-off-layout-icon', Codicon.layoutSidebarRightOff, ( localizeWithPath(
    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
    'toggleAuxiliaryIconRightOn',
    'Icon to toggle the auxiliary bar on in its right position.'
)));
const auxiliaryBarLeftIcon = registerIcon('auxiliarybar-left-layout-icon', Codicon.layoutSidebarLeft, ( localizeWithPath(
    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
    'toggleAuxiliaryIconLeft',
    'Icon to toggle the auxiliary bar in its left position.'
)));
const auxiliaryBarLeftOffIcon = registerIcon('auxiliarybar-left-off-layout-icon', Codicon.layoutSidebarLeftOff, ( localizeWithPath(
    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
    'toggleAuxiliaryIconLeftOn',
    'Icon to toggle the auxiliary bar on in its left position.'
)));
class ToggleAuxiliaryBarAction extends Action2 {
    static { this.ID = 'workbench.action.toggleAuxiliaryBar'; }
    static { this.LABEL = ( localize2WithPath(
        'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
        'toggleAuxiliaryBar',
        "Toggle Secondary Side Bar Visibility"
    )); }
    constructor() {
        super({
            id: ToggleAuxiliaryBarAction.ID,
            title: ToggleAuxiliaryBarAction.LABEL,
            toggled: {
                condition: AuxiliaryBarVisibleContext,
                title: ( localizeWithPath(
                    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
                    'secondary sidebar',
                    "Secondary Side Bar"
                )),
                mnemonicTitle: ( localizeWithPath(
                    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
                    { key: 'secondary sidebar mnemonic', comment: ['&& denotes a mnemonic'] },
                    "Secondary Si&&de Bar"
                )),
            },
            category: Categories.View,
            f1: true,
            keybinding: {
                weight: 200 ,
                primary: 2048  | 512  | 32
            },
            menu: [
                {
                    id: MenuId.LayoutControlMenuSubmenu,
                    group: '0_workbench_layout',
                    order: 1
                },
                {
                    id: MenuId.MenubarAppearanceMenu,
                    group: '2_workbench_layout',
                    order: 2
                }
            ]
        });
    }
    async run(accessor) {
        const layoutService = accessor.get(IWorkbenchLayoutService);
        layoutService.setPartHidden(layoutService.isVisible("workbench.parts.auxiliarybar" ), "workbench.parts.auxiliarybar" );
    }
}
registerAction2(ToggleAuxiliaryBarAction);
registerAction2(class FocusAuxiliaryBarAction extends Action2 {
    static { this.ID = 'workbench.action.focusAuxiliaryBar'; }
    static { this.LABEL = ( localize2WithPath(
        'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
        'focusAuxiliaryBar',
        "Focus into Secondary Side Bar"
    )); }
    constructor() {
        super({
            id: FocusAuxiliaryBarAction.ID,
            title: FocusAuxiliaryBarAction.LABEL,
            category: Categories.View,
            f1: true,
        });
    }
    async run(accessor) {
        const paneCompositeService = accessor.get(IPaneCompositePartService);
        const layoutService = accessor.get(IWorkbenchLayoutService);
        if (!layoutService.isVisible("workbench.parts.auxiliarybar" )) {
            layoutService.setPartHidden(false, "workbench.parts.auxiliarybar" );
        }
        const composite = paneCompositeService.getActivePaneComposite(2 );
        composite?.focus();
    }
});
MenuRegistry.appendMenuItems([
    {
        id: MenuId.LayoutControlMenu,
        item: {
            group: '0_workbench_toggles',
            command: {
                id: ToggleAuxiliaryBarAction.ID,
                title: ( localizeWithPath(
                    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
                    'toggleSecondarySideBar',
                    "Toggle Secondary Side Bar"
                )),
                toggled: { condition: AuxiliaryBarVisibleContext, icon: auxiliaryBarLeftIcon },
                icon: auxiliaryBarLeftOffIcon,
            },
            when: ( ContextKeyExpr.and(( ContextKeyExpr.or(( ContextKeyExpr.equals('config.workbench.layoutControl.type', 'toggles')), ( ContextKeyExpr.equals('config.workbench.layoutControl.type', 'both')))), ( ContextKeyExpr.equals('config.workbench.sideBar.location', 'right')))),
            order: 0
        }
    }, {
        id: MenuId.LayoutControlMenu,
        item: {
            group: '0_workbench_toggles',
            command: {
                id: ToggleAuxiliaryBarAction.ID,
                title: ( localizeWithPath(
                    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
                    'toggleSecondarySideBar',
                    "Toggle Secondary Side Bar"
                )),
                toggled: { condition: AuxiliaryBarVisibleContext, icon: auxiliaryBarRightIcon },
                icon: auxiliaryBarRightOffIcon,
            },
            when: ( ContextKeyExpr.and(( ContextKeyExpr.or(( ContextKeyExpr.equals('config.workbench.layoutControl.type', 'toggles')), ( ContextKeyExpr.equals('config.workbench.layoutControl.type', 'both')))), ( ContextKeyExpr.equals('config.workbench.sideBar.location', 'left')))),
            order: 2
        }
    }, {
        id: MenuId.ViewTitleContext,
        item: {
            group: '3_workbench_layout_move',
            command: {
                id: ToggleAuxiliaryBarAction.ID,
                title: ( localize2WithPath(
                    'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarActions',
                    'hideAuxiliaryBar',
                    'Hide Secondary Side Bar'
                )),
            },
            when: ( ContextKeyExpr.and(AuxiliaryBarVisibleContext, ( ContextKeyExpr.equals(
                'viewLocation',
                ViewContainerLocationToString(2 )
            )))),
            order: 2
        }
    }
]);
export { ToggleAuxiliaryBarAction };
