import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { ObjectPickEntity } from "../Entities/ObjectPickEntity";
export class ClearCorrectObjectIdsUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(ClearCorrectObjectIdsUC.type, appObjects);
    }
}
ClearCorrectObjectIdsUC.type = "ClearCorrectObjectIdsUC";
export function makeClearCorrectObjectIdsUC(appObject) {
    return new ClearCorrectObjectIdsUCImp(appObject);
}
class ClearCorrectObjectIdsUCImp extends ClearCorrectObjectIdsUC {
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get objectPick() {
        return this.getCachedSingleton(ObjectPickEntity.type);
    }
    constructor(appObject) {
        super(appObject, ClearCorrectObjectIdsUC.type);
        this.clearCorrectObjectIds = () => {
            const objectPick = this.objectPick;
            if (!objectPick)
                return;
            const clearedIds = [...objectPick.correctObjectIds];
            if (clearedIds.length === 0)
                return;
            objectPick.clearCorrectObjectIds();
            dispatchStateChange(this.appObjects);
            this.undo?.submitAction({
                redoAction: () => {
                    clearedIds.forEach((id) => {
                        objectPick.removeCorrectObjectId(id);
                    });
                    dispatchStateChange(this.appObjects);
                },
                undoAction: () => {
                    clearedIds.forEach((id) => {
                        objectPick.addCorrectObjectId(id);
                    });
                    dispatchStateChange(this.appObjects);
                },
            });
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ClearCorrectObjectIdsUC.js.map