import { MarkdownString } from '../../../../base/common/htmlContent.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { registerEditorContribution, EditorContributionInstantiation } from '../../../browser/editorExtensions.js';
import { EditorOption } from '../../../common/config/editorOptions.js';
import { MessageController } from '../../message/browser/messageController.js';
import { localizeWithPath } from '../../../../nls.js';
const _moduleId = "vs/editor/contrib/readOnlyMessage/browser/contribution";
class ReadOnlyMessageController extends Disposable {
    static { this.ID = 'editor.contrib.readOnlyMessageController'; }
    constructor(editor) {
        super();
        this.editor = editor;
        this._register(this.editor.onDidAttemptReadOnlyEdit(() => this._onDidAttemptReadOnlyEdit()));
    }
    _onDidAttemptReadOnlyEdit() {
        const messageController = MessageController.get(this.editor);
        if (messageController && this.editor.hasModel()) {
            let message = this.editor.getOptions().get(EditorOption.readOnlyMessage);
            if (!message) {
                if (this.editor.isSimpleWidget) {
                    message = ( (new MarkdownString(( localizeWithPath(_moduleId, 0, "Cannot edit in read-only input")))));
                }
                else {
                    message = ( (new MarkdownString(( localizeWithPath(_moduleId, 1, "Cannot edit in read-only editor")))));
                }
            }
            messageController.showMessage(message, this.editor.getPosition());
        }
    }
}
registerEditorContribution(ReadOnlyMessageController.ID, ReadOnlyMessageController, EditorContributionInstantiation.BeforeFirstInteraction);
export { ReadOnlyMessageController };
