"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClearCorrectObjectIdsUC = void 0;
exports.makeClearCorrectObjectIdsUC = makeClearCorrectObjectIdsUC;
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 ClearCorrectObjectIdsUC extends core_1.AppObjectUC {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ClearCorrectObjectIdsUC.type, appObjects);
    }
}
exports.ClearCorrectObjectIdsUC = ClearCorrectObjectIdsUC;
ClearCorrectObjectIdsUC.type = "ClearCorrectObjectIdsUC";
function makeClearCorrectObjectIdsUC(appObject) {
    return new ClearCorrectObjectIdsUCImp(appObject);
}
class ClearCorrectObjectIdsUCImp extends ClearCorrectObjectIdsUC {
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity_1.UndoRedoEntity.type);
    }
    get objectPick() {
        return this.getCachedSingleton(ObjectPickEntity_1.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();
            (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
            this.undo?.submitAction({
                redoAction: () => {
                    clearedIds.forEach((id) => {
                        objectPick.removeCorrectObjectId(id);
                    });
                    (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
                },
                undoAction: () => {
                    clearedIds.forEach((id) => {
                        objectPick.addCorrectObjectId(id);
                    });
                    (0, DispatchStateChangeUC_1.dispatchStateChange)(this.appObjects);
                },
            });
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ClearCorrectObjectIdsUC.js.map