import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { localizeWithPath } from '../../../../nls.js';
import { registerAction2 } from '../../../../platform/actions/common/actions.js';
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { EditorPaneDescriptor } from '../../../browser/editor.js';
import { registerWorkbenchContribution2 } from '../../../common/contributions.js';
import { EditorExtensions } from '../../../common/editor.js';
import { IEditorGroupsService } from '../../../services/editor/common/editorGroupsService.js';
import { ShowWebViewEditorFindWidgetAction, HideWebViewEditorFindCommand, WebViewEditorFindNextCommand, WebViewEditorFindPreviousCommand, ReloadWebviewAction } from './webviewCommands.js';
import { WebviewEditor } from './webviewEditor.js';
import { WebviewInput } from './webviewEditorInput.js';
import { WebviewEditorInputSerializer } from './webviewEditorInputSerializer.js';
import './webviewWorkbenchService.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
(( Registry.as(EditorExtensions.EditorPane))).registerEditorPane(EditorPaneDescriptor.create(WebviewEditor, WebviewEditor.ID, ( localizeWithPath(
    'vs/workbench/contrib/webviewPanel/browser/webviewPanel.contribution',
    'webview.editor.label',
    "webview editor"
))), [( new SyncDescriptor(WebviewInput))]);
let WebviewPanelContribution = class WebviewPanelContribution extends Disposable {
    static { this.ID = 'workbench.contrib.webviewPanel'; }
    constructor(editorService, editorGroupService) {
        super();
        this.editorGroupService = editorGroupService;
        this._register(editorService.onWillOpenEditor(e => {
            const group = editorGroupService.getGroup(e.groupId);
            if (group) {
                this.onEditorOpening(e.editor, group);
            }
        }));
    }
    onEditorOpening(editor, group) {
        if (!(editor instanceof WebviewInput) || editor.typeId !== WebviewInput.typeId) {
            return;
        }
        if (group.contains(editor)) {
            return;
        }
        let previousGroup;
        const groups = this.editorGroupService.groups;
        for (const group of groups) {
            if (group.contains(editor)) {
                previousGroup = group;
                break;
            }
        }
        if (!previousGroup) {
            return;
        }
        previousGroup.closeEditor(editor);
    }
};
WebviewPanelContribution = ( __decorate([
    ( __param(0, IEditorService)),
    ( __param(1, IEditorGroupsService))
], WebviewPanelContribution));
registerWorkbenchContribution2(WebviewPanelContribution.ID, WebviewPanelContribution, 1 );
( Registry.as(EditorExtensions.EditorFactory)).registerEditorSerializer(WebviewEditorInputSerializer.ID, WebviewEditorInputSerializer);
registerAction2(ShowWebViewEditorFindWidgetAction);
registerAction2(HideWebViewEditorFindCommand);
registerAction2(WebViewEditorFindNextCommand);
registerAction2(WebViewEditorFindPreviousCommand);
registerAction2(ReloadWebviewAction);
