"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelObjectsHaveOverlayPM = void 0;
exports.makeModelObjectsHaveOverlayPM = makeModelObjectsHaveOverlayPM;
const core_1 = require("@vived/core");
const OverlayColor_1 = require("../../OverlayColor");
const Entities_1 = require("../Entities");
class ModelObjectsHaveOverlayPM extends core_1.AppObjectPM {
    static get(appObjID, appObjects) {
        return appObjects
            .get(appObjID)
            ?.getComponent(ModelObjectsHaveOverlayPM.type);
    }
}
exports.ModelObjectsHaveOverlayPM = ModelObjectsHaveOverlayPM;
ModelObjectsHaveOverlayPM.type = "ModelObjectsHaveOverlayPM";
function makeModelObjectsHaveOverlayPM(appObject) {
    return new ModelObjectsHaveOverlayPMImp(appObject);
}
class ModelObjectsHaveOverlayPMImp extends ModelObjectsHaveOverlayPM {
    get channelModel() {
        return this.getCachedLocalComponent(Entities_1.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_1.OverlayColor.type);
                if (overlay && overlay.overlayColor !== OverlayColor_1.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