"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const contextview = require("../../../base/browser/ui/contextview/contextview.js");
const lifecycle = require("../../../base/common/lifecycle.js");
const layoutService = require("../../layout/browser/layoutService.js");
var __decorate = globalThis && globalThis.__decorate || function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = globalThis && globalThis.__param || function(paramIndex, decorator) {
  return function(target, key) {
    decorator(target, key, paramIndex);
  };
};
exports.ContextViewService = class ContextViewService extends lifecycle.Disposable {
  constructor(layoutService2) {
    super();
    this.layoutService = layoutService2;
    this.currentViewDisposable = lifecycle.Disposable.None;
    this.container = layoutService2.hasContainer ? layoutService2.container : null;
    this.contextView = this._register(new contextview.ContextView(
      this.container,
      1
      /* ABSOLUTE */
    ));
    this.layout();
    this._register(layoutService2.onDidLayout(() => this.layout()));
  }
  // ContextView
  setContainer(container, domPosition) {
    this.contextView.setContainer(
      container,
      domPosition || 1
      /* ABSOLUTE */
    );
  }
  showContextView(delegate, container, shadowRoot) {
    if (container) {
      if (container !== this.container) {
        this.container = container;
        this.setContainer(
          container,
          shadowRoot ? 3 : 2
          /* FIXED */
        );
      }
    } else {
      if (this.layoutService.hasContainer && this.container !== this.layoutService.container) {
        this.container = this.layoutService.container;
        this.setContainer(
          this.container,
          1
          /* ABSOLUTE */
        );
      }
    }
    this.contextView.show(delegate);
    const disposable = lifecycle.toDisposable(() => {
      if (this.currentViewDisposable === disposable) {
        this.hideContextView();
      }
    });
    this.currentViewDisposable = disposable;
    return disposable;
  }
  getContextViewElement() {
    return this.contextView.getViewElement();
  }
  layout() {
    this.contextView.layout();
  }
  hideContextView(data) {
    this.contextView.hide(data);
  }
};
exports.ContextViewService = __decorate([
  __param(0, layoutService.ILayoutService)
], exports.ContextViewService);
