import { differenceInCalendarDays } from 'date-fns'
import { DateRange } from 'react-day-picker'

type Props = {
  calendarRange?: DateRange
}

export const nightsCount = ({ calendarRange }: Props) => {
  if (!calendarRange || !calendarRange.from || !calendarRange.to) {
    return undefined
  }

  const diffDays = differenceInCalendarDays(
    calendarRange.to,
    calendarRange.from
  )

  return diffDays
}
