{"version":3,"sources":["../../../../src/components/Calendar/utils/formatters.ts"],"sourcesContent":["/**\n * Supported date and time display formats.\n */\nexport type CalendarDateTimeFormat =\n  | 'day'\n  | 'month'\n  | 'shortMonth'\n  | 'year'\n  | 'monthDayYear'\n  | 'monthYear'\n  | 'weekday'\n  | 'shortWeekday';\n\n/**\n * A date and its formatted display value.\n */\nexport type CalendarDateLabelData = {\n  /**\n   * The actual date object.\n   */\n  date: Date;\n  /**\n   * The formatted display value of the date.\n   */\n  formattedDate: string;\n};\n\n/**\n * A year range and its formatted display value.\n */\nexport type CalendarYearRangeLabelData = {\n  /**\n   * The starting year of the range.\n   */\n  fromYear: number;\n  /**\n   * The ending year of the range.\n   */\n  toYear: number;\n  /**\n   * The formatted display value of the year range.\n   */\n  formattedRange: string;\n};\n\n/**\n * Formatters used for calendar display values and accessibility labels.\n */\nexport type CalendarFormatters = {\n  /**\n   * Label for the button that navigates to today.\n   */\n  goToTodayLabel: () => string;\n  /**\n   * Label for the button that closes the calendar.\n   */\n  closeLabel: () => string;\n  /**\n   * Formats a date according to the specified format.\n   */\n  dateTime: (data: { date: Date; format: CalendarDateTimeFormat }) => string;\n\n  /**\n   * Formats the label for the previous month button.\n   */\n  previousMonthLabel: (data: CalendarDateLabelData) => string;\n\n  /**\n   * Formats the label for the next month button.\n   */\n  nextMonthLabel: (data: CalendarDateLabelData) => string;\n\n  /**\n   * Formats the label for the previous year button.\n   */\n  previousYearLabel: (data: CalendarDateLabelData) => string;\n  /**\n   * Formats the label for the next year button.\n   */\n  nextYearLabel: (data: CalendarDateLabelData) => string;\n  /**\n   * Formats the label for the previous year range button.\n   */\n  previousYearRangeLabel: (data: CalendarYearRangeLabelData) => string;\n  /**\n   * Formats the label for the next year range button.\n   */\n  nextYearRangeLabel: (data: CalendarYearRangeLabelData) => string;\n  /**\n   * Formats the label for the month picker header.\n   */\n  monthPickerHeaderLabel: (data: CalendarDateLabelData) => string;\n  /**\n   * Formats the label for the day picker header.\n   */\n  dayPickerHeaderLabel: (data: CalendarDateLabelData) => string;\n  /**\n   * Formats the label for the year range picker header.\n   */\n  yearRangePickerHeaderLabel: (data: CalendarYearRangeLabelData) => string;\n  /**\n   * Formats the label for the week number column header.\n   */\n  weekNumberLabel: (data: { weekNumber: number }) => string;\n\n  /**\n   * Formats the label for the selected date.\n   */\n  selectedDateLabel: (data: CalendarDateLabelData) => string;\n  /**\n   * Formats the label for today's date.\n   */\n  todayDateLabel: (data: CalendarDateLabelData) => string;\n\n  /**\n   * Formats the label for a marked day.\n   */\n  dayMarkedLabel: (data: CalendarDateLabelData) => string;\n};\n\nconst dateTimeFormatters = {\n  day: { day: 'numeric' },\n  month: { month: 'long' },\n  shortMonth: { month: 'short' },\n  year: { year: 'numeric' },\n  monthDayYear: { day: 'numeric', month: 'long', year: 'numeric' },\n  monthYear: { month: 'long', year: 'numeric' },\n  weekday: { weekday: 'long' },\n  shortWeekday: { weekday: 'narrow' },\n} satisfies Record<CalendarDateTimeFormat, Intl.DateTimeFormatOptions>;\n\n/**\n * Creates reusable Intl formatters for every calendar date format. The defaults use en-US; pass the\n * desired locale to localize date labels.\n */\nexport function createCalendarDateTimeFormatter(locales: string | string[] = 'en-US'): CalendarFormatters['dateTime'] {\n  const formatters = Object.fromEntries(\n    Object.entries(dateTimeFormatters).map(([key, fields]) => [\n      key,\n      new Intl.DateTimeFormat(locales, {\n        ...fields,\n        ...({ calendar: 'gregory' } as Intl.DateTimeFormatOptions),\n      }),\n    ]),\n  );\n\n  return data => formatters[data.format].format(data.date);\n}\n\n/**\n * Default calendar formatters.\n */\nexport const calendarFormatters: CalendarFormatters = {\n  goToTodayLabel: () => 'Go to today',\n  closeLabel: () => 'Close',\n  dateTime: createCalendarDateTimeFormatter(),\n  previousMonthLabel: data => `Previous month ${data.formattedDate}`,\n  nextMonthLabel: data => `Next month ${data.formattedDate}`,\n  previousYearLabel: data => `Previous year ${data.formattedDate}`,\n  nextYearLabel: data => `Next year ${data.formattedDate}`,\n  previousYearRangeLabel: data => `Previous year range ${data.formattedRange}`,\n  nextYearRangeLabel: data => `Next year range ${data.formattedRange}`,\n  monthPickerHeaderLabel: data => `${data.formattedDate}, change year`,\n  dayPickerHeaderLabel: data => `${data.formattedDate}, change month`,\n  yearRangePickerHeaderLabel: data => `${data.formattedRange}, change year`,\n  weekNumberLabel: data => `Week number ${data.weekNumber}`,\n  selectedDateLabel: data => `Selected date ${data.formattedDate}`,\n  todayDateLabel: data => `Today's date ${data.formattedDate}`,\n  dayMarkedLabel: data => `${data.formattedDate}, marked`,\n};\n"],"names":["calendarFormatters","createCalendarDateTimeFormatter","dateTimeFormatters","day","month","shortMonth","year","monthDayYear","monthYear","weekday","shortWeekday","locales","formatters","Object","fromEntries","entries","map","key","fields","Intl","DateTimeFormat","calendar","data","format","date","goToTodayLabel","closeLabel","dateTime","previousMonthLabel","formattedDate","nextMonthLabel","previousYearLabel","nextYearLabel","previousYearRangeLabel","formattedRange","nextYearRangeLabel","monthPickerHeaderLabel","dayPickerHeaderLabel","yearRangePickerHeaderLabel","weekNumberLabel","weekNumber","selectedDateLabel","todayDateLabel","dayMarkedLabel"],"mappings":"AAAA;;CAEC;;;;;;;;;;;QAsJYA;eAAAA;;QAjBGC;eAAAA;;;AAfhB,MAAMC,qBAAqB;IACzBC,KAAK;QAAEA,KAAK;IAAU;IACtBC,OAAO;QAAEA,OAAO;IAAO;IACvBC,YAAY;QAAED,OAAO;IAAQ;IAC7BE,MAAM;QAAEA,MAAM;IAAU;IACxBC,cAAc;QAAEJ,KAAK;QAAWC,OAAO;QAAQE,MAAM;IAAU;IAC/DE,WAAW;QAAEJ,OAAO;QAAQE,MAAM;IAAU;IAC5CG,SAAS;QAAEA,SAAS;IAAO;IAC3BC,cAAc;QAAED,SAAS;IAAS;AACpC;AAMO,SAASR,gCAAgCU,UAA6B,OAAO;IAClF,MAAMC,aAAaC,OAAOC,WAAW,CACnCD,OAAOE,OAAO,CAACb,oBAAoBc,GAAG,CAAC,CAAC,CAACC,KAAKC,O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