import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher/UC/DispatchStateChangeUC";
import { UndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { LabelDropRepo } from "../Entities/LabelDropRepo";
export class DeleteAllLabelDropUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(DeleteAllLabelDropUC.type, appObjects);
    }
}
DeleteAllLabelDropUC.type = "DeleteAllLabelDropUC";
export function makeDeleteAllLabelDropUC(appObject) {
    return new DeleteAllLabelDropUCImp(appObject);
}
class DeleteAllLabelDropUCImp extends DeleteAllLabelDropUC {
    get repo() {
        return this.getCachedSingleton(LabelDropRepo.type);
    }
    get undo() {
        return this.getCachedSingleton(UndoRedoEntity.type);
    }
    get dispatchStateChange() {
        return this.getCachedSingleton(DispatchStateChangeUC.type)?.doDispatch;
    }
    delete() {
        const repo = this.repo;
        const dispatchStateChange = this.dispatchStateChange;
        if (!repo || !dispatchStateChange) {
            this.error("Missing Component");
            return;
        }
        const allData = repo.getAll().map((item) => item.data);
        if (allData.length === 0)
            return;
        repo.deleteAllItems();
        this.undo?.submitAction({
            undoAction: () => {
                allData.forEach((data) => {
                    repo.makeLabelDropItem(data.id).data = data;
                });
                dispatchStateChange();
            },
            redoAction: () => {
                allData.forEach((data) => {
                    repo.deleteItem(data.id);
                });
                dispatchStateChange();
            },
        });
        dispatchStateChange();
    }
    constructor(appObject) {
        super(appObject, DeleteAllLabelDropUC.type);
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=DeleteAllLabelDropUC.js.map