import { ConfirmModal } from '@/components/ui/ConfirmModal'
import { useDeletePlant, type Plant } from '@/lib/plants'

/**
 * Confirmation dialog for deleting a custom plant. A plant still used by
 * plantings is refused by the server (409 PLANT_IN_USE); ConfirmModal surfaces
 * that message inline rather than pretending it worked.
 */
export function DeletePlantModal({ plant, onClose }: { plant: Plant; onClose: () => void }) {
  const deletion = useDeletePlant()
  return (
    <ConfirmModal
      title="Delete plant"
      confirmLabel="Delete"
      busyLabel="Deleting…"
      errorFallback="Could not delete the plant."
      onConfirm={() => deletion.mutateAsync(plant.id)}
      onClose={onClose}
    >
      <p className="text-sm text-muted">
        Delete <span className="font-medium text-fg">{plant.name}</span> from your catalog? This can't be
        undone.
      </p>
    </ConfirmModal>
  )
}
