import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import './media/auxiliaryBarPart.css.js';
import { localizeWithPath } from '../../../../nls.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
import { INotificationService } from '../../../../platform/notification/common/notification.js';
import { IStorageService } from '../../../../platform/storage/common/storage.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 { IThemeService } from '../../../../platform/theme/common/themeService.js';
import { ActiveAuxiliaryContext, AuxiliaryBarFocusContext } from '../../../common/contextkeys.js';
import { SIDE_BAR_BORDER, SIDE_BAR_BACKGROUND, SIDE_BAR_FOREGROUND, PANEL_ACTIVE_TITLE_BORDER, ACTIVITY_BAR_TOP_ACTIVE_BORDER, PANEL_ACTIVE_TITLE_FOREGROUND, ACTIVITY_BAR_TOP_FOREGROUND, PANEL_INACTIVE_TITLE_FOREGROUND, ACTIVITY_BAR_TOP_INACTIVE_FOREGROUND, ACTIVITY_BAR_BADGE_BACKGROUND, ACTIVITY_BAR_BADGE_FOREGROUND, PANEL_DRAG_AND_DROP_BORDER, ACTIVITY_BAR_TOP_DRAG_AND_DROP_BORDER } from '../../../common/theme.js';
import { IViewDescriptorService } from '../../../common/views.js';
import { IExtensionService } from '../../../services/extensions/common/extensions.js';
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
import { Separator, SubmenuAction, toAction } from '../../../../base/common/actions.js';
import { ToggleAuxiliaryBarAction } from './auxiliaryBarActions.js';
import { assertIsDefined } from '../../../../base/common/types.js';
import { ToggleSidebarPositionAction } from '../../actions/layoutActions.js';
import { ICommandService } from '../../../../platform/commands/common/commands.js';
import { AbstractPaneCompositePart, CompositeBarPosition } from '../paneCompositePart.js';
import { prepareActions } from '../../../../base/browser/ui/actionbar/actionbar.js';
import { MenuId, IMenuService } from '../../../../platform/actions/common/actions.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { createAndFillInContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js';
import { $ } from '../../../../base/browser/dom.js';
import { WorkbenchToolBar } from '../../../../platform/actions/browser/toolbar.js';
import { ActionViewItem } from '../../../../base/browser/ui/actionbar/actionViewItems.js';
import { CompositeMenuActions } from '../../actions.js';
var AuxiliaryBarPart_1;
let AuxiliaryBarPart = class AuxiliaryBarPart extends AbstractPaneCompositePart {
    static { AuxiliaryBarPart_1 = this; }
    static { this.activePanelSettingsKey = 'workbench.auxiliarybar.activepanelid'; }
    static { this.pinnedPanelsKey = 'workbench.auxiliarybar.pinnedPanels'; }
    static { this.placeholdeViewContainersKey = 'workbench.auxiliarybar.placeholderPanels'; }
    static { this.viewContainersWorkspaceStateKey = 'workbench.auxiliarybar.viewContainersWorkspaceState'; }
    get preferredHeight() {
        return this.layoutService.mainContainerDimension.height * 0.4;
    }
    get preferredWidth() {
        const activeComposite = this.getActivePaneComposite();
        if (!activeComposite) {
            return;
        }
        const width = activeComposite.getOptimalWidth();
        if (typeof width !== 'number') {
            return;
        }
        return Math.max(width, 300);
    }
    constructor(notificationService, storageService, contextMenuService, layoutService, keybindingService, instantiationService, themeService, viewDescriptorService, contextKeyService, extensionService, commandService, menuService, configurationService) {
        super("workbench.parts.auxiliarybar" , {
            hasTitle: true,
            borderWidth: () => (this.getColor(SIDE_BAR_BORDER) || this.getColor(contrastBorder)) ? 1 : 0,
        }, AuxiliaryBarPart_1.activePanelSettingsKey, ActiveAuxiliaryContext.bindTo(contextKeyService), AuxiliaryBarFocusContext.bindTo(contextKeyService), 'auxiliarybar', 'auxiliarybar', undefined, notificationService, storageService, contextMenuService, layoutService, keybindingService, instantiationService, themeService, viewDescriptorService, contextKeyService, extensionService, menuService);
        this.commandService = commandService;
        this.configurationService = configurationService;
        this.minimumWidth = 170;
        this.maximumWidth = Number.POSITIVE_INFINITY;
        this.minimumHeight = 0;
        this.maximumHeight = Number.POSITIVE_INFINITY;
        this.priority = 1 ;
        this._register(configurationService.onDidChangeConfiguration(e => {
            if (e.affectsConfiguration("workbench.activityBar.location" )) {
                this.onDidChangeActivityBarLocation();
            }
        }));
    }
    onDidChangeActivityBarLocation() {
        this.updateCompositeBar();
        const id = this.getActiveComposite()?.getId();
        if (id) {
            this.onTitleAreaUpdate(id);
        }
    }
    updateStyles() {
        super.updateStyles();
        const container = assertIsDefined(this.getContainer());
        container.style.backgroundColor = this.getColor(SIDE_BAR_BACKGROUND) || '';
        const borderColor = this.getColor(SIDE_BAR_BORDER) || this.getColor(contrastBorder);
        const isPositionLeft = this.layoutService.getSideBarPosition() === 1 ;
        container.style.color = this.getColor(SIDE_BAR_FOREGROUND) || '';
        container.style.borderLeftColor = borderColor ?? '';
        container.style.borderRightColor = borderColor ?? '';
        container.style.borderLeftStyle = borderColor && !isPositionLeft ? 'solid' : 'none';
        container.style.borderRightStyle = borderColor && isPositionLeft ? 'solid' : 'none';
        container.style.borderLeftWidth = borderColor && !isPositionLeft ? '1px' : '0px';
        container.style.borderRightWidth = borderColor && isPositionLeft ? '1px' : '0px';
    }
    getCompositeBarOptions() {
        const $this = this;
        return {
            partContainerClass: 'auxiliarybar',
            pinnedViewContainersKey: AuxiliaryBarPart_1.pinnedPanelsKey,
            placeholderViewContainersKey: AuxiliaryBarPart_1.placeholdeViewContainersKey,
            viewContainersWorkspaceStateKey: AuxiliaryBarPart_1.viewContainersWorkspaceStateKey,
            icon: true,
            orientation: 0 ,
            recomputeSizes: true,
            activityHoverOptions: {
                position: () => this.getCompositeBarPosition() === CompositeBarPosition.BOTTOM ? 3  : 2 ,
            },
            fillExtraContextMenuActions: actions => this.fillExtraContextMenuActions(actions),
            compositeSize: 0,
            iconSize: 16,
            get overflowActionSize() { return $this.getCompositeBarPosition() === CompositeBarPosition.TITLE ? 40 : 30; },
            colors: theme => ({
                activeBackgroundColor: theme.getColor(SIDE_BAR_BACKGROUND),
                inactiveBackgroundColor: theme.getColor(SIDE_BAR_BACKGROUND),
                get activeBorderBottomColor() { return $this.getCompositeBarPosition() === CompositeBarPosition.TITLE ? theme.getColor(PANEL_ACTIVE_TITLE_BORDER) : theme.getColor(ACTIVITY_BAR_TOP_ACTIVE_BORDER); },
                get activeForegroundColor() { return $this.getCompositeBarPosition() === CompositeBarPosition.TITLE ? theme.getColor(PANEL_ACTIVE_TITLE_FOREGROUND) : theme.getColor(ACTIVITY_BAR_TOP_FOREGROUND); },
                get inactiveForegroundColor() { return $this.getCompositeBarPosition() === CompositeBarPosition.TITLE ? theme.getColor(PANEL_INACTIVE_TITLE_FOREGROUND) : theme.getColor(ACTIVITY_BAR_TOP_INACTIVE_FOREGROUND); },
                badgeBackground: theme.getColor(ACTIVITY_BAR_BADGE_BACKGROUND),
                badgeForeground: theme.getColor(ACTIVITY_BAR_BADGE_FOREGROUND),
                get dragAndDropBorder() { return $this.getCompositeBarPosition() === CompositeBarPosition.TITLE ? theme.getColor(PANEL_DRAG_AND_DROP_BORDER) : theme.getColor(ACTIVITY_BAR_TOP_DRAG_AND_DROP_BORDER); }
            }),
            compact: true
        };
    }
    fillExtraContextMenuActions(actions) {
        const currentPositionRight = this.layoutService.getSideBarPosition() === 0 ;
        const viewsSubmenuAction = this.getViewsSubmenuAction();
        if (viewsSubmenuAction) {
            actions.push(( new Separator()));
            actions.push(viewsSubmenuAction);
        }
        const activityBarPositionMenu = this.menuService.createMenu(MenuId.ActivityBarPositionMenu, this.contextKeyService);
        const positionActions = [];
        createAndFillInContextMenuActions(activityBarPositionMenu, { shouldForwardArgs: true, renderShortTitle: true }, { primary: [], secondary: positionActions });
        activityBarPositionMenu.dispose();
        actions.push(...[
            ( new Separator()),
            ( new SubmenuAction('workbench.action.panel.position', ( localizeWithPath(
                'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart',
                'activity bar position',
                "Activity Bar Position"
            )), positionActions)),
            toAction({ id: ToggleSidebarPositionAction.ID, label: currentPositionRight ? ( localizeWithPath(
                'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart',
                'move second side bar left',
                "Move Secondary Side Bar Left"
            )) : ( localizeWithPath(
                'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart',
                'move second side bar right',
                "Move Secondary Side Bar Right"
            )), run: () => this.commandService.executeCommand(ToggleSidebarPositionAction.ID) }),
            toAction({ id: ToggleAuxiliaryBarAction.ID, label: ( localizeWithPath(
                'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart',
                'hide second side bar',
                "Hide Secondary Side Bar"
            )), run: () => this.commandService.executeCommand(ToggleAuxiliaryBarAction.ID) })
        ]);
    }
    shouldShowCompositeBar() {
        return this.configurationService.getValue("workbench.activityBar.location" ) !== "hidden" ;
    }
    getCompositeBarPosition() {
        const activityBarPosition = this.configurationService.getValue("workbench.activityBar.location" );
        switch (activityBarPosition) {
            case "top" : return CompositeBarPosition.TOP;
            case "bottom" : return CompositeBarPosition.BOTTOM;
            case "hidden" : return CompositeBarPosition.TITLE;
            case "default" : return CompositeBarPosition.TITLE;
            default: return CompositeBarPosition.TITLE;
        }
    }
    createHeaderArea() {
        const headerArea = super.createHeaderArea();
        const globalHeaderContainer = $('.auxiliary-bar-global-header');
        const menu = this.headerFooterCompositeBarDispoables.add(this.instantiationService.createInstance(CompositeMenuActions, MenuId.AuxiliaryBarHeader, undefined, undefined));
        const toolBar = this.headerFooterCompositeBarDispoables.add(this.instantiationService.createInstance(WorkbenchToolBar, globalHeaderContainer, {
            actionViewItemProvider: (action, options) => this.headerActionViewItemProvider(action, options),
            orientation: 0 ,
            hiddenItemStrategy: -1 ,
            getKeyBinding: action => this.keybindingService.lookupKeybinding(action.id),
        }));
        toolBar.setActions(prepareActions(menu.getPrimaryActions()));
        this.headerFooterCompositeBarDispoables.add(menu.onDidChange(() => toolBar.setActions(prepareActions(menu.getPrimaryActions()))));
        headerArea.appendChild(globalHeaderContainer);
        return headerArea;
    }
    getToolbarWidth() {
        if (this.getCompositeBarPosition() === CompositeBarPosition.TOP) {
            return 22;
        }
        return super.getToolbarWidth();
    }
    headerActionViewItemProvider(action, options) {
        if (action.id === ToggleAuxiliaryBarAction.ID) {
            return this.instantiationService.createInstance(ActionViewItem, undefined, action, options);
        }
        return undefined;
    }
    toJSON() {
        return {
            type: "workbench.parts.auxiliarybar"
        };
    }
};
AuxiliaryBarPart = AuxiliaryBarPart_1 = ( __decorate([
    ( __param(0, INotificationService)),
    ( __param(1, IStorageService)),
    ( __param(2, IContextMenuService)),
    ( __param(3, IWorkbenchLayoutService)),
    ( __param(4, IKeybindingService)),
    ( __param(5, IInstantiationService)),
    ( __param(6, IThemeService)),
    ( __param(7, IViewDescriptorService)),
    ( __param(8, IContextKeyService)),
    ( __param(9, IExtensionService)),
    ( __param(10, ICommandService)),
    ( __param(11, IMenuService)),
    ( __param(12, IConfigurationService))
], AuxiliaryBarPart));
export { AuxiliaryBarPart };
