"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LabelDropReviewPM = void 0;
exports.makeLabelDropReviewPM = makeLabelDropReviewPM;
const core_1 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
class LabelDropReviewPM extends core_1.AppObjectPM {
}
exports.LabelDropReviewPM = LabelDropReviewPM;
LabelDropReviewPM.type = "LabelDropReviewPM";
LabelDropReviewPM.get = (appObjects) => (0, core_1.getSingletonComponent)(LabelDropReviewPM.type, appObjects);
function makeLabelDropReviewPM(appObject) {
    return new LabelDropReviewPMImp(appObject);
}
class LabelDropReviewPMImp extends LabelDropReviewPM {
    get labelDropRepo() {
        return this.getCachedSingleton(LabelDropRepo_1.LabelDropRepo.type);
    }
    vmsAreEqual(a, b) {
        if (a.length !== b.length)
            return false;
        let vmsEqual = true;
        for (let i = 0; i < a.length; i++) {
            if (a[i].id !== b[i].id) {
                vmsEqual = false;
            }
            else if (a[i].label !== b[i].label) {
                vmsEqual = false;
            }
            else if (a[i].tries !== b[i].tries) {
                vmsEqual = false;
            }
        }
        return vmsEqual;
    }
    constructor(appObject) {
        super(appObject, LabelDropReviewPM.type);
        this.onEntityChange = () => {
            if (!this.labelDropRepo)
                return;
            const labelDropReviewVM = this.labelDropRepo
                .getAll()
                .map((item) => {
                return {
                    id: item.id,
                    label: item.labelEntity.display,
                    tries: item.tries,
                };
            });
            this.doUpdateView(labelDropReviewVM);
        };
        this.labelDropRepo?.addChangeObserver(this.onEntityChange);
        this.appObjects.registerSingleton(this);
        this.onEntityChange();
    }
}
//# sourceMappingURL=LabelDropReviewPM.js.map