import './media/panelpart.css.js';
import { localize2WithPath, localizeWithPath } from '../../../../nls.js';
import { KeyMod as KeyMod$1, KeyCode } from '../../../../base/common/keyCodes.js';
import { Action2, MenuId, registerAction2, MenuRegistry } from '../../../../platform/actions/common/actions.js';
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
import { Parts, Position, LayoutSettings, ActivityBarPosition, positionToString } from '../../../services/layout/browser/layoutService.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.service.js';
import { PanelVisibleContext, PanelAlignmentContext, PanelPositionContext, PanelMaximizedContext, AuxiliaryBarVisibleContext } from '../../../common/contextkeys.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
import { ViewContainerLocation, ViewContainerLocationToString } from '../../../common/views.js';
import { IViewDescriptorService } from '../../../common/views.service.js';
import { IViewsService } from '../../../services/views/common/viewsService.service.js';
import { IPaneCompositePartService } from '../../../services/panecomposite/browser/panecomposite.service.js';
import { INotificationService } from '../../../../platform/notification/common/notification.service.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
const _moduleId = "vs/workbench/browser/parts/panel/panelActions";
const maximizeIcon = registerIcon('panel-maximize', Codicon.chevronUp, ( localizeWithPath(_moduleId, 0, 'Icon to maximize a panel.')));
const restoreIcon = registerIcon('panel-restore', Codicon.chevronDown, ( localizeWithPath(_moduleId, 1, 'Icon to restore a panel.')));
const closeIcon = registerIcon('panel-close', Codicon.close, ( localizeWithPath(_moduleId, 2, 'Icon to close a panel.')));
const panelIcon = registerIcon('panel-layout-icon', Codicon.layoutPanel, ( localizeWithPath(_moduleId, 3, 'Icon to toggle the panel off when it is on.')));
const panelOffIcon = registerIcon('panel-layout-icon-off', Codicon.layoutPanelOff, ( localizeWithPath(_moduleId, 4, 'Icon to toggle the panel on when it is off.')));
class TogglePanelAction extends Action2 {
    static { this.ID = 'workbench.action.togglePanel'; }
    static { this.LABEL = ( localize2WithPath(_moduleId, 5, "Toggle Panel Visibility")); }
    constructor() {
        super({
            id: TogglePanelAction.ID,
            title: TogglePanelAction.LABEL,
            toggled: {
                condition: PanelVisibleContext,
                title: ( localizeWithPath(_moduleId, 6, "Panel")),
                mnemonicTitle: ( localizeWithPath(_moduleId, 7, "&&Panel")),
            },
            f1: true,
            category: Categories.View,
            keybinding: { primary: KeyMod$1.CtrlCmd | KeyCode.KeyJ, weight: KeybindingWeight.WorkbenchContrib },
            menu: [
                {
                    id: MenuId.MenubarAppearanceMenu,
                    group: '2_workbench_layout',
                    order: 5
                }, {
                    id: MenuId.LayoutControlMenuSubmenu,
                    group: '0_workbench_layout',
                    order: 4
                },
            ]
        });
    }
    async run(accessor) {
        const layoutService = accessor.get(IWorkbenchLayoutService);
        layoutService.setPartHidden(layoutService.isVisible(Parts.PANEL_PART), Parts.PANEL_PART);
    }
}
registerAction2(TogglePanelAction);
registerAction2(class extends Action2 {
    static { this.ID = 'workbench.action.focusPanel'; }
    static { this.LABEL = ( localizeWithPath(_moduleId, 8, "Focus into Panel")); }
    constructor() {
        super({
            id: 'workbench.action.focusPanel',
            title: ( localize2WithPath(_moduleId, 8, "Focus into Panel")),
            category: Categories.View,
            f1: true,
        });
    }
    async run(accessor) {
        const layoutService = accessor.get(IWorkbenchLayoutService);
        const paneCompositeService = accessor.get(IPaneCompositePartService);
        if (!layoutService.isVisible(Parts.PANEL_PART)) {
            layoutService.setPartHidden(false, Parts.PANEL_PART);
        }
        const panel = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
        panel?.focus();
    }
});
const PositionPanelActionId = {
    LEFT: 'workbench.action.positionPanelLeft',
    RIGHT: 'workbench.action.positionPanelRight',
    BOTTOM: 'workbench.action.positionPanelBottom',
};
const AlignPanelActionId = {
    LEFT: 'workbench.action.alignPanelLeft',
    RIGHT: 'workbench.action.alignPanelRight',
    CENTER: 'workbench.action.alignPanelCenter',
    JUSTIFY: 'workbench.action.alignPanelJustify',
};
function createPanelActionConfig(id, title, shortLabel, value, when) {
    return {
        id,
        title,
        shortLabel,
        value,
        when,
    };
}
function createPositionPanelActionConfig(id, title, shortLabel, position) {
    return createPanelActionConfig(id, title, shortLabel, position, ( (PanelPositionContext.notEqualsTo(positionToString(position)))));
}
function createAlignmentPanelActionConfig(id, title, shortLabel, alignment) {
    return createPanelActionConfig(id, title, shortLabel, alignment, ( (PanelAlignmentContext.notEqualsTo(alignment))));
}
const PositionPanelActionConfigs = [
    createPositionPanelActionConfig(PositionPanelActionId.LEFT, ( localize2WithPath(_moduleId, 9, "Move Panel Left")), ( localizeWithPath(_moduleId, 10, "Left")), Position.LEFT),
    createPositionPanelActionConfig(PositionPanelActionId.RIGHT, ( localize2WithPath(_moduleId, 11, "Move Panel Right")), ( localizeWithPath(_moduleId, 12, "Right")), Position.RIGHT),
    createPositionPanelActionConfig(PositionPanelActionId.BOTTOM, ( localize2WithPath(_moduleId, 13, "Move Panel To Bottom")), ( localizeWithPath(_moduleId, 14, "Bottom")), Position.BOTTOM),
];
const AlignPanelActionConfigs = [
    createAlignmentPanelActionConfig(AlignPanelActionId.LEFT, ( localize2WithPath(_moduleId, 15, "Set Panel Alignment to Left")), ( localizeWithPath(_moduleId, 16, "Left")), 'left'),
    createAlignmentPanelActionConfig(AlignPanelActionId.RIGHT, ( localize2WithPath(_moduleId, 17, "Set Panel Alignment to Right")), ( localizeWithPath(_moduleId, 18, "Right")), 'right'),
    createAlignmentPanelActionConfig(AlignPanelActionId.CENTER, ( localize2WithPath(_moduleId, 19, "Set Panel Alignment to Center")), ( localizeWithPath(_moduleId, 20, "Center")), 'center'),
    createAlignmentPanelActionConfig(AlignPanelActionId.JUSTIFY, ( localize2WithPath(_moduleId, 21, "Set Panel Alignment to Justify")), ( localizeWithPath(_moduleId, 22, "Justify")), 'justify'),
];
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
    submenu: MenuId.PanelPositionMenu,
    title: ( localizeWithPath(_moduleId, 23, "Panel Position")),
    group: '3_workbench_layout_move',
    order: 4
});
PositionPanelActionConfigs.forEach(positionPanelAction => {
    const { id, title, shortLabel, value, when } = positionPanelAction;
    registerAction2(class extends Action2 {
        constructor() {
            super({
                id,
                title,
                category: Categories.View,
                f1: true
            });
        }
        run(accessor) {
            const layoutService = accessor.get(IWorkbenchLayoutService);
            layoutService.setPanelPosition(value === undefined ? Position.BOTTOM : value);
        }
    });
    MenuRegistry.appendMenuItem(MenuId.PanelPositionMenu, {
        command: {
            id,
            title: shortLabel,
            toggled: ( (when.negate()))
        },
        order: 5
    });
});
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
    submenu: MenuId.PanelAlignmentMenu,
    title: ( localizeWithPath(_moduleId, 24, "Align Panel")),
    group: '3_workbench_layout_move',
    order: 5
});
AlignPanelActionConfigs.forEach(alignPanelAction => {
    const { id, title, shortLabel, value, when } = alignPanelAction;
    registerAction2(class extends Action2 {
        constructor() {
            super({
                id,
                title,
                category: Categories.View,
                toggled: ( (when.negate())),
                f1: true
            });
        }
        run(accessor) {
            const layoutService = accessor.get(IWorkbenchLayoutService);
            layoutService.setPanelAlignment(value === undefined ? 'center' : value);
        }
    });
    MenuRegistry.appendMenuItem(MenuId.PanelAlignmentMenu, {
        command: {
            id,
            title: shortLabel,
            toggled: ( (when.negate()))
        },
        order: 5
    });
});
class SwitchPanelViewAction extends Action2 {
    constructor(id, title) {
        super({
            id,
            title,
            category: Categories.View,
            f1: true,
        });
    }
    async run(accessor, offset) {
        const paneCompositeService = accessor.get(IPaneCompositePartService);
        const pinnedPanels = paneCompositeService.getVisiblePaneCompositeIds(ViewContainerLocation.Panel);
        const activePanel = paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);
        if (!activePanel) {
            return;
        }
        let targetPanelId;
        for (let i = 0; i < pinnedPanels.length; i++) {
            if (pinnedPanels[i] === activePanel.getId()) {
                targetPanelId = pinnedPanels[(i + pinnedPanels.length + offset) % pinnedPanels.length];
                break;
            }
        }
        if (typeof targetPanelId === 'string') {
            await paneCompositeService.openPaneComposite(targetPanelId, ViewContainerLocation.Panel, true);
        }
    }
}
registerAction2(class extends SwitchPanelViewAction {
    constructor() {
        super('workbench.action.previousPanelView', ( localize2WithPath(_moduleId, 25, "Previous Panel View")));
    }
    run(accessor) {
        return super.run(accessor, -1);
    }
});
registerAction2(class extends SwitchPanelViewAction {
    constructor() {
        super('workbench.action.nextPanelView', ( localize2WithPath(_moduleId, 26, "Next Panel View")));
    }
    run(accessor) {
        return super.run(accessor, 1);
    }
});
registerAction2(class extends Action2 {
    constructor() {
        super({
            id: 'workbench.action.toggleMaximizedPanel',
            title: ( localize2WithPath(_moduleId, 27, 'Toggle Maximized Panel')),
            tooltip: ( localizeWithPath(_moduleId, 28, "Maximize Panel Size")),
            category: Categories.View,
            f1: true,
            icon: maximizeIcon,
            precondition: ( (ContextKeyExpr.or(
                 (PanelAlignmentContext.isEqualTo('center')),
                 (PanelPositionContext.notEqualsTo('bottom'))
            ))),
            toggled: { condition: PanelMaximizedContext, icon: restoreIcon, tooltip: ( localizeWithPath(_moduleId, 29, "Restore Panel Size")) },
            menu: [{
                    id: MenuId.PanelTitle,
                    group: 'navigation',
                    order: 1,
                    when: ( (ContextKeyExpr.or(
                         (PanelAlignmentContext.isEqualTo('center')),
                         (PanelPositionContext.notEqualsTo('bottom'))
                    )))
                }]
        });
    }
    run(accessor) {
        const layoutService = accessor.get(IWorkbenchLayoutService);
        const notificationService = accessor.get(INotificationService);
        if (layoutService.getPanelAlignment() !== 'center' && layoutService.getPanelPosition() === Position.BOTTOM) {
            notificationService.warn(( localizeWithPath(
                _moduleId,
                30,
                "Maximizing the panel is only supported when it is center aligned."
            )));
            return;
        }
        if (!layoutService.isVisible(Parts.PANEL_PART)) {
            layoutService.setPartHidden(false, Parts.PANEL_PART);
            if (!layoutService.isPanelMaximized()) {
                layoutService.toggleMaximizedPanel();
            }
        }
        else {
            layoutService.toggleMaximizedPanel();
        }
    }
});
registerAction2(class extends Action2 {
    constructor() {
        super({
            id: 'workbench.action.closePanel',
            title: ( localize2WithPath(_moduleId, 31, 'Hide Panel')),
            category: Categories.View,
            icon: closeIcon,
            menu: [{
                    id: MenuId.CommandPalette,
                    when: PanelVisibleContext,
                }, {
                    id: MenuId.PanelTitle,
                    group: 'navigation',
                    order: 2
                }]
        });
    }
    run(accessor) {
        accessor.get(IWorkbenchLayoutService).setPartHidden(true, Parts.PANEL_PART);
    }
});
registerAction2(class extends Action2 {
    constructor() {
        super({
            id: 'workbench.action.closeAuxiliaryBar',
            title: ( localize2WithPath(_moduleId, 32, 'Hide Secondary Side Bar')),
            category: Categories.View,
            icon: closeIcon,
            menu: [{
                    id: MenuId.CommandPalette,
                    when: AuxiliaryBarVisibleContext,
                }, {
                    id: MenuId.AuxiliaryBarTitle,
                    group: 'navigation',
                    order: 2,
                    when: ( (ContextKeyExpr.notEquals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP)))
                }, {
                    id: MenuId.AuxiliaryBarHeader,
                    group: 'navigation',
                    when: ( (ContextKeyExpr.equals(`config.${LayoutSettings.ACTIVITY_BAR_LOCATION}`, ActivityBarPosition.TOP)))
                }]
        });
    }
    run(accessor) {
        accessor.get(IWorkbenchLayoutService).setPartHidden(true, Parts.AUXILIARYBAR_PART);
    }
});
MenuRegistry.appendMenuItems([
    {
        id: MenuId.LayoutControlMenu,
        item: {
            group: '0_workbench_toggles',
            command: {
                id: TogglePanelAction.ID,
                title: ( localizeWithPath(_moduleId, 33, "Toggle Panel")),
                icon: panelOffIcon,
                toggled: { condition: PanelVisibleContext, icon: panelIcon }
            },
            when: ( (ContextKeyExpr.or(
                 (ContextKeyExpr.equals('config.workbench.layoutControl.type', 'toggles')),
                 (ContextKeyExpr.equals('config.workbench.layoutControl.type', 'both'))
            ))),
            order: 1
        }
    }, {
        id: MenuId.ViewTitleContext,
        item: {
            group: '3_workbench_layout_move',
            command: {
                id: TogglePanelAction.ID,
                title: ( localize2WithPath(_moduleId, 34, 'Hide Panel')),
            },
            when: ( (ContextKeyExpr.and(
                PanelVisibleContext,
                 (ContextKeyExpr.equals('viewLocation', ViewContainerLocationToString(ViewContainerLocation.Panel)))
            ))),
            order: 2
        }
    }
]);
class MoveViewsBetweenPanelsAction extends Action2 {
    constructor(source, destination, desc) {
        super(desc);
        this.source = source;
        this.destination = destination;
    }
    run(accessor, ...args) {
        const viewDescriptorService = accessor.get(IViewDescriptorService);
        const layoutService = accessor.get(IWorkbenchLayoutService);
        const viewsService = accessor.get(IViewsService);
        const srcContainers = viewDescriptorService.getViewContainersByLocation(this.source);
        const destContainers = viewDescriptorService.getViewContainersByLocation(this.destination);
        if (srcContainers.length) {
            const activeViewContainer = viewsService.getVisibleViewContainer(this.source);
            srcContainers.forEach(viewContainer => viewDescriptorService.moveViewContainerToLocation(viewContainer, this.destination, undefined, this.desc.id));
            layoutService.setPartHidden(false, this.destination === ViewContainerLocation.Panel ? Parts.PANEL_PART : Parts.AUXILIARYBAR_PART);
            if (activeViewContainer && destContainers.length === 0) {
                viewsService.openViewContainer(activeViewContainer.id, true);
            }
        }
    }
}
class MovePanelToSidePanelAction extends MoveViewsBetweenPanelsAction {
    static { this.ID = 'workbench.action.movePanelToSidePanel'; }
    constructor() {
        super(ViewContainerLocation.Panel, ViewContainerLocation.AuxiliaryBar, {
            id: MovePanelToSidePanelAction.ID,
            title: ( localize2WithPath(_moduleId, 35, "Move Panel Views To Secondary Side Bar")),
            category: Categories.View,
            f1: false
        });
    }
}
class MovePanelToSecondarySideBarAction extends MoveViewsBetweenPanelsAction {
    static { this.ID = 'workbench.action.movePanelToSecondarySideBar'; }
    constructor() {
        super(ViewContainerLocation.Panel, ViewContainerLocation.AuxiliaryBar, {
            id: MovePanelToSecondarySideBarAction.ID,
            title: ( localize2WithPath(_moduleId, 35, "Move Panel Views To Secondary Side Bar")),
            category: Categories.View,
            f1: true
        });
    }
}
registerAction2(MovePanelToSidePanelAction);
registerAction2(MovePanelToSecondarySideBarAction);
class MoveSidePanelToPanelAction extends MoveViewsBetweenPanelsAction {
    static { this.ID = 'workbench.action.moveSidePanelToPanel'; }
    constructor() {
        super(ViewContainerLocation.AuxiliaryBar, ViewContainerLocation.Panel, {
            id: MoveSidePanelToPanelAction.ID,
            title: ( localize2WithPath(_moduleId, 36, "Move Secondary Side Bar Views To Panel")),
            category: Categories.View,
            f1: false
        });
    }
}
class MoveSecondarySideBarToPanelAction extends MoveViewsBetweenPanelsAction {
    static { this.ID = 'workbench.action.moveSecondarySideBarToPanel'; }
    constructor() {
        super(ViewContainerLocation.AuxiliaryBar, ViewContainerLocation.Panel, {
            id: MoveSecondarySideBarToPanelAction.ID,
            title: ( localize2WithPath(_moduleId, 36, "Move Secondary Side Bar Views To Panel")),
            category: Categories.View,
            f1: true
        });
    }
}
registerAction2(MoveSidePanelToPanelAction);
registerAction2(MoveSecondarySideBarToPanelAction);
export { MovePanelToSecondarySideBarAction, MoveSecondarySideBarToPanelAction, TogglePanelAction };
