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