import { Disposable } from "../../../../base/common/lifecycle.mjs";
import { registerEditorContribution, registerEditorAction, EditorCommand, registerEditorCommand, EditorAction } from "../../../browser/editorExtensions.mjs";
import { EditorContextKeys } from "../../../common/editorContextKeys.mjs";
import { SignatureHelpTriggerKind } from "../../../common/languages.mjs";
import { Context } from "./provideSignatureHelp.mjs";
import { localize } from "../../../../nls.mjs";
import { ContextKeyExpr } from "../../../../platform/contextkey/common/contextkey.mjs";
import { IInstantiationService } from "../../../../platform/instantiation/common/instantiation.mjs";
import { ParameterHintsWidget } from "./parameterHintsWidget.mjs";
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);
  };
};
let ParameterHintsController = class ParameterHintsController2 extends Disposable {
  constructor(editor, instantiationService) {
    super();
    this.editor = editor;
    this.widget = this._register(instantiationService.createInstance(ParameterHintsWidget, this.editor));
  }
  static get(editor) {
    return editor.getContribution(ParameterHintsController2.ID);
  }
  cancel() {
    this.widget.cancel();
  }
  previous() {
    this.widget.previous();
  }
  next() {
    this.widget.next();
  }
  trigger(context) {
    this.widget.trigger(context);
  }
};
ParameterHintsController.ID = "editor.controller.parameterHints";
ParameterHintsController = __decorate([
  __param(1, IInstantiationService)
], ParameterHintsController);
class TriggerParameterHintsAction extends EditorAction {
  constructor() {
    super({
      id: "editor.action.triggerParameterHints",
      label: localize("parameterHints.trigger.label", "Trigger Parameter Hints"),
      alias: "Trigger Parameter Hints",
      precondition: EditorContextKeys.hasSignatureHelpProvider,
      kbOpts: {
        kbExpr: EditorContextKeys.editorTextFocus,
        primary: 2048 | 1024 | 10,
        weight: 100
        /* EditorContrib */
      }
    });
  }
  run(accessor, editor) {
    const controller = ParameterHintsController.get(editor);
    if (controller) {
      controller.trigger({
        triggerKind: SignatureHelpTriggerKind.Invoke
      });
    }
  }
}
registerEditorContribution(ParameterHintsController.ID, ParameterHintsController);
registerEditorAction(TriggerParameterHintsAction);
const weight = 100 + 75;
const ParameterHintsCommand = EditorCommand.bindToContribution(ParameterHintsController.get);
registerEditorCommand(new ParameterHintsCommand({
  id: "closeParameterHints",
  precondition: Context.Visible,
  handler: (x) => x.cancel(),
  kbOpts: {
    weight,
    kbExpr: EditorContextKeys.focus,
    primary: 9,
    secondary: [
      1024 | 9
      /* Escape */
    ]
  }
}));
registerEditorCommand(new ParameterHintsCommand({
  id: "showPrevParameterHint",
  precondition: ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures),
  handler: (x) => x.previous(),
  kbOpts: {
    weight,
    kbExpr: EditorContextKeys.focus,
    primary: 16,
    secondary: [
      512 | 16
      /* UpArrow */
    ],
    mac: { primary: 16, secondary: [
      512 | 16,
      256 | 46
      /* KeyP */
    ] }
  }
}));
registerEditorCommand(new ParameterHintsCommand({
  id: "showNextParameterHint",
  precondition: ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures),
  handler: (x) => x.next(),
  kbOpts: {
    weight,
    kbExpr: EditorContextKeys.focus,
    primary: 18,
    secondary: [
      512 | 18
      /* DownArrow */
    ],
    mac: { primary: 18, secondary: [
      512 | 18,
      256 | 44
      /* KeyN */
    ] }
  }
}));
export {
  TriggerParameterHintsAction
};
