import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
import { ContextView } from '../../../base/browser/ui/contextview/contextview.js';
import { Disposable, MutableDisposable, toDisposable } from '../../../base/common/lifecycle.js';
import { ILayoutService } from '../../layout/browser/layoutService.js';
import { getWindow } from '../../../base/browser/dom.js';
let ContextViewHandler = class ContextViewHandler extends Disposable {
    constructor(layoutService) {
        super();
        this.layoutService = layoutService;
        this.currentViewDisposable = this._register(( new MutableDisposable()));
        this.contextView = this._register(( new ContextView(this.layoutService.mainContainer, 1 )));
        this.layout();
        this._register(layoutService.onDidLayoutContainer(() => this.layout()));
    }
    showContextView(delegate, container, shadowRoot) {
        let domPosition;
        if (container) {
            if (container === this.layoutService.getContainer(getWindow(container))) {
                domPosition = 1 ;
            }
            else if (shadowRoot) {
                domPosition = 3 ;
            }
            else {
                domPosition = 2 ;
            }
        }
        else {
            domPosition = 1 ;
        }
        this.contextView.setContainer(container ?? this.layoutService.activeContainer, domPosition);
        this.contextView.show(delegate);
        const disposable = toDisposable(() => {
            if (this.currentViewDisposable === disposable) {
                this.hideContextView();
            }
        });
        this.currentViewDisposable.value = disposable;
        return disposable;
    }
    layout() {
        this.contextView.layout();
    }
    hideContextView(data) {
        this.contextView.hide(data);
    }
};
ContextViewHandler = ( __decorate([
    ( __param(0, ILayoutService))
], ContextViewHandler));
class ContextViewService extends ContextViewHandler {
    getContextViewElement() {
        return this.contextView.getViewElement();
    }
}
export { ContextViewHandler, ContextViewService };
