import { AppObjectPM } from "@vived/core";
import { Hideable } from "../../Hideable/Entities/Hideable";
import { ChannelModelEntity } from "../Entities/ChannelModel";
export class ModelObjectsAreHiddenPM extends AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsAreHiddenPM.type);
    }
}
ModelObjectsAreHiddenPM.type = "ModelObjectsAreHiddenPM";
export function makeModelObjectsAreHiddenPM(appObject) {
    return new ModelObjectsAreHiddenPMImp(appObject);
}
class ModelObjectsAreHiddenPMImp extends ModelObjectsAreHiddenPM {
    get channelModel() {
        return this.getCachedLocalComponent(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.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