import { AppObjectPM } from "@vived/core";
import { OverlayColor, OverlayColorEnums } from "../../OverlayColor";
import { ChannelModelEntity } from "../Entities";
export class ModelObjectsHaveOverlayPM extends AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsHaveOverlayPM.type);
    }
}
ModelObjectsHaveOverlayPM.type = "ModelObjectsHaveOverlayPM";
export function makeModelObjectsHaveOverlayPM(appObject) {
    return new ModelObjectsHaveOverlayPMImp(appObject);
}
class ModelObjectsHaveOverlayPMImp extends ModelObjectsHaveOverlayPM {
    get channelModel() {
        return this.getCachedLocalComponent(ChannelModelEntity.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, ModelObjectsHaveOverlayPM.type);
        this.onRepoChange = () => {
            if (!this.channelModel)
                return;
            let haveOverlay = false;
            this.channelModel.modelObjects().forEach((obj) => {
                if (haveOverlay)
                    return;
                const overlay = obj.appObject.getComponent(OverlayColor.type);
                if (overlay && overlay.overlayColor !== OverlayColorEnums.NONE) {
                    haveOverlay = true;
                }
            });
            this.doUpdateView(haveOverlay);
        };
        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=ModelObjectsHaveOverlayPM.js.map