import { AppObjectPM } from "@vived/core";
import { ChannelModelObject } from "../Entities";
export const defaultChannelModelObjectVM = {
    label: "",
    labelValidationMessage: null,
    tags: [],
};
export class ChannelModelObjectPM extends AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(ChannelModelObjectPM.type);
    }
}
ChannelModelObjectPM.type = "ChannelModelObjectPM";
export function makeChannelModelObjectPM(appObject) {
    return new ChannelModelObjectPMImp(appObject);
}
class ChannelModelObjectPMImp extends ChannelModelObjectPM {
    get modelObject() {
        return this.getCachedLocalComponent(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