"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelModelObjectPM = exports.defaultChannelModelObjectVM = void 0;
exports.makeChannelModelObjectPM = makeChannelModelObjectPM;
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
exports.defaultChannelModelObjectVM = {
    label: "",
    labelValidationMessage: null,
    tags: [],
};
class ChannelModelObjectPM extends core_1.AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(ChannelModelObjectPM.type);
    }
}
exports.ChannelModelObjectPM = ChannelModelObjectPM;
ChannelModelObjectPM.type = "ChannelModelObjectPM";
function makeChannelModelObjectPM(appObject) {
    return new ChannelModelObjectPMImp(appObject);
}
class ChannelModelObjectPMImp extends ChannelModelObjectPM {
    get modelObject() {
        return this.getCachedLocalComponent(Entities_1.ChannelModelObject.type);
    }
    vmsAreEqual(a, b) {
        if (a.label !== b.label)
            return false;
        if (a.labelValidationMessage !== b.labelValidationMessage)
            return false;
        if (a.tags.length !== b.tags.length)
            return false;
        let tagsAreTheSame = true;
        a.tags.forEach((tagA, i) => {
            const tagB = b.tags[i];
            if (tagA !== tagB) {
                tagsAreTheSame = false;
            }
        });
        return tagsAreTheSame;
    }
    constructor(appObject) {
        super(appObject, ChannelModelObjectPM.type);
        this.onEntityChange = () => {
            if (!this.modelObject)
                return;
            const vm = {
                label: this.modelObject.label.display,
                labelValidationMessage: this.modelObject.label
                    .customLabelValidationMessage,
                tags: this.modelObject.tags,
            };
            this.doUpdateView(vm);
        };
        this.modelObject?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
    }
}
//# sourceMappingURL=ChannelModelObjectPM.js.map