import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { LabelDropRepo } from "../Entities/LabelDropRepo";
import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
export class DeleteLabelDropUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(DeleteLabelDropUC.type, appObjects);
    }
}
DeleteLabelDropUC.type = "DeleteLabelDropUC";
export function makeDeleteLabelDropUC(appObject) {
    return new DeleteLabelDropUCImp(appObject);
}
class DeleteLabelDropUCImp extends DeleteLabelDropUC {
    get repo() {
        return this.getCachedSingleton(LabelDropRepo.type);
    }
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(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