
import '../../../../../../base/common/observableInternal/index.js';
import { localize } from '../../../../../../nls.js';
import { observableCodeEditor } from '../../../../../browser/observableCodeEditor.js';
import { StringText, TextEdit } from '../../../../../common/core/textEdit.js';
import { InlineEditTabAction } from './inlineEditsViewInterface.js';
import { InlineEditWithChanges } from './inlineEditWithChanges.js';
import { derived } from '../../../../../../base/common/observableInternal/derived.js';

class InlineEditModel {
    constructor(_model, inlineEdit, tabAction) {
        this._model = _model;
        this.inlineEdit = inlineEdit;
        this.tabAction = tabAction;
        this.action = this.inlineEdit.inlineCompletion.action;
        this.displayName = this.inlineEdit.inlineCompletion.source.provider.displayName ?? ( localize(1280, "Inline Edit"));
        this.extensionCommands = this.inlineEdit.inlineCompletion.source.inlineCompletions.commands ?? [];
        this.showCollapsed = this._model.showCollapsed;
    }
    accept() {
        this._model.accept();
    }
    jump() {
        this._model.jump();
    }
    abort(reason) {
        console.error(reason);
        this._model.stop();
    }
    handleInlineEditShown() {
        this._model.handleInlineEditShown(this.inlineEdit.inlineCompletion);
    }
}
class InlineEditHost {
    constructor(_model) {
        this._model = _model;
        this.onDidAccept = this._model.onDidAccept;
        this.inAcceptFlow = this._model.inAcceptFlow;
        this.inPartialAcceptFlow = this._model.inPartialAcceptFlow;
    }
}
class GhostTextIndicator {
    constructor(editor, model, lineRange, inlineCompletion) {
        this.lineRange = lineRange;
        const editorObs = observableCodeEditor(editor);
        const tabAction = derived(this, reader => {
            if (editorObs.isFocused.read(reader)) {
                if (model.inlineCompletionState.read(reader)?.inlineCompletion?.sourceInlineCompletion.showInlineEditMenu) {
                    return InlineEditTabAction.Accept;
                }
            }
            return InlineEditTabAction.Inactive;
        });
        this.model = ( new InlineEditModel(model, ( new InlineEditWithChanges(( new StringText('')), ( new TextEdit([])), model.primaryPosition.get(), inlineCompletion.source.inlineCompletions.commands ?? [], inlineCompletion.inlineCompletion)), tabAction));
    }
}

export { GhostTextIndicator, InlineEditHost, InlineEditModel };
