import { AppObjectPM } from "@vived/core";
import { StickableEntity } from "../../Stick/Entities/Stickable";
import { ChannelModelEntity } from "../Entities";
export class ModelObjectsAreStickablePM extends AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsAreStickablePM.type);
    }
}
ModelObjectsAreStickablePM.type = "ModelObjectsAreStickablePM";
export function makeModelObjectsAreStickablePM(appObject) {
    return new ModelObjectsAreStickablePMImp(appObject);
}
class ModelObjectsAreStickablePMImp extends ModelObjectsAreStickablePM {
    get channelModel() {
        return this.getCachedLocalComponent(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(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