"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelHasLandmarksPM = void 0;
exports.makeModelHasLandmarksPM = makeModelHasLandmarksPM;
const core_1 = require("@vived/core");
const Landmarks_1 = require("../../Landmarks");
const ChannelModel_1 = require("../Entities/ChannelModel");
class ModelHasLandmarksPM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelHasLandmarksPM.type);
    }
}
exports.ModelHasLandmarksPM = ModelHasLandmarksPM;
ModelHasLandmarksPM.type = "ModelHasLandmarksPM";
function makeModelHasLandmarksPM(appObject) {
    return new ModelHasLandmarksPMImp(appObject);
}
class ModelHasLandmarksPMImp extends ModelHasLandmarksPM {
    get channelModel() {
        return this.getCachedLocalComponent(ChannelModel_1.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(Landmarks_1.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