import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { KeyCode, KeyMod as KeyMod$1 } from '../../../../base/common/keyCodes.js';
import { Lazy } from '../../../../base/common/lazy.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { registerEditorContribution, registerEditorAction, registerEditorCommand, EditorContributionInstantiation, EditorCommand, EditorAction } from '../../../browser/editorExtensions.js';
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
import { SignatureHelpTriggerKind } from '../../../common/languages.js';
import { ILanguageFeaturesService } from '../../../common/services/languageFeatures.js';
import { ParameterHintsModel } from './parameterHintsModel.js';
import { Context } from './provideSignatureHelp.js';
import { localizeWithPath } from '../../../../nls.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { ParameterHintsWidget } from './parameterHintsWidget.js';
var ParameterHintsController_1;
const _moduleId = "vs/editor/contrib/parameterHints/browser/parameterHints";
let ParameterHintsController = class ParameterHintsController extends Disposable {
    static { ParameterHintsController_1 = this; }
    static { this.ID = 'editor.controller.parameterHints'; }
    static get(editor) {
        return editor.getContribution(ParameterHintsController_1.ID);
    }
    constructor(editor, instantiationService, languageFeaturesService) {
        super();
        this.editor = editor;
        this.model = this._register(( (new ParameterHintsModel(editor, languageFeaturesService.signatureHelpProvider))));
        this._register(this.model.onChangedHints(newParameterHints => {
            if (newParameterHints) {
                this.widget.value.show();
                this.widget.value.render(newParameterHints);
            }
            else {
                this.widget.rawValue?.hide();
            }
        }));
        this.widget = ( (new Lazy(
            () => this._register(instantiationService.createInstance(ParameterHintsWidget, this.editor, this.model))
        )));
    }
    cancel() {
        this.model.cancel();
    }
    previous() {
        this.widget.rawValue?.previous();
    }
    next() {
        this.widget.rawValue?.next();
    }
    trigger(context) {
        this.model.trigger(context, 0);
    }
};
ParameterHintsController = ParameterHintsController_1 = ( (__decorate([
    ( (__param(1, IInstantiationService))),
    ( (__param(2, ILanguageFeaturesService)))
], ParameterHintsController)));
class TriggerParameterHintsAction extends EditorAction {
    constructor() {
        super({
            id: 'editor.action.triggerParameterHints',
            label: ( localizeWithPath(_moduleId, 0, "Trigger Parameter Hints")),
            alias: 'Trigger Parameter Hints',
            precondition: EditorContextKeys.hasSignatureHelpProvider,
            kbOpts: {
                kbExpr: EditorContextKeys.editorTextFocus,
                primary: KeyMod$1.CtrlCmd | KeyMod$1.Shift | KeyCode.Space,
                weight: KeybindingWeight.EditorContrib
            }
        });
    }
    run(accessor, editor) {
        const controller = ParameterHintsController.get(editor);
        controller?.trigger({
            triggerKind: SignatureHelpTriggerKind.Invoke
        });
    }
}
registerEditorContribution(ParameterHintsController.ID, ParameterHintsController, EditorContributionInstantiation.BeforeFirstInteraction);
registerEditorAction(TriggerParameterHintsAction);
const weight = KeybindingWeight.EditorContrib + 75;
const ParameterHintsCommand = EditorCommand.bindToContribution(ParameterHintsController.get);
registerEditorCommand(( (new ParameterHintsCommand({
    id: 'closeParameterHints',
    precondition: Context.Visible,
    handler: x => x.cancel(),
    kbOpts: {
        weight: weight,
        kbExpr: EditorContextKeys.focus,
        primary: KeyCode.Escape,
        secondary: [KeyMod$1.Shift | KeyCode.Escape]
    }
}))));
registerEditorCommand(( (new ParameterHintsCommand({
    id: 'showPrevParameterHint',
    precondition: ( (ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures))),
    handler: x => x.previous(),
    kbOpts: {
        weight: weight,
        kbExpr: EditorContextKeys.focus,
        primary: KeyCode.UpArrow,
        secondary: [KeyMod$1.Alt | KeyCode.UpArrow],
        mac: { primary: KeyCode.UpArrow, secondary: [KeyMod$1.Alt | KeyCode.UpArrow, KeyMod$1.WinCtrl | KeyCode.KeyP] }
    }
}))));
registerEditorCommand(( (new ParameterHintsCommand({
    id: 'showNextParameterHint',
    precondition: ( (ContextKeyExpr.and(Context.Visible, Context.MultipleSignatures))),
    handler: x => x.next(),
    kbOpts: {
        weight: weight,
        kbExpr: EditorContextKeys.focus,
        primary: KeyCode.DownArrow,
        secondary: [KeyMod$1.Alt | KeyCode.DownArrow],
        mac: { primary: KeyCode.DownArrow, secondary: [KeyMod$1.Alt | KeyCode.DownArrow, KeyMod$1.WinCtrl | KeyCode.KeyN] }
    }
}))));
export { ParameterHintsController, TriggerParameterHintsAction };
