"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultStickTargetVM = exports.StickTargetPM = void 0;
exports.makeStickTargetPM = makeStickTargetPM;
const core_1 = require("@vived/core");
const Stickable_1 = require("../Entities/Stickable");
class StickTargetPM extends core_1.AppObjectPM {
    static get(id, appObjects) {
        return appObjects.get(id)?.getComponent(StickTargetPM.type);
    }
}
exports.StickTargetPM = StickTargetPM;
StickTargetPM.type = "StickTargetPM";
function makeStickTargetPM(appObject) {
    return new StickTargetPMImp(appObject);
}
class StickTargetPMImp extends StickTargetPM {
    get entity() {
        return this.getCachedLocalComponent(Stickable_1.StickableEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.highlightTarget !== b.highlightTarget)
            return false;
        if (a.showStickTarget !== b.showStickTarget)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, StickTargetPM.type);
        this.onEntityChange = () => {
            if (!this.entity)
                return;
            const showStickTarget = this.entity.showStickTarget;
            const highlightTarget = this.entity.highlightTarget;
            const vm = {
                showStickTarget,
                highlightTarget,
            };
            this.doUpdateView(vm);
        };
        this.entity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
    }
}
exports.defaultStickTargetVM = {
    showStickTarget: false,
    highlightTarget: false,
};
//# sourceMappingURL=StickTargetPM.js.map