"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelHasCalloutsPM = void 0;
exports.makeModelHasCalloutsPM = makeModelHasCalloutsPM;
const core_1 = require("@vived/core");
const CalloutRepo_1 = require("../../Callouts/Entities/CalloutRepo");
const Entities_1 = require("../Entities");
class ModelHasCalloutsPM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelHasCalloutsPM.type);
    }
}
exports.ModelHasCalloutsPM = ModelHasCalloutsPM;
ModelHasCalloutsPM.type = "ModelHasCalloutsPM";
function makeModelHasCalloutsPM(appObject) {
    return new ModelHasCalloutsPmImp(appObject);
}
class ModelHasCalloutsPmImp extends ModelHasCalloutsPM {
    get channelModel() {
        return this.getCachedLocalComponent(Entities_1.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_1.CalloutRepo.type);
                if (repo && repo.getAll().length > 0) {
                    hasCallouts = true;
                }
            });
            this.doUpdateView(hasCallouts);
        };
        this.channelModel?.addChangeObserver(this.onRepoChange);
        this.onRepoChange();
    }
}
//# sourceMappingURL=ModelHasCalloutsPM.js.map