"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./standaloneQuickInput.css.js");
const editorExtensions = require("../../../browser/editorExtensions.js");
const themeService = require("../../../../platform/theme/common/themeService.js");
const cancellation = require("../../../../base/common/cancellation.js");
const instantiation = require("../../../../platform/instantiation/common/instantiation.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const accessibility = require("../../../../platform/accessibility/common/accessibility.js");
const standaloneLayoutService = require("../standaloneLayoutService.js");
const codeEditorService = require("../../../browser/services/codeEditorService.js");
const quickInput = require("../../../../platform/quickinput/browser/quickInput.js");
const functional = require("../../../../base/common/functional.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.EditorScopedQuickInputService = class EditorScopedQuickInputService extends quickInput.QuickInputService {
  constructor(editor, instantiationService, contextKeyService, themeService2, accessibilityService, codeEditorService2) {
    super(instantiationService, contextKeyService, themeService2, accessibilityService, new standaloneLayoutService.EditorScopedLayoutService(editor.getContainerDomNode(), codeEditorService2));
    this.host = void 0;
    const contribution = QuickInputEditorContribution.get(editor);
    if (contribution) {
      const widget = contribution.widget;
      this.host = {
        _serviceBrand: void 0,
        get hasContainer() {
          return true;
        },
        get container() {
          return widget.getDomNode();
        },
        get dimension() {
          return editor.getLayoutInfo();
        },
        get onDidLayout() {
          return editor.onDidLayoutChange;
        },
        focus: () => editor.focus()
      };
    } else {
      this.host = void 0;
    }
  }
  createController() {
    return super.createController(this.host);
  }
};
exports.EditorScopedQuickInputService = __decorate([
  __param(1, instantiation.IInstantiationService),
  __param(2, contextkey.IContextKeyService),
  __param(3, themeService.IThemeService),
  __param(4, accessibility.IAccessibilityService),
  __param(5, codeEditorService.ICodeEditorService)
], exports.EditorScopedQuickInputService);
exports.StandaloneQuickInputService = class StandaloneQuickInputService {
  constructor(instantiationService, codeEditorService2) {
    this.instantiationService = instantiationService;
    this.codeEditorService = codeEditorService2;
    this.mapEditorToService = /* @__PURE__ */ new Map();
  }
  get activeService() {
    const editor = this.codeEditorService.getFocusedCodeEditor();
    if (!editor) {
      throw new Error("Quick input service needs a focused editor to work.");
    }
    let quickInputService = this.mapEditorToService.get(editor);
    if (!quickInputService) {
      const newQuickInputService = quickInputService = this.instantiationService.createInstance(exports.EditorScopedQuickInputService, editor);
      this.mapEditorToService.set(editor, quickInputService);
      functional.once(editor.onDidDispose)(() => {
        newQuickInputService.dispose();
        this.mapEditorToService.delete(editor);
      });
    }
    return quickInputService;
  }
  get quickAccess() {
    return this.activeService.quickAccess;
  }
  pick(picks, options = {}, token = cancellation.CancellationToken.None) {
    return this.activeService.pick(picks, options, token);
  }
  createQuickPick() {
    return this.activeService.createQuickPick();
  }
};
exports.StandaloneQuickInputService = __decorate([
  __param(0, instantiation.IInstantiationService),
  __param(1, codeEditorService.ICodeEditorService)
], exports.StandaloneQuickInputService);
class QuickInputEditorContribution {
  constructor(editor) {
    this.editor = editor;
    this.widget = new QuickInputEditorWidget(this.editor);
  }
  static get(editor) {
    return editor.getContribution(QuickInputEditorContribution.ID);
  }
  dispose() {
    this.widget.dispose();
  }
}
QuickInputEditorContribution.ID = "editor.controller.quickInput";
class QuickInputEditorWidget {
  constructor(codeEditor) {
    this.codeEditor = codeEditor;
    this.domNode = document.createElement("div");
    this.codeEditor.addOverlayWidget(this);
  }
  getId() {
    return QuickInputEditorWidget.ID;
  }
  getDomNode() {
    return this.domNode;
  }
  getPosition() {
    return {
      preference: 2
      /* TOP_CENTER */
    };
  }
  dispose() {
    this.codeEditor.removeOverlayWidget(this);
  }
}
QuickInputEditorWidget.ID = "editor.contrib.quickInputWidget";
editorExtensions.registerEditorContribution(QuickInputEditorContribution.ID, QuickInputEditorContribution);
exports.QuickInputEditorContribution = QuickInputEditorContribution;
exports.QuickInputEditorWidget = QuickInputEditorWidget;
