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CAAC,EAAE,CAAC,KAAK;IAE9B;IAEA,OAAO,gBAAgB,MAAM,CAAC,aAAa;QAAC,WAAW;QAAY,SAAS;IAAQ;AACtF","sources":["packages/react-aria/src/calendar/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n  CalendarDate,\n  DateFormatter,\n  endOfMonth,\n  isSameDay,\n  startOfMonth\n} from '@internationalized/date';\nimport {CalendarSelectionMode, CalendarState} from 'react-stately/useCalendarState';\n// @ts-ignore\nimport intlMessages from '../../intl/calendar/*.json';\nimport type {LocalizedStringFormatter} from '@internationalized/string';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {useDateFormatter} from '../i18n/useDateFormatter';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useMemo} from 'react';\n\ninterface HookData {\n  ariaLabel?: string;\n  ariaLabelledBy?: string;\n  errorMessageId: string;\n  selectedDateDescription: string;\n}\n\nexport const hookData: WeakMap<\n  CalendarState<CalendarSelectionMode> | RangeCalendarState,\n  HookData\n> = new WeakMap<CalendarState<CalendarSelectionMode> | RangeCalendarState, HookData>();\n\nexport function getEraFormat(date: CalendarDate | undefined): 'short' | undefined {\n  return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;\n}\n\nexport function useSelectedDateDescription(\n  state: CalendarState<'single' | 'multiple'> | RangeCalendarState\n): string {\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n\n  let start: CalendarDate | undefined, end: CalendarDate | undefined;\n  if ('highlightedRange' in state) {\n    ({start, end} = state.highlightedRange || {});\n  } else {\n    start = Array.isArray(state.value) ? state.value[0] : (state.value ?? undefined);\n    end = Array.isArray(state.value) ? state.value.at(-1) : (state.value ?? undefined);\n  }\n\n  let dateFormatter = useDateFormatter({\n    weekday: 'long',\n    month: 'long',\n    year: 'numeric',\n    day: 'numeric',\n    era: getEraFormat(start) || getEraFormat(end),\n    timeZone: state.timeZone\n  });\n\n  let {locale} = useLocale();\n  let listFormatter = useMemo(() => new Intl.ListFormat(locale), [locale]);\n\n  let anchorDate = 'anchorDate' in state ? state.anchorDate : null;\n  return useMemo(() => {\n    // No message if currently selecting a range, or there is nothing highlighted.\n    if (!anchorDate && start && end) {\n      // Use a single date message if the start and end dates are the same day,\n      // otherwise include both dates.\n      if (isSameDay(start, end)) {\n        let date = dateFormatter.format(start.toDate(state.timeZone));\n        return stringFormatter.format('selectedDateDescription', {date});\n      } else if ('highlightedRange' in state) {\n        let dateRange = formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);\n        return stringFormatter.format('selectedRangeDescription', {dateRange});\n      } else if (Array.isArray(state.value)) {\n        let dates = state.value.map(date => dateFormatter.format(date.toDate(state.timeZone)));\n        let formatted = listFormatter.format(dates);\n        return stringFormatter.format('selectedDateDescription', {date: formatted});\n      }\n    }\n    return '';\n  }, [start, end, anchorDate, state, stringFormatter, dateFormatter, listFormatter]);\n}\n\nexport function useVisibleRangeDescription(\n  startDate: CalendarDate,\n  endDate: CalendarDate,\n  timeZone: string,\n  isAria: boolean\n): string {\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n  let era: any = getEraFormat(startDate) || getEraFormat(endDate);\n  let monthFormatter = useDateFormatter({\n    month: 'long',\n    year: 'numeric',\n    era,\n    calendar: startDate.calendar.identifier,\n    timeZone\n  });\n\n  let dateFormatter = useDateFormatter({\n    month: 'long',\n    year: 'numeric',\n    day: 'numeric',\n    era,\n    calendar: startDate.calendar.identifier,\n    timeZone\n  });\n\n  return useMemo(() => {\n    // Special case for month granularity. Format as a single month if only a\n    // single month is visible, otherwise format as a range of months.\n    if (isSameDay(startDate, startOfMonth(startDate))) {\n      let startMonth = startDate;\n      let endMonth = endDate;\n      if (startDate.calendar.getFormattableMonth) {\n        startMonth = startDate.calendar.getFormattableMonth(startDate);\n      }\n      if (endDate.calendar.getFormattableMonth) {\n        endMonth = endDate.calendar.getFormattableMonth(endDate);\n      }\n\n      if (isSameDay(endDate, endOfMonth(startDate))) {\n        return monthFormatter.format(startMonth.toDate(timeZone));\n      } else if (isSameDay(endDate, endOfMonth(endDate))) {\n        return isAria\n          ? formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone)\n          : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));\n      }\n    }\n\n    return isAria\n      ? formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone)\n      : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));\n  }, [startDate, endDate, monthFormatter, dateFormatter, stringFormatter, timeZone, isAria]);\n}\n\nfunction formatRange(\n  dateFormatter: DateFormatter,\n  stringFormatter: LocalizedStringFormatter,\n  start: CalendarDate,\n  end: CalendarDate,\n  timeZone: string\n) {\n  let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));\n\n  // Find the separator between the start and end date. This is determined\n  // by finding the last shared literal before the end range.\n  let separatorIndex = -1;\n  for (let i = 0; i < parts.length; i++) {\n    let part = parts[i];\n    if (part.source === 'shared' && part.type === 'literal') {\n      separatorIndex = i;\n    } else if (part.source === 'endRange') {\n      break;\n    }\n  }\n\n  // Now we can combine the parts into start and end strings.\n  let startValue = '';\n  let endValue = '';\n  for (let i = 0; i < parts.length; i++) {\n    if (i < separatorIndex) {\n      startValue += parts[i].value;\n    } else if (i > separatorIndex) {\n      endValue += parts[i].value;\n    }\n  }\n\n  return stringFormatter.format('dateRange', {startDate: startValue, endDate: endValue});\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}