import { jsx as _jsx } from "react/jsx-runtime";
import { ConfirmModal } from "./ConfirmModal.js";
import { useToast } from "./toast/index.js";
export function DeleteModal({ idToDelete, title, content, setIdToDelete, deleteApi }) {
    const toast = useToast();
    const doDelete = async () => {
        if (!idToDelete) {
            return;
        }
        return deleteApi(idToDelete)
            .then(() => {
            toast({
                title: 'Delete succeeded',
                status: 'success'
            });
        }).catch((err) => {
            toast({
                title: 'Failed to delete',
                description: err.message ?? 'An error occurred while deleting the object',
                status: 'error'
            });
        }).finally(() => {
            setIdToDelete(undefined);
        });
    };
    return (_jsx(ConfirmModal, { title: title, content: content, isOpen: !!idToDelete, onConfirm: doDelete, onCancel: () => { setIdToDelete(undefined); } }));
}
//# sourceMappingURL=DeleteModal.js.map