"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalloutListPM = void 0;
exports.makeCalloutListPM = makeCalloutListPM;
const core_1 = require("@vived/core");
const CalloutRepo_1 = require("../Entities/CalloutRepo");
class CalloutListPM extends core_1.AppObjectPM {
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(CalloutListPM.type);
    }
}
exports.CalloutListPM = CalloutListPM;
CalloutListPM.type = "CalloutListPM";
function makeCalloutListPM(appObject) {
    return new CalloutListPMImp(appObject);
}
class CalloutListPMImp extends CalloutListPM {
    get calloutRepo() {
        return this.getCachedLocalComponent(CalloutRepo_1.CalloutRepo.type);
    }
    vmsAreEqual(a, b) {
        if (a.length !== b.length)
            return false;
        let idAreTheSame = true;
        a.forEach((aId, i) => {
            if (!idAreTheSame)
                return;
            const bId = b[i];
            if (aId !== bId) {
                idAreTheSame = false;
            }
        });
        return idAreTheSame;
    }
    constructor(appObject) {
        super(appObject, CalloutListPM.type);
        this.onRepoChange = () => {
            if (!this.calloutRepo)
                return;
            const callouts = this.calloutRepo.getAll();
            const ids = callouts.map((callout) => callout.appObject.id);
            this.doUpdateView(ids);
        };
        this.calloutRepo?.addChangeObserver(this.onRepoChange);
        this.onRepoChange();
    }
}
//# sourceMappingURL=CalloutListPM.js.map