import { AppObjectPM } from "@vived/core";
import { CalloutRepo } from "../../Callouts/Entities/CalloutRepo";
import { ChannelModelEntity } from "../Entities";
export class ModelHasCalloutsPM extends AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelHasCalloutsPM.type);
    }
}
ModelHasCalloutsPM.type = "ModelHasCalloutsPM";
export function makeModelHasCalloutsPM(appObject) {
    return new ModelHasCalloutsPmImp(appObject);
}
class ModelHasCalloutsPmImp extends ModelHasCalloutsPM {
    get channelModel() {
        return this.getCachedLocalComponent(ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, ModelHasCalloutsPM.type);
        this.onRepoChange = () => {
            if (!this.channelModel)
                return;
            let hasCallouts = false;
            this.channelModel.modelObjects().forEach((obj) => {
                if (hasCallouts)
                    return;
                const repo = obj.appObject.getComponent(CalloutRepo.type);
                if (repo && repo.getAll().length > 0) {
                    hasCallouts = true;
                }
            });
            this.doUpdateView(hasCallouts);
        };
        this.channelModel?.addChangeObserver(this.onRepoChange);
        this.onRepoChange();
    }
}
//# sourceMappingURL=ModelHasCalloutsPM.js.map