import { structuralEquals } from '../../../../base/common/equals.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { derivedOpts, derived } from '../../../../base/common/observableInternal/derived.js';
import '../../../../base/common/observableInternal/autorun.js';
import '../../../../base/common/observableInternal/utils.js';
import '../../../../base/common/cancellation.js';
import './placeholderText.css.js';
import { registerEditorContribution, EditorContributionInstantiation } from '../../../browser/editorExtensions.js';
import { observableCodeEditor } from '../../../browser/observableCodeEditor.js';
import { EditorOption } from '../../../common/config/editorOptions.js';
import { ghostTextForeground } from '../../../common/core/editorColorRegistry.js';
import { Range } from '../../../common/core/range.js';
import { InjectedTextCursorStops } from '../../../common/model.js';
import { localizeWithPath } from '../../../../nls.js';
import { registerColor } from '../../../../platform/theme/common/colorUtils.js';
const _moduleId = "vs/editor/contrib/placeholderText/browser/placeholderText.contribution";
class PlaceholderTextContribution extends Disposable {
    static get(editor) {
        return editor.getContribution(PlaceholderTextContribution.ID);
    }
    static { this.ID = 'editor.contrib.placeholderText'; }
    constructor(_editor) {
        super();
        this._editor = _editor;
        this._editorObs = observableCodeEditor(this._editor);
        this._placeholderText = this._editorObs.getOption(EditorOption.placeholder);
        this._decorationOptions = derivedOpts({ owner: this, equalsFn: structuralEquals }, reader => {
            const p = this._placeholderText.read(reader);
            if (!p) {
                return undefined;
            }
            if (!this._editorObs.valueIsEmpty.read(reader)) {
                return undefined;
            }
            return { placeholder: p };
        });
        this._decorations = derived(this, (reader) => {
            const options = this._decorationOptions.read(reader);
            if (!options) {
                return [];
            }
            return [{
                    range: ( (new Range(1, 1, 1, 1))),
                    options: {
                        description: 'placeholder',
                        showIfCollapsed: true,
                        after: {
                            content: options.placeholder,
                            cursorStops: InjectedTextCursorStops.None,
                            inlineClassName: 'placeholder-text'
                        }
                    }
                }];
        });
        this._register(this._editorObs.setDecorations(this._decorations));
    }
}
registerEditorContribution(PlaceholderTextContribution.ID, PlaceholderTextContribution, EditorContributionInstantiation.Eager);
registerColor('editor.placeholder.foreground', { dark: ghostTextForeground, light: ghostTextForeground, hcDark: ghostTextForeground, hcLight: ghostTextForeground }, ( localizeWithPath(_moduleId, 0, 'Foreground color of the placeholder text in the editor.')));
export { PlaceholderTextContribution };
