"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelObjectsAreHiddenPM = void 0;
exports.makeModelObjectsAreHiddenPM = makeModelObjectsAreHiddenPM;
const core_1 = require("@vived/core");
const Hideable_1 = require("../../Hideable/Entities/Hideable");
const ChannelModel_1 = require("../Entities/ChannelModel");
class ModelObjectsAreHiddenPM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsAreHiddenPM.type);
    }
}
exports.ModelObjectsAreHiddenPM = ModelObjectsAreHiddenPM;
ModelObjectsAreHiddenPM.type = "ModelObjectsAreHiddenPM";
function makeModelObjectsAreHiddenPM(appObject) {
    return new ModelObjectsAreHiddenPMImp(appObject);
}
class ModelObjectsAreHiddenPMImp extends ModelObjectsAreHiddenPM {
    get channelModel() {
        return this.getCachedLocalComponent(ChannelModel_1.ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, ModelObjectsAreHiddenPM.type);
        this.onRepoChange = () => {
            if (!this.channelModel)
                return;
            let hidden = false;
            this.channelModel.modelObjects().forEach((obj) => {
                if (hidden)
                    return;
                if (obj.appObject.getComponent(Hideable_1.Hideable.type)?.isHidden) {
                    hidden = true;
                }
            });
            this.doUpdateView(hidden);
        };
        this.dispose = () => {
            super.dispose();
            this.channelModel?.removeChangeObserver(this.onRepoChange);
            this.channelModel?.removeOnDisposeObserver(this.dispose);
        };
        if (this.channelModel) {
            this.channelModel.addChangeObserver(this.onRepoChange);
            this.channelModel.addOnDisposeObserver(() => this.dispose());
            this.onRepoChange();
        }
        else {
            this.error("App Object does not have a ChannelModelEntity");
        }
    }
}
//# sourceMappingURL=ModelObjectsAreHiddenPM.js.map