"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelObjectsAreStickablePM = void 0;
exports.makeModelObjectsAreStickablePM = makeModelObjectsAreStickablePM;
const core_1 = require("@vived/core");
const Stickable_1 = require("../../Stick/Entities/Stickable");
const Entities_1 = require("../Entities");
class ModelObjectsAreStickablePM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsAreStickablePM.type);
    }
}
exports.ModelObjectsAreStickablePM = ModelObjectsAreStickablePM;
ModelObjectsAreStickablePM.type = "ModelObjectsAreStickablePM";
function makeModelObjectsAreStickablePM(appObject) {
    return new ModelObjectsAreStickablePMImp(appObject);
}
class ModelObjectsAreStickablePMImp extends ModelObjectsAreStickablePM {
    get channelModel() {
        return this.getCachedLocalComponent(Entities_1.ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, ModelObjectsAreStickablePM.type);
        this.onRepoChange = () => {
            if (!this.channelModel)
                return;
            let stickable = false;
            this.channelModel.modelObjects().forEach((obj) => {
                if (stickable)
                    return;
                if (obj.appObject.getComponent(Stickable_1.StickableEntity.type)
                    ?.canBeStuck) {
                    stickable = true;
                }
            });
            this.doUpdateView(stickable);
        };
        this.dispose = () => {
            super.dispose();
            this.channelModel?.removeChangeObserver(this.onRepoChange);
        };
        if (this.channelModel) {
            this.channelModel.addChangeObserver(this.onRepoChange);
            this.onRepoChange();
        }
        else {
            this.error("App Object does not have a ChannelModelEntity");
        }
    }
}
//# sourceMappingURL=ModelObjectsAreStickablePM.js.map