import { AppObjectPM } from "@vived/core";
import { ChannelModelEntity } from "../Entities";
export const defaultChannelModelVM = {
    childHasValidationMessage: false,
    modelObjectIds: [],
};
export class ChannelModelPM extends AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(ChannelModelPM.type);
    }
}
ChannelModelPM.type = "ChannelModelPM";
export function makeChannelModelPM(appObject) {
    return new ChannelModelPMImp(appObject);
}
class ChannelModelPMImp extends ChannelModelPM {
    get modelEntity() {
        return this.getCachedLocalComponent(ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.childHasValidationMessage !== b.childHasValidationMessage)
            return false;
        if (a.modelObjectIds.length !== b.modelObjectIds.length)
            return false;
        let objectsAreTheSame = true;
        a.modelObjectIds.forEach((objA, i) => {
            const objB = b.modelObjectIds[i];
            if (objA !== objB) {
                objectsAreTheSame = false;
            }
        });
        return objectsAreTheSame;
    }
    constructor(appObject) {
        super(appObject, ChannelModelPM.type);
        this.onEntityChange = () => {
            if (!this.modelEntity)
                return;
            let childHasValidationMessage = false;
            this.modelEntity.modelObjects().forEach((obj) => {
                if (childHasValidationMessage) {
                    // Don't need to keep checking
                    return;
                }
                if (obj.label.customLabelValidationMessage !== null) {
                    childHasValidationMessage = true;
                }
            });
            const vm = {
                childHasValidationMessage,
                modelObjectIds: this.modelEntity.modelObjectIds,
            };
            this.doUpdateView(vm);
        };
        this.modelEntity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
    }
}
//# sourceMappingURL=ChannelModelPM.js.map