import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { dispatchStateChange } from "../../Dispatcher";
import { UndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { ObjectPickEntity } from "../Entities/ObjectPickEntity";
export class AddCorrectObjectIdUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(AddCorrectObjectIdUC.type, appObjects);
    }
}
AddCorrectObjectIdUC.type = "AddCorrectObjectIdUC";
export function makeAddCorrectObjectIdUC(appObject) {
    return new AddCorrectObjectIdUCImp(appObject);
}
class AddCorrectObjectIdUCImp extends AddCorrectObjectIdUC {
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get objectPick() {
        return this.getCachedSingleton(ObjectPickEntity.type);
    }
    constructor(appObject) {
        super(appObject, AddCorrectObjectIdUC.type);
        this.addCorrectObjectId = (id) => {
            if (!this.objectPick)
                return;
            this.objectPick.addCorrectObjectId(id);
            dispatchStateChange(this.appObjects);
            const objectPick = this.objectPick;
            this.undo?.submitAction({
                redoAction: () => {
                    objectPick.addCorrectObjectId(id);
                    dispatchStateChange(this.appObjects);
                },
                undoAction: () => {
                    objectPick.removeCorrectObjectId(id);
                    dispatchStateChange(this.appObjects);
                },
            });
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=AddCorrectObjectIdUC.js.map