"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LabelDropTargetsPM = exports.defaultLabelDropTargetsVM = void 0;
exports.makeLabelDropTargetsPM = makeLabelDropTargetsPM;
const core_1 = require("@vived/core");
const LabelDropItemEntity_1 = require("../Entities/LabelDropItemEntity");
exports.defaultLabelDropTargetsVM = {
    targetIds: [],
    targetValidationMessage: undefined,
};
class LabelDropTargetsPM extends core_1.AppObjectPM {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(LabelDropTargetsPM.type);
    }
}
exports.LabelDropTargetsPM = LabelDropTargetsPM;
LabelDropTargetsPM.type = "LabelDropTargetsPM";
function makeLabelDropTargetsPM(appObject) {
    return new LabelDropTargetsPMImp(appObject);
}
class LabelDropTargetsPMImp extends LabelDropTargetsPM {
    get entity() {
        return this.getCachedLocalComponent(LabelDropItemEntity_1.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