
import { registerCss } from '../../../../../../../css.js';
import * as panelpart from './media/panelpart.css';
import { localize, localize2 } 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, positionToString, Position, isHorizontal } from '../../../services/layout/browser/layoutService.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.service.js';
import { PanelVisibleContext, PanelPositionContext, PanelAlignmentContext, PanelMaximizedContext, IsAuxiliaryWindowContext } 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 } 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';
import { SwitchCompositeViewAction } from '../compositeBarActions.js';

registerCss(panelpart);
const maximizeIcon = registerIcon("panel-maximize", Codicon.screenFull, ( localize(3801, "Icon to maximize a panel.")));
const closeIcon = registerIcon("panel-close", Codicon.close, ( localize(3802, "Icon to close a panel.")));
const panelIcon = registerIcon("panel-layout-icon", Codicon.layoutPanel, ( localize(3803, "Icon to toggle the panel off when it is on.")));
const panelOffIcon = registerIcon("panel-layout-icon-off", Codicon.layoutPanelOff, ( localize(3804, "Icon to toggle the panel on when it is off.")));
class TogglePanelAction extends Action2 {
    static {
        this.ID = "workbench.action.togglePanel";
    }
    static {
        this.LABEL = ( localize2(3805, "Toggle Panel Visibility"));
    }
    constructor() {
        super({
            id: TogglePanelAction.ID,
            title: TogglePanelAction.LABEL,
            toggled: {
                condition: PanelVisibleContext,
                title: ( localize(3806, "Hide Panel")),
                icon: closeIcon,
                mnemonicTitle: ( localize(3807, "&&Panel"))
            },
            icon: closeIcon,
            f1: true,
            category: Categories.View,
            metadata: {
                description: ( localize(3808, "Open/Show and Close/Hide Panel"))
            },
            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);
MenuRegistry.appendMenuItem(MenuId.PanelTitle, {
    command: {
        id: TogglePanelAction.ID,
        title: ( localize(3806, "Hide Panel")),
        icon: closeIcon
    },
    group: "navigation",
    order: 2
});
registerAction2(class extends Action2 {
    constructor() {
        super({
            id: "workbench.action.closePanel",
            title: ( localize2(3806, "Hide Panel")),
            category: Categories.View,
            precondition: PanelVisibleContext,
            f1: true
        });
    }
    run(accessor) {
        accessor.get(IWorkbenchLayoutService).setPartHidden(true, Parts.PANEL_PART);
    }
});
registerAction2(class extends Action2 {
    static {
        this.ID = "workbench.action.focusPanel";
    }
    static {
        this.LABEL = ( localize(3809, "Focus into Panel"));
    }
    constructor() {
        super({
            id: "workbench.action.focusPanel",
            title: ( localize2(3809, "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",
    TOP: "workbench.action.positionPanelTop"
};
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.TOP, ( localize2(3810, "Move Panel To Top")), ( localize(3811, "Top")), Position.TOP), createPositionPanelActionConfig(PositionPanelActionId.LEFT, ( localize2(3812, "Move Panel Left")), ( localize(3813, "Left")), Position.LEFT), createPositionPanelActionConfig(PositionPanelActionId.RIGHT, ( localize2(3814, "Move Panel Right")), ( localize(3815, "Right")), Position.RIGHT), createPositionPanelActionConfig(PositionPanelActionId.BOTTOM, ( localize2(3816, "Move Panel To Bottom")), ( localize(3817, "Bottom")), Position.BOTTOM)];
const AlignPanelActionConfigs = [createAlignmentPanelActionConfig(AlignPanelActionId.LEFT, ( localize2(3818, "Set Panel Alignment to Left")), ( localize(3819, "Left")), "left"), createAlignmentPanelActionConfig(AlignPanelActionId.RIGHT, ( localize2(3820, "Set Panel Alignment to Right")), ( localize(3821, "Right")), "right"), createAlignmentPanelActionConfig(AlignPanelActionId.CENTER, ( localize2(3822, "Set Panel Alignment to Center")), ( localize(3823, "Center")), "center"), createAlignmentPanelActionConfig(AlignPanelActionId.JUSTIFY, ( localize2(3824, "Set Panel Alignment to Justify")), ( localize(3825, "Justify")), "justify")];
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
    submenu: MenuId.PanelPositionMenu,
    title: ( localize(3826, "Panel Position")),
    group: "3_workbench_layout_move",
    order: 4
});
PositionPanelActionConfigs.forEach((positionPanelAction, index) => {
    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 + index
    });
});
MenuRegistry.appendMenuItem(MenuId.MenubarAppearanceMenu, {
    submenu: MenuId.PanelAlignmentMenu,
    title: ( localize(3827, "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
    });
});
registerAction2(class extends SwitchCompositeViewAction {
    constructor() {
        super({
            id: "workbench.action.previousPanelView",
            title: ( localize2(3828, "Previous Panel View")),
            category: Categories.View,
            f1: true
        }, ViewContainerLocation.Panel, -1);
    }
});
registerAction2(class extends SwitchCompositeViewAction {
    constructor() {
        super({
            id: "workbench.action.nextPanelView",
            title: ( localize2(3829, "Next Panel View")),
            category: Categories.View,
            f1: true
        }, ViewContainerLocation.Panel, 1);
    }
});
const panelMaximizationSupportedWhen = ( ContextKeyExpr.or(( PanelAlignmentContext.isEqualTo("center")), ( ContextKeyExpr.and(( PanelPositionContext.notEqualsTo("bottom")), ( PanelPositionContext.notEqualsTo("top"))))));
registerAction2(class extends Action2 {
    constructor() {
        super({
            id: "workbench.action.toggleMaximizedPanel",
            title: ( localize2(3830, "Toggle Maximized Panel")),
            tooltip: ( localize(3831, "Maximize Panel")),
            category: Categories.View,
            f1: true,
            icon: maximizeIcon,
            precondition: panelMaximizationSupportedWhen,
            toggled: {
                condition: PanelMaximizedContext,
                tooltip: ( localize(3832, "Restore Panel"))
            },
            menu: [{
                id: MenuId.PanelTitle,
                group: "navigation",
                order: 1,
                when: panelMaximizationSupportedWhen
            }]
        });
    }
    run(accessor) {
        const layoutService = accessor.get(IWorkbenchLayoutService);
        const notificationService = accessor.get(INotificationService);
        if (layoutService.getPanelAlignment() !== "center" && isHorizontal(layoutService.getPanelPosition())) {
            notificationService.warn(( localize(3833, "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();
        }
    }
});
MenuRegistry.appendMenuItems([{
    id: MenuId.LayoutControlMenu,
    item: {
        group: "navigation",
        command: {
            id: TogglePanelAction.ID,
            title: ( localize(3834, "Toggle Panel")),
            icon: panelOffIcon,
            toggled: {
                condition: PanelVisibleContext,
                icon: panelIcon
            }
        },
        when: ( ContextKeyExpr.and(( IsAuxiliaryWindowContext.negate()), ( ContextKeyExpr.or(( ContextKeyExpr.equals("config.workbench.layoutControl.type", "toggles")), ( ContextKeyExpr.equals("config.workbench.layoutControl.type", "both")))))),
        order: 1
    }
}]);
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: ( localize2(3835, "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: ( localize2(3835, "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: ( localize2(3836, "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: ( localize2(3836, "Move Secondary Side Bar Views To Panel")),
            category: Categories.View,
            f1: true
        });
    }
}
registerAction2(MoveSidePanelToPanelAction);
registerAction2(MoveSecondarySideBarToPanelAction);

export { MovePanelToSecondarySideBarAction, MoveSecondarySideBarToPanelAction, TogglePanelAction };
