{"version":3,"file":"YearViewMonth.cjs","names":["getWeekdaysNames","getMonthDays","isSameMonth","UnstyledButton","getWeekNumber","Box","formatDate"],"sources":["../../../src/components/YearView/YearViewMonth.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { Box, GetStylesApi, getThemeColor, UnstyledButton, useMantineTheme } from '@mantine/core';\nimport { useDatesContext } from '@mantine/dates';\nimport { ScheduleLabelsOverride } from '../../labels';\nimport { DateLabelFormat, DateStringValue, DayOfWeek, ScheduleMode } from '../../types';\nimport {\n  formatDate,\n  getMonthDays,\n  getWeekdaysNames,\n  getWeekNumber,\n  isSameMonth,\n} from '../../utils';\nimport { GroupedEvents } from './get-year-view-events/get-year-view-events';\nimport type { YearViewFactory } from './YearView';\n\nexport interface YearViewDayKeydownPayload {\n  weekIndex: number;\n  dayIndex: number;\n  date: string;\n}\n\nexport interface YearViewMonthSettings {\n  /** `dayjs` format for month label  @default 'MMMM' */\n  monthLabelFormat?: DateLabelFormat;\n\n  /** If set, show week numbers */\n  withWeekNumbers?: boolean;\n\n  /** If set, weekdays names are displayed in the first row @default true */\n  withWeekDays?: boolean;\n\n  /** Locale passed down to dayjs, overrides value defined on `DatesProvider` */\n  locale?: string;\n\n  /** Number 0-6, where 0 – Sunday and 6 – Saturday @default 0 */\n  firstDayOfWeek?: DayOfWeek;\n\n  /** `dayjs` format for weekdays names  @default 'd' */\n  weekdayFormat?: DateLabelFormat;\n\n  /** Indices of weekend days, 0-6, where 0 is Sunday and 6 is Saturday. The default value is defined by `DatesProvider`. */\n  weekendDays?: DayOfWeek[];\n\n  /** Props passed down to the week number button */\n  getWeekNumberProps?: (weekStartDate: DateStringValue) => Record<string, any>;\n\n  /** Props passed down to the day button */\n  getDayProps?: (date: DateStringValue) => Record<string, any>;\n\n  /** Called when day is clicked */\n  onDayClick?: (date: DateStringValue, event: React.MouseEvent<HTMLButtonElement>) => void;\n\n  /** Called with first day of the week when week number is clicked */\n  onWeekNumberClick?: (date: DateStringValue, event: React.MouseEvent<HTMLButtonElement>) => void;\n\n  /** Called with the first day of the month when month label is clicked */\n  onMonthClick?: (date: DateStringValue, event: React.MouseEvent<HTMLButtonElement>) => void;\n\n  /** If set, highlights the current day @default true */\n  highlightToday?: boolean;\n\n  /** Labels override for i18n */\n  labels?: ScheduleLabelsOverride;\n\n  /** Interaction mode: 'default' allows all interactions, 'static' disables event interactions */\n  mode?: ScheduleMode;\n\n  /** If true, days from adjacent months are displayed @default true */\n  withOutsideDays?: boolean;\n}\n\nexport interface YearViewMonthProps extends YearViewMonthSettings {\n  /** Month to display, Date object or date string in `YYYY-MM-DD` format */\n  month: Date | string;\n\n  /** `useStyles` return value of `YearView` */\n  getStyles: GetStylesApi<YearViewFactory>;\n\n  /** Events grouped by date */\n  groupedEvents?: GroupedEvents;\n\n  /** Assigns ref of every day based on its position in the month, used for keyboard navigation */\n  __getDayRef?: (weekIndex: number, dayIndex: number, node: HTMLButtonElement) => void;\n\n  /** Called when any keydown event is registered on day, used for keyboard navigation */\n  __onDayKeyDown?: (\n    event: React.KeyboardEvent<HTMLButtonElement>,\n    payload: YearViewDayKeydownPayload\n  ) => void;\n\n  /** Index of the first day of the month in the grid (for determining which day should be in tab order) */\n  firstDayIndex?: { weekIndex: number; dayIndex: number };\n}\n\nexport function YearViewMonth({\n  month,\n  getStyles,\n  monthLabelFormat = 'MMMM',\n  withWeekNumbers,\n  withWeekDays,\n  locale,\n  firstDayOfWeek,\n  weekdayFormat,\n  weekendDays,\n  getDayProps,\n  onDayClick,\n  onWeekNumberClick,\n  onMonthClick,\n  getWeekNumberProps,\n  highlightToday,\n  groupedEvents,\n  mode,\n  withOutsideDays,\n  __getDayRef,\n  __onDayKeyDown,\n  firstDayIndex,\n}: YearViewMonthProps) {\n  const ctx = useDatesContext();\n  const theme = useMantineTheme();\n  const today = dayjs();\n\n  const weekdays = withWeekDays\n    ? getWeekdaysNames({\n        locale: ctx.getLocale(locale),\n        format: weekdayFormat,\n        firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),\n      }).map((day, index) => (\n        <div {...getStyles('yearViewWeekday')} key={index}>\n          {day}\n        </div>\n      ))\n    : null;\n\n  const weeks = getMonthDays({\n    month: dayjs(month).format('YYYY-MM-DD'),\n    firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),\n    consistentWeeks: true,\n  }).map((week, weekIndex) => {\n    const days = week.map((date, dayIndex) => {\n      const outside = !isSameMonth(date, month);\n\n      if (outside && !withOutsideDays) {\n        return <div {...getStyles('yearViewDay')} data-day-placeholder key={date} />;\n      }\n\n      const weekend = ctx.getWeekendDays(weekendDays).includes(dayjs(date).day());\n      const ariaLabel = dayjs(date)\n        .locale(locale || ctx.locale)\n        .format('MMMM D, YYYY');\n\n      const dayProps = getDayProps?.(dayjs(date).format('YYYY-MM-DD')) || {};\n      const isToday = dayjs(date).isSame(today, 'day') && highlightToday;\n      const dayEvents = groupedEvents?.[dayjs(date).format('YYYY-MM-DD')] || [];\n\n      // Determine if this day should be in the tab order\n      // Only the first day of the month (not outside) should be focusable via tab\n      const isFirstDayOfMonth =\n        firstDayIndex &&\n        weekIndex === firstDayIndex.weekIndex &&\n        dayIndex === firstDayIndex.dayIndex;\n      const isInTabOrder = mode !== 'static' && !outside && isFirstDayOfMonth;\n\n      const indicators = dayEvents.slice(0, 3).map((event) => (\n        <div\n          {...getStyles('yearViewDayIndicator', {\n            style: { backgroundColor: getThemeColor(event.color, theme) },\n          })}\n          key={event.id}\n        />\n      ));\n\n      return (\n        <UnstyledButton\n          aria-label={ariaLabel}\n          {...dayProps}\n          {...getStyles('yearViewDay', { className: dayProps.className, style: dayProps.style })}\n          key={date}\n          mod={[{ outside, weekend, today: isToday, static: mode === 'static' }, dayProps.mod]}\n          tabIndex={isInTabOrder ? 0 : -1}\n          ref={(node) => {\n            if (node) {\n              __getDayRef?.(weekIndex, dayIndex, node);\n            }\n          }}\n          onKeyDown={(event) => {\n            dayProps.onKeyDown?.(event);\n            __onDayKeyDown?.(event, { weekIndex, dayIndex, date });\n          }}\n          onClick={\n            mode === 'static'\n              ? undefined\n              : (event) => {\n                  onDayClick?.(dayjs(date).format('YYYY-MM-DD'), event);\n                  dayProps.onClick?.(event);\n                }\n          }\n        >\n          {dayjs(date).format('D')}\n\n          <div {...getStyles('yearViewDayIndicators')}>{indicators}</div>\n        </UnstyledButton>\n      );\n    });\n\n    const weekNumberProps = getWeekNumberProps?.(dayjs(week[0]).format('YYYY-MM-DD')) || {};\n    const weekNumber = getWeekNumber(week);\n\n    return (\n      <div {...getStyles('yearViewWeek')} key={weekIndex}>\n        {withWeekNumbers && (\n          <UnstyledButton\n            key={weekNumber}\n            aria-label={`Week ${weekNumber}`}\n            title={`Week ${weekNumber}`}\n            {...weekNumberProps}\n            onClick={\n              mode === 'static'\n                ? undefined\n                : (event) => {\n                    onWeekNumberClick?.(dayjs(week[0]).format('YYYY-MM-DD'), event);\n                    weekNumberProps.onClick?.(event);\n                  }\n            }\n            mod={{ static: mode === 'static' }}\n            tabIndex={mode === 'static' ? -1 : 0}\n            {...getStyles('yearViewWeekNumber', {\n              className: weekNumberProps.className,\n              style: weekNumberProps.style,\n            })}\n          >\n            {weekNumber}\n          </UnstyledButton>\n        )}\n\n        {days}\n      </div>\n    );\n  });\n\n  return (\n    <Box\n      mod={[\n        {\n          'with-week-numbers': withWeekNumbers,\n          'with-weekdays': withWeekDays,\n          static: mode === 'static',\n        },\n      ]}\n      {...getStyles('yearViewMonth')}\n    >\n      <UnstyledButton\n        onClick={\n          mode === 'static'\n            ? undefined\n            : (event) => onMonthClick?.(dayjs(month).startOf('month').format('YYYY-MM-DD'), event)\n        }\n        mod={{ static: mode === 'static' }}\n        tabIndex={mode === 'static' ? -1 : 0}\n        {...getStyles('yearViewMonthCaption')}\n      >\n        {formatDate({ locale: ctx.getLocale(locale), date: month, format: monthLabelFormat })}\n      </UnstyledButton>\n\n      {weekdays && (\n        <div {...getStyles('yearViewWeekdays')}>\n          {withWeekNumbers && <div {...getStyles('yearViewWeekd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