import { AppObjectPM } from "@vived/core";
import { LabelDropItemEntity } from "../Entities/LabelDropItemEntity";
export const defaultLabelDropTargetsVM = {
    targetIds: [],
    targetValidationMessage: undefined,
};
export class LabelDropTargetsPM extends AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(LabelDropTargetsPM.type);
    }
}
LabelDropTargetsPM.type = "LabelDropTargetsPM";
export function makeLabelDropTargetsPM(appObject) {
    return new LabelDropTargetsPMImp(appObject);
}
class LabelDropTargetsPMImp extends LabelDropTargetsPM {
    get entity() {
        return this.getCachedLocalComponent(LabelDropItemEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.targetValidationMessage !== b.targetValidationMessage)
            return false;
        if (a.targetIds.length !== b.targetIds.length)
            return false;
        let targetsAreEqual = true;
        for (let i = 0; i < a.targetIds.length; i++) {
            if (a.targetIds[i] !== b.targetIds[i]) {
                targetsAreEqual = false;
            }
        }
        return targetsAreEqual;
    }
    constructor(appObject) {
        super(appObject, LabelDropTargetsPM.type);
        this.onEntityChange = () => {
            if (!this.entity)
                return;
            const vm = {
                targetIds: [...this.entity.targetIds],
                targetValidationMessage: this.entity.targetValidationMessage,
            };
            this.doUpdateView(vm);
        };
        this.entity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
    }
}
//# sourceMappingURL=LabelDropTargetsPM.js.map