import { AppObjectPM } from "@vived/core";
import { CalloutRepo } from "../Entities/CalloutRepo";
export class CalloutListPM extends AppObjectPM {
    static getById(id, appObjects) {
        return appObjects.get(id)?.getComponent(CalloutListPM.type);
    }
}
CalloutListPM.type = "CalloutListPM";
export function makeCalloutListPM(appObject) {
    return new CalloutListPMImp(appObject);
}
class CalloutListPMImp extends CalloutListPM {
    get calloutRepo() {
        return this.getCachedLocalComponent(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