"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WidgetDescriptor = void 0;
const lodash_1 = require("../../../lodash.js");
const actions_1 = require("./actions.js");
const plugin_1 = require("./plugin.js");
class WidgetDescriptor {
    #id;
    #initPos;
    #view;
    #getPos;
    get id() {
        return this.#id;
    }
    get initPos() {
        return this.#initPos;
    }
    get view() {
        return this.#view;
    }
    get getPos() {
        return this.#getPos;
    }
    get pos() {
        return this.getPos?.() ?? this.initPos;
    }
    constructor(initPos, idPrefix) {
        this.#id = (0, lodash_1.uniqueId)(idPrefix);
        this.#initPos = initPos;
    }
    render(view, getPos) {
        this.#view = view;
        this.#getPos = getPos;
        return this.renderWidget(view, getPos);
    }
    applyTo(tr) {
        const meta = {
            type: 'add',
            descriptor: this,
        };
        return tr.setMeta(plugin_1.widgetDecorationPluginKey, meta);
    }
    rmDeco(tr) {
        return (0, actions_1.removeDecoration)(tr, this.id);
    }
}
exports.WidgetDescriptor = WidgetDescriptor;
//# sourceMappingURL=WidgetDescriptor.js.map
