"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RemoveCorrectObjectIdUC = void 0;
exports.makeRemoveCorrectObjectIdUC = makeRemoveCorrectObjectIdUC;
const core_1 = require("@vived/core");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const UndoRedoEntity_1 = require("../../UndoRedo/Entities/UndoRedoEntity");
const ObjectPickEntity_1 = require("../Entities/ObjectPickEntity");
class RemoveCorrectObjectIdUC extends core_1.AppObjectUC {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(RemoveCorrectObjectIdUC.type, appObjects);
    }
}
exports.RemoveCorrectObjectIdUC = RemoveCorrectObjectIdUC;
RemoveCorrectObjectIdUC.type = "RemoveCorrectObjectIdUC";
function makeRemoveCorrectObjectIdUC(appObject) {
    return new RemoveCorrectObjectIdUCImp(appObject);
}
class RemoveCorrectObjectIdUCImp extends RemoveCorrectObjectIdUC {
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity_1.UndoRedoEntity.type);
    }
    get objectPick() {
        return this.getCachedSingleton(ObjectPickEntity_1.ObjectPickEntity.type);
    }
    constructor(appObject) {
        super(appObject, RemoveCorrectObjectIdUC.type);
        this.removeCorrectObjectId = (id) => {
            const objectPick = this.objectPick;
            if (!objectPick)
                return;
            objectPick.removeCorrectObjectId(id);
            (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
            this.undo?.submitAction({
                redoAction: () => {
                    objectPick.removeCorrectObjectId(id);
                    (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
                },
                undoAction: () => {
                    objectPick.addCorrectObjectId(id);
                    (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
                },
            });
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=RemoveCorrectObjectIdUC.js.map