"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClearModelObjectOverlaysUC = void 0;
exports.makeClearModelObjectOverlaysUC = makeClearModelObjectOverlaysUC;
const core_1 = require("@vived/core");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const OverlayColor_1 = require("../../OverlayColor/Entities/OverlayColor");
const Entities_1 = require("../Entities");
const ClearAllColorOverlayUndoRedo_1 = require("./ClearAllColorOverlayUndoRedo");
class ClearModelObjectOverlaysUC extends core_1.AppObjectUC {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(ClearModelObjectOverlaysUC.type);
    }
}
exports.ClearModelObjectOverlaysUC = ClearModelObjectOverlaysUC;
ClearModelObjectOverlaysUC.type = "ClearModelObjectOverlaysUC";
function makeClearModelObjectOverlaysUC(appObject) {
    return new ClearModelObjectOverlaysUCImp(appObject);
}
class ClearModelObjectOverlaysUCImp extends ClearModelObjectOverlaysUC {
    get model() {
        return this.getCachedLocalComponent(Entities_1.ChannelModelEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(DispatchStateChangeUC_1.DispatchStateChangeUC.type)?.doDispatch;
    }
    constructor(appObject) {
        super(appObject, ClearModelObjectOverlaysUC.type);
        this.clearOverlays = () => {
            if (!this.model)
                return;
            const undoRedoMap = new Map();
            let somethingHadOverlay = false;
            this.model.modelObjects().forEach((modelObject) => {
                const overlay = OverlayColor_1.OverlayColor.get(modelObject.appObject);
                if (overlay && overlay.overlayColor !== OverlayColor_1.OverlayColorEnums.NONE) {
                    undoRedoMap.set(modelObject.id, overlay.overlayColor);
                    overlay.overlayColor = OverlayColor_1.OverlayColorEnums.NONE;
                    somethingHadOverlay = true;
                }
            });
            if (!somethingHadOverlay)
                return;
            if (this.dispatchStateChange) {
                this.dispatchStateChange();
            }
            new ClearAllColorOverlayUndoRedo_1.ClearAllColorOverlayUndoRedo(undoRedoMap, this.appObjects);
        };
    }
}
//# sourceMappingURL=ClearModelObjectOverlaysUC.js.map