import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { LabelDropRepo } from "../Entities/LabelDropRepo";
export class RemainingLabelDropListPM extends AppObjectPM {
}
RemainingLabelDropListPM.type = "RemainingLabelDropListPM";
RemainingLabelDropListPM.get = (appObjects) => getSingletonComponent(RemainingLabelDropListPM.type, appObjects);
export function makeRemainingLabelDropListPM(appObject) {
    return new RemainingLabelDropListPMImp(appObject);
}
class RemainingLabelDropListPMImp extends RemainingLabelDropListPM {
    get labelDropRepo() {
        return this.getCachedSingleton(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