
import { registerCss } from '../../../../../../../css.js';
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import * as panelpart from './media/panelpart.css';
import { localize } from '../../../../nls.js';
import { Separator, toAction, SubmenuAction } from '../../../../base/common/actions.js';
import { ActionsOrientation } from '../../../../base/browser/ui/actionbar/actionbar.js';
import { ActivePanelContext, PanelFocusContext } from '../../../common/contextkeys.js';
import { Parts, Position } from '../../../services/layout/browser/layoutService.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.service.js';
import { IStorageService } from '../../../../platform/storage/common/storage.service.js';
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.service.js';
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.service.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { TogglePanelAction } from './panelActions.js';
import { IThemeService } from '../../../../platform/theme/common/themeService.service.js';
import { PANEL_TITLE_BORDER, PANEL_BACKGROUND, PANEL_BORDER, PANEL_DRAG_AND_DROP_BORDER, PANEL_TITLE_BADGE_FOREGROUND, PANEL_TITLE_BADGE_BACKGROUND, PANEL_INACTIVE_TITLE_FOREGROUND, PANEL_ACTIVE_TITLE_FOREGROUND, PANEL_ACTIVE_TITLE_BORDER } from '../../../common/theme.js';
import '../../../../platform/theme/common/colorUtils.js';
import { contrastBorder } from '../../../../platform/theme/common/colors/baseColors.js';
import '../../../../platform/theme/common/colors/chartsColors.js';
import '../../../../platform/theme/common/colors/editorColors.js';
import '../../../../platform/theme/common/colors/inputColors.js';
import '../../../../platform/theme/common/colors/listColors.js';
import '../../../../platform/theme/common/colors/menuColors.js';
import '../../../../platform/theme/common/colors/minimapColors.js';
import '../../../../platform/theme/common/colors/miscColors.js';
import '../../../../platform/theme/common/colors/quickpickColors.js';
import '../../../../platform/theme/common/colors/searchColors.js';
import { INotificationService } from '../../../../platform/notification/common/notification.service.js';
import { Dimension } from '../../../../base/browser/dom.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.service.js';
import { assertReturnsDefined } from '../../../../base/common/types.js';
import { IExtensionService } from '../../../services/extensions/common/extensions.service.js';
import { ViewContainerLocation } from '../../../common/views.js';
import { IViewDescriptorService } from '../../../common/views.service.js';
import { HoverPosition } from '../../../../base/browser/ui/hover/hoverWidget.js';
import { MenuId } from '../../../../platform/actions/common/actions.js';
import { IMenuService } from '../../../../platform/actions/common/actions.service.js';
import { AbstractPaneCompositePart, CompositeBarPosition } from '../paneCompositePart.js';
import { ICommandService } from '../../../../platform/commands/common/commands.service.js';
import { getContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js';
import { IHoverService } from '../../../../platform/hover/browser/hover.service.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.service.js';
import { Extensions } from '../../panecomposite.js';

var PanelPart_1;
registerCss(panelpart);
let PanelPart = class PanelPart extends AbstractPaneCompositePart {
    static {
        PanelPart_1 = this;
    }
    get preferredHeight() {
        return this.layoutService.mainContainerDimension.height * 0.4;
    }
    get preferredWidth() {
        const activeComposite = this.getActivePaneComposite();
        if (!activeComposite) {
            return undefined;
        }
        const width = activeComposite.getOptimalWidth();
        if (typeof width !== "number") {
            return undefined;
        }
        return Math.max(width, 300);
    }
    static {
        this.activePanelSettingsKey = "workbench.panelpart.activepanelid";
    }
    constructor(
        notificationService,
        storageService,
        contextMenuService,
        layoutService,
        keybindingService,
        hoverService,
        instantiationService,
        themeService,
        viewDescriptorService,
        contextKeyService,
        extensionService,
        commandService,
        menuService,
        configurationService
    ) {
        super(Parts.PANEL_PART, {
            hasTitle: true,
            trailingSeparator: true
        }, PanelPart_1.activePanelSettingsKey, ActivePanelContext.bindTo(contextKeyService), PanelFocusContext.bindTo(contextKeyService), "panel", "panel", undefined, PANEL_TITLE_BORDER, ViewContainerLocation.Panel, Extensions.Panels, MenuId.PanelTitle, notificationService, storageService, contextMenuService, layoutService, keybindingService, hoverService, instantiationService, themeService, viewDescriptorService, contextKeyService, extensionService, menuService);
        this.commandService = commandService;
        this.configurationService = configurationService;
        this.minimumWidth = 300;
        this.maximumWidth = Number.POSITIVE_INFINITY;
        this.minimumHeight = 77;
        this.maximumHeight = Number.POSITIVE_INFINITY;
        this._register(this.configurationService.onDidChangeConfiguration(e => {
            if (e.affectsConfiguration("workbench.panel.showLabels")) {
                this.updateCompositeBar(true);
            }
        }));
    }
    updateStyles() {
        super.updateStyles();
        const container = assertReturnsDefined(this.getContainer());
        container.style.backgroundColor = this.getColor(PANEL_BACKGROUND) || "";
        const borderColor = this.getColor(PANEL_BORDER) || this.getColor(contrastBorder) || "";
        container.style.borderLeftColor = borderColor;
        container.style.borderRightColor = borderColor;
        container.style.borderBottomColor = borderColor;
        if (this.titleArea) {
            this.titleArea.style.borderTopColor = this.getColor(PANEL_BORDER) || this.getColor(contrastBorder) || "";
        }
    }
    getCompositeBarOptions() {
        return {
            partContainerClass: "panel",
            pinnedViewContainersKey: "workbench.panel.pinnedPanels",
            placeholderViewContainersKey: "workbench.panel.placeholderPanels",
            viewContainersWorkspaceStateKey: "workbench.panel.viewContainersWorkspaceState",
            icon: this.configurationService.getValue("workbench.panel.showLabels") === false,
            orientation: ActionsOrientation.HORIZONTAL,
            recomputeSizes: true,
            activityHoverOptions: {
                position: () => this.layoutService.getPanelPosition() === Position.BOTTOM && !this.layoutService.isPanelMaximized() ? HoverPosition.ABOVE : HoverPosition.BELOW
            },
            fillExtraContextMenuActions: actions => this.fillExtraContextMenuActions(actions),
            compositeSize: 0,
            iconSize: 16,
            compact: true,
            overflowActionSize: 44,
            colors: theme => ({
                activeBackgroundColor: theme.getColor(PANEL_BACKGROUND),
                inactiveBackgroundColor: theme.getColor(PANEL_BACKGROUND),
                activeBorderBottomColor: theme.getColor(PANEL_ACTIVE_TITLE_BORDER),
                activeForegroundColor: theme.getColor(PANEL_ACTIVE_TITLE_FOREGROUND),
                inactiveForegroundColor: theme.getColor(PANEL_INACTIVE_TITLE_FOREGROUND),
                badgeBackground: theme.getColor(PANEL_TITLE_BADGE_BACKGROUND),
                badgeForeground: theme.getColor(PANEL_TITLE_BADGE_FOREGROUND),
                dragAndDropBorder: theme.getColor(PANEL_DRAG_AND_DROP_BORDER)
            })
        };
    }
    fillExtraContextMenuActions(actions) {
        if (this.getCompositeBarPosition() === CompositeBarPosition.TITLE) {
            const viewsSubmenuAction = this.getViewsSubmenuAction();
            if (viewsSubmenuAction) {
                actions.push(( new Separator()));
                actions.push(viewsSubmenuAction);
            }
        }
        const panelPositionMenu = this.menuService.getMenuActions(MenuId.PanelPositionMenu, this.contextKeyService, {
            shouldForwardArgs: true
        });
        const panelAlignMenu = this.menuService.getMenuActions(MenuId.PanelAlignmentMenu, this.contextKeyService, {
            shouldForwardArgs: true
        });
        const positionActions = getContextMenuActions(panelPositionMenu).secondary;
        const alignActions = getContextMenuActions(panelAlignMenu).secondary;
        const panelShowLabels = this.configurationService.getValue("workbench.panel.showLabels");
        const toggleShowLabelsAction = toAction({
            id: "workbench.action.panel.toggleShowLabels",
            label: panelShowLabels ? ( localize(3837, "Show Icons")) : ( localize(3838, "Show Labels")),
            run: () => this.configurationService.updateValue("workbench.panel.showLabels", !panelShowLabels)
        });
        actions.push(...[( new Separator()), ( new SubmenuAction("workbench.action.panel.position", ( localize(3839, "Panel Position")), positionActions)), ( new SubmenuAction("workbench.action.panel.align", ( localize(3840, "Align Panel")), alignActions)), toggleShowLabelsAction, toAction({
            id: TogglePanelAction.ID,
            label: ( localize(3841, "Hide Panel")),
            run: () => this.commandService.executeCommand(TogglePanelAction.ID)
        })]);
    }
    layout(width, height, top, left) {
        let dimensions;
        switch (this.layoutService.getPanelPosition()) {
        case Position.RIGHT:
            dimensions = ( new Dimension(width - 1, height));
            break;
        case Position.TOP:
            dimensions = ( new Dimension(width, height - 1));
            break;
        default:
            dimensions = ( new Dimension(width, height));
            break;
        }
        super.layout(dimensions.width, dimensions.height, top, left);
    }
    shouldShowCompositeBar() {
        return true;
    }
    getCompositeBarPosition() {
        return CompositeBarPosition.TITLE;
    }
    toJSON() {
        return {
            type: Parts.PANEL_PART
        };
    }
};
PanelPart = PanelPart_1 = ( __decorate([( __param(0, INotificationService)), ( __param(1, IStorageService)), ( __param(2, IContextMenuService)), ( __param(3, IWorkbenchLayoutService)), ( __param(4, IKeybindingService)), ( __param(5, IHoverService)), ( __param(6, IInstantiationService)), ( __param(7, IThemeService)), ( __param(8, IViewDescriptorService)), ( __param(9, IContextKeyService)), ( __param(10, IExtensionService)), ( __param(11, ICommandService)), ( __param(12, IMenuService)), ( __param(13, IConfigurationService))], PanelPart));

export { PanelPart };
