import { ConfirmModal } from '@/components/ui/ConfirmModal'
import { formatQuantity, useDeleteSeedLot, type SeedLot } from '@/lib/seedLots'

/**
 * Retire a lot. Worth confirming because it's the one place cost and germination
 * data lives — and worth saying plainly that the plantings survive it, since
 * "will this wipe my garden" is the reasonable fear.
 */
export function DeleteSeedLotModal({ lot, onClose }: { lot: SeedLot; onClose: () => void }) {
  const del = useDeleteSeedLot()
  return (
    <ConfirmModal
      title="Retire this seed lot?"
      confirmLabel="Retire lot"
      busyLabel="Retiring…"
      errorFallback="Could not retire the lot."
      onConfirm={() => del.mutateAsync(lot.id)}
      onClose={onClose}
    >
      <p className="text-sm text-fg">
        {formatQuantity(lot.quantity)} {lot.unit}
        {lot.vendor ? ` from ${lot.vendor}` : ''}
        {lot.packedForYear != null ? `, packed for ${lot.packedForYear}` : ''}.
      </p>
      <p className="text-sm text-muted">
        Anything planted from it stays exactly where it is — it just stops being attributed to this purchase.
      </p>
    </ConfirmModal>
  )
}
