import { addDays } from 'date-fns'

import { DisableCalendarDates } from '../CalendarTypes'

export const disabledDatesByPage = ({
  newDisableCalendarDates,
  selectedPath,
  today,
}: {
  newDisableCalendarDates?: DisableCalendarDates
  selectedPath?: string
  today: Date
}) => {
  const daysToOffsetCalendar =
    newDisableCalendarDates?.disabledDatesByPage && selectedPath
      ? [
          newDisableCalendarDates?.disabledDatesByPage?.find(
            (item) => selectedPath === item.page
          ),
        ]
      : []

  return daysToOffsetCalendar.length
    ? [
        {
          from: addDays(today, daysToOffsetCalendar[0]?.offset ?? -1),
          to: addDays(today, -100),
        },
      ]
    : []
}
