import { AppObjectUC } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { OverlayColor, OverlayColorEnums, } from "../../OverlayColor/Entities/OverlayColor";
import { ChannelModelEntity } from "../Entities";
import { ClearAllColorOverlayUndoRedo } from "./ClearAllColorOverlayUndoRedo";
export class ClearModelObjectOverlaysUC extends AppObjectUC {
    static get(id, appObjects) {
        return appObjects
            .get(id)
            ?.getComponent(ClearModelObjectOverlaysUC.type);
    }
}
ClearModelObjectOverlaysUC.type = "ClearModelObjectOverlaysUC";
export function makeClearModelObjectOverlaysUC(appObject) {
    return new ClearModelObjectOverlaysUCImp(appObject);
}
class ClearModelObjectOverlaysUCImp extends ClearModelObjectOverlaysUC {
    get model() {
        return this.getCachedLocalComponent(ChannelModelEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(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.get(modelObject.appObject);
                if (overlay && overlay.overlayColor !== OverlayColorEnums.NONE) {
                    undoRedoMap.set(modelObject.id, overlay.overlayColor);
                    overlay.overlayColor = OverlayColorEnums.NONE;
                    somethingHadOverlay = true;
                }
            });
            if (!somethingHadOverlay)
                return;
            if (this.dispatchStateChange) {
                this.dispatchStateChange();
            }
            new ClearAllColorOverlayUndoRedo(undoRedoMap, this.appObjects);
        };
    }
}
//# sourceMappingURL=ClearModelObjectOverlaysUC.js.map