import { useCallback } from "react";
import EnhancedDynamicModal from "@/record-management/common/EnhancedDynamicModal";
import { useUserRecords } from "../../hooks/useUserRecords";
// import { useIncomingRecords } from "@/components/hooks/useIncomingRecords";
import { useTranslation } from "react-i18next";

interface DeleteRecordProps {
  recordId: string;
  onSuccess: () => void;
  onClose: () => void;
}

const DeleteRecord: React.FC<DeleteRecordProps> = ({
  recordId,
  onSuccess,
  onClose,
}) => {
  const { refetch, deleteRecord } = useUserRecords();
   const { t } = useTranslation();

  const handleDelete = useCallback(async () => {
    if (!recordId) throw new Error("Invalid record ID");

    await deleteRecord(recordId);
    await refetch();


    onSuccess();
  }, [recordId, deleteRecord, refetch, onSuccess]);

  return (
    <EnhancedDynamicModal
      open={true}
      onClose={onClose}
      title={t("userRecord.Delete Record")}
      actionConfig={{
        type: "delete",
        onAction: handleDelete,
        confirmText: t("userRecord.Confirm Delete"),
        confirmVariant: "default",
      }}
    />
  );
};

export default DeleteRecord;
