"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteLabelDropUC = void 0;
exports.makeDeleteLabelDropUC = makeDeleteLabelDropUC;
const core_1 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const DispatchStateChangeUC_1 = require("../../Dispatcher/UC/DispatchStateChangeUC");
const UndoRedoEntity_1 = require("../../UndoRedo/Entities/UndoRedoEntity");
class DeleteLabelDropUC extends core_1.AppObjectUC {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(DeleteLabelDropUC.type, appObjects);
    }
}
exports.DeleteLabelDropUC = DeleteLabelDropUC;
DeleteLabelDropUC.type = "DeleteLabelDropUC";
function makeDeleteLabelDropUC(appObject) {
    return new DeleteLabelDropUCImp(appObject);
}
class DeleteLabelDropUCImp extends DeleteLabelDropUC {
    get repo() {
        return this.getCachedSingleton(LabelDropRepo_1.LabelDropRepo.type);
    }
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity_1.UndoRedoEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(DispatchStateChangeUC_1.DispatchStateChangeUC.type)?.doDispatch;
    }
    deleteLabelDrop(id) {
        const repo = this.repo;
        const dispatchStateChange = this.dispatchStateChange;
        if (!repo || !dispatchStateChange) {
            this.error("Missing Component");
            return;
        }
        const data = repo.getForAppObject(id)?.data;
        if (!data) {
            this.appObjects.submitWarning("DeleteLabelDropUC", `Unable to find label drop for id: ${id}`);
            return;
        }
        repo.deleteItem(id);
        this.undo?.submitAction({
            undoAction: () => {
                repo.makeLabelDropItem(id).data = data;
                dispatchStateChange();
            },
            redoAction: () => {
                repo.deleteItem(id);
                dispatchStateChange();
            },
        });
        repo.editingID = undefined;
        dispatchStateChange();
    }
    constructor(appObject) {
        super(appObject, DeleteLabelDropUC.type);
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=DeleteLabelDropUC.js.map