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. 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 {CalendarDate} from '@internationalized/date';\nimport {CalendarSelectionMode, CalendarState} from 'react-stately/useCalendarState';\nimport {Key} from '@react-types/shared';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {useDateFormatter} from '../i18n/useDateFormatter';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useMemo} from 'react';\n\nexport interface CalendarMonthPickerProps {\n /**\n * The format of the month.\n */\n format?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';\n}\n\nexport interface CalendarMonthPickerAria {\n 'aria-label': string;\n value: Key;\n onChange: (key: Key | null) => void;\n items: CalendarMonthPickerItem[];\n}\n\nexport interface CalendarMonthPickerItem {\n id: number;\n date: CalendarDate;\n formatted: string;\n}\n\nexport function useCalendarMonthPicker(\n props: CalendarMonthPickerProps,\n state: CalendarState<CalendarSelectionMode> | RangeCalendarState\n): CalendarMonthPickerAria {\n let formatter = useDateFormatter({\n month: props.format || 'short',\n calendar: state.focusedDate.calendar.identifier,\n timeZone: state.timeZone\n });\n\n // Format the name of each month in the year according to the\n // current locale and calendar system. Note that in some calendar\n // systems, such as the Hebrew, the number of months may differ\n // between years.\n let months: CalendarMonthPickerItem[] = [];\n let numMonths = state.focusedDate.calendar.getMonthsInYear(state.focusedDate);\n for (let i = 1; i <= numMonths; i++) {\n let date = state.focusedDate.set({month: i});\n // Calendars like the 4-5-4 fiscal calendar use getFormattableMonth to map\n // their internal month back to the Gregorian month that should be displayed.\n let displayDate = date.calendar.getFormattableMonth\n ? date.calendar.getFormattableMonth(date)\n : date;\n months.push({\n id: i,\n date,\n formatted: formatter.format(displayDate.toDate(state.timeZone))\n });\n }\n\n let {locale} = useLocale();\n let ariaLabel = useMemo(\n () => new Intl.DisplayNames(locale, {type: 'dateTimeField'}).of('month')!,\n [locale]\n );\n\n return {\n 'aria-label': ariaLabel,\n value: state.focusedDate.month,\n onChange: key => {\n if (key != null) {\n state.setFocusedDate(months[Number(key) - 1].date);\n }\n },\n items: months\n };\n}\n"],"names":[],"version":3,"file":"useCalendarMonthPicker.mjs.map"}