import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { localizeWithPath } from '../../../../nls.js';
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
import { isMacintosh, isWeb, OS } from '../../../../base/common/platform.js';
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.service.js';
import { WorkbenchState } from '../../../../platform/workspace/common/workspace.js';
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.service.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.service.js';
import { h, append, $, clearNode } from '../../../../base/browser/dom.js';
import { KeybindingLabel } from '../../../../base/browser/ui/keybindingLabel/keybindingLabel.js';
import { CommandsRegistry } from '../../../../platform/commands/common/commands.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.service.js';
import { defaultKeybindingLabelStyles } from '../../../../platform/theme/browser/defaultStyles.js';
import { registerColor, transparent } from '../../../../platform/theme/common/colorUtils.js';
import '../../../../platform/theme/common/colors/baseColors.js';
import '../../../../platform/theme/common/colors/chartsColors.js';
import { editorForeground } from '../../../../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';
const _moduleId = "vs/workbench/browser/parts/editor/editorGroupWatermark";
registerColor('editorWatermark.foreground', { dark: ( (transparent(editorForeground, 0.6))), light: ( (transparent(editorForeground, 0.68))), hcDark: editorForeground, hcLight: editorForeground }, ( localizeWithPath(_moduleId, 0, 'Foreground color for the labels in the editor watermark.')));
const showCommands = { text: ( localizeWithPath(_moduleId, 1, "Show All Commands")), id: 'workbench.action.showCommands' };
const quickAccess = { text: ( localizeWithPath(_moduleId, 2, "Go to File")), id: 'workbench.action.quickOpen' };
const openFileNonMacOnly = { text: ( localizeWithPath(_moduleId, 3, "Open File")), id: 'workbench.action.files.openFile', mac: false };
const openFolderNonMacOnly = { text: ( localizeWithPath(_moduleId, 4, "Open Folder")), id: 'workbench.action.files.openFolder', mac: false };
const openFileOrFolderMacOnly = { text: ( localizeWithPath(_moduleId, 5, "Open File or Folder")), id: 'workbench.action.files.openFileFolder', mac: true };
const openRecent = { text: ( localizeWithPath(_moduleId, 6, "Open Recent")), id: 'workbench.action.openRecent' };
const newUntitledFileMacOnly = { text: ( localizeWithPath(_moduleId, 7, "New Untitled Text File")), id: 'workbench.action.files.newUntitledFile', mac: true };
const findInFiles = { text: ( localizeWithPath(_moduleId, 8, "Find in Files")), id: 'workbench.action.findInFiles' };
const toggleTerminal = { text: ( localizeWithPath(_moduleId, 9, "Toggle Terminal")), id: 'workbench.action.terminal.toggleTerminal', when: ( (ContextKeyExpr.equals('terminalProcessSupported', true))) };
const startDebugging = { text: ( localizeWithPath(_moduleId, 10, "Start Debugging")), id: 'workbench.action.debug.start', when: ( (ContextKeyExpr.equals('terminalProcessSupported', true))) };
const toggleFullscreen = { text: ( localizeWithPath(_moduleId, 11, "Toggle Full Screen")), id: 'workbench.action.toggleFullScreen' };
const showSettings = { text: ( localizeWithPath(_moduleId, 12, "Show Settings")), id: 'workbench.action.openSettings' };
const noFolderEntries = [
    showCommands,
    openFileNonMacOnly,
    openFolderNonMacOnly,
    openFileOrFolderMacOnly,
    openRecent,
    newUntitledFileMacOnly
];
const folderEntries = [
    showCommands,
    quickAccess,
    findInFiles,
    startDebugging,
    toggleTerminal,
    toggleFullscreen,
    showSettings
];
let EditorGroupWatermark = class EditorGroupWatermark extends Disposable {
    constructor(container, keybindingService, contextService, contextKeyService, configurationService) {
        super();
        this.keybindingService = keybindingService;
        this.contextService = contextService;
        this.contextKeyService = contextKeyService;
        this.configurationService = configurationService;
        this.transientDisposables = this._register(( (new DisposableStore())));
        this.enabled = false;
        this.keybindingLabels = ( (new Set()));
        const elements = h('.editor-group-watermark', [
            h('.letterpress'),
            h('.shortcuts@shortcuts'),
        ]);
        append(container, elements.root);
        this.shortcuts = elements.shortcuts;
        this.registerListeners();
        this.workbenchState = contextService.getWorkbenchState();
        this.render();
    }
    registerListeners() {
        this._register(this.configurationService.onDidChangeConfiguration(e => {
            if (e.affectsConfiguration('workbench.tips.enabled')) {
                this.render();
            }
        }));
        this._register(this.contextService.onDidChangeWorkbenchState(workbenchState => {
            if (this.workbenchState === workbenchState) {
                return;
            }
            this.workbenchState = workbenchState;
            this.render();
        }));
        const allEntriesWhenClauses = ( ([...noFolderEntries, ...folderEntries].filter(entry => entry.when !== undefined).map(entry => entry.when)));
        const allKeys = ( (new Set()));
        allEntriesWhenClauses.forEach(when => ( (when.keys())).forEach(key => allKeys.add(key)));
        this._register(this.contextKeyService.onDidChangeContext(e => {
            if (e.affectsSome(allKeys)) {
                this.render();
            }
        }));
    }
    render() {
        const enabled = this.configurationService.getValue('workbench.tips.enabled');
        if (enabled === this.enabled) {
            return;
        }
        this.enabled = enabled;
        this.clear();
        if (!enabled) {
            return;
        }
        const box = append(this.shortcuts, $('.watermark-box'));
        const folder = this.workbenchState !== WorkbenchState.EMPTY;
        const selected = (folder ? folderEntries : noFolderEntries)
            .filter(entry => !('when' in entry) || this.contextKeyService.contextMatchesRules(entry.when))
            .filter(entry => !('mac' in entry) || entry.mac === (isMacintosh && !isWeb))
            .filter(entry => !!CommandsRegistry.getCommand(entry.id))
            .filter(entry => !!this.keybindingService.lookupKeybinding(entry.id));
        const update = () => {
            clearNode(box);
            this.keybindingLabels.forEach(label => label.dispose());
            this.keybindingLabels.clear();
            for (const entry of selected) {
                const keys = this.keybindingService.lookupKeybinding(entry.id);
                if (!keys) {
                    continue;
                }
                const dl = append(box, $('dl'));
                const dt = append(dl, $('dt'));
                dt.textContent = entry.text;
                const dd = append(dl, $('dd'));
                const label = ( (new KeybindingLabel(
                    dd,
                    OS,
                    { renderUnboundKeybindings: true, ...defaultKeybindingLabelStyles }
                )));
                label.set(keys);
                this.keybindingLabels.add(label);
            }
        };
        update();
        this.transientDisposables.add(this.keybindingService.onDidUpdateKeybindings(update));
    }
    clear() {
        clearNode(this.shortcuts);
        this.transientDisposables.clear();
    }
    dispose() {
        super.dispose();
        this.clear();
        this.keybindingLabels.forEach(label => label.dispose());
    }
};
EditorGroupWatermark = ( (__decorate([
    ( (__param(1, IKeybindingService))),
    ( (__param(2, IWorkspaceContextService))),
    ( (__param(3, IContextKeyService))),
    ( (__param(4, IConfigurationService)))
], EditorGroupWatermark)));
export { EditorGroupWatermark };
