import { ConfirmDialog } from '@/components/ui/ConfirmDialog'
import { useClearObject } from '@/lib/objects'

/** Confirm clearing every active plop from a bed — a soft remove (the rows are
 *  kept with removed_at, so history and past seasons survive), as one step. */
export function ClearBedDialog({
  objectId,
  objectName,
  plopCount,
  gardenId,
  onClose,
}: {
  objectId: number
  objectName: string
  plopCount: number
  gardenId: number
  onClose: () => void
}) {
  const clear = useClearObject(gardenId)
  return (
    <ConfirmDialog
      title={`Clear ${objectName}?`}
      confirmLabel="Clear it"
      busyLabel="Clearing…"
      confirmDisabled={plopCount === 0}
      errorFallback="Could not clear the bed."
      onConfirm={() => clear.mutateAsync(objectId)}
      onClose={onClose}
    >
      Pull all <span className="font-semibold text-text">{plopCount}</span> {plopCount === 1 ? 'planting' : 'plantings'} out
      of <span className="font-semibold text-text">{objectName}</span>. They stay in the journal and past seasons, and this
      is one undoable step.
    </ConfirmDialog>
  )
}
