"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemainingLabelDropListPM = void 0;
exports.makeRemainingLabelDropListPM = makeRemainingLabelDropListPM;
const core_1 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
class RemainingLabelDropListPM extends core_1.AppObjectPM {
}
exports.RemainingLabelDropListPM = RemainingLabelDropListPM;
RemainingLabelDropListPM.type = "RemainingLabelDropListPM";
RemainingLabelDropListPM.get = (appObjects) => (0, core_1.getSingletonComponent)(RemainingLabelDropListPM.type, appObjects);
function makeRemainingLabelDropListPM(appObject) {
    return new RemainingLabelDropListPMImp(appObject);
}
class RemainingLabelDropListPMImp extends RemainingLabelDropListPM {
    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;
            }
        }
        return vmsEqual;
    }
    constructor(appObject) {
        super(appObject, RemainingLabelDropListPM.type);
        this.onEntityChange = () => {
            if (!this.labelDropRepo)
                return;
            const labelDropIds = this.labelDropRepo.getRemainingLabelDrops();
            const items = this.labelDropRepo.getAll();
            const datas = [];
            items.forEach((item) => {
                if (labelDropIds.includes(item.id)) {
                    datas.push({
                        id: item.id,
                        label: item.labelEntity.display,
                    });
                }
            });
            this.doUpdateView(datas);
        };
        this.labelDropRepo?.addChangeObserver(this.onEntityChange);
        this.appObjects.registerSingleton(this);
        this.onEntityChange();
    }
}
//# sourceMappingURL=RemainingLabelDropListPM.js.map