import { AppObjectPM } from "@vived/core";
import { LandmarkRepo } from "../../Landmarks";
import { ChannelModelEntity } from "../Entities/ChannelModel";
export class ModelHasLandmarksPM extends AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelHasLandmarksPM.type);
    }
}
ModelHasLandmarksPM.type = "ModelHasLandmarksPM";
export function makeModelHasLandmarksPM(appObject) {
    return new ModelHasLandmarksPMImp(appObject);
}
class ModelHasLandmarksPMImp extends ModelHasLandmarksPM {
    get channelModel() {
        return this.getCachedLocalComponent(ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, ModelHasLandmarksPM.type);
        this.onRepoChange = () => {
            if (!this.channelModel)
                return;
            let hasLandmark = false;
            this.channelModel.modelObjects().forEach((obj) => {
                if (hasLandmark)
                    return;
                const repo = obj.appObject.getComponent(LandmarkRepo.type);
                if (repo && repo.getAll().length > 0) {
                    hasLandmark = true;
                }
            });
            this.doUpdateView(hasLandmark);
        };
        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=ModelHasLandmarksPM.js.map