{"version":3,"file":"YearView.cjs","names":["getYearViewEvents","expandRecurringEvents","getMonthDays","isSameMonth","getMonthsByQuarter","YearViewMonth","Box","ScheduleHeaderBase","toDateString","classes"],"sources":["../../../src/components/YearView/YearView.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRef } from 'react';\nimport {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  DataAttributes,\n  ElementProps,\n  factory,\n  Factory,\n  getRadius,\n  MantineRadius,\n  StylesApiProps,\n  useProps,\n  useResolvedStylesApi,\n  useStyles,\n} from '@mantine/core';\nimport { useDatesContext } from '@mantine/dates';\nimport { DateStringValue, ScheduleEventData, ScheduleMode, ScheduleViewLevel } from '../../types';\nimport {\n  expandRecurringEvents,\n  getMonthDays,\n  getMonthsByQuarter,\n  isSameMonth,\n  toDateString,\n} from '../../utils';\nimport { MonthYearSelectProps } from '../ScheduleHeader/MonthYearSelect/MonthYearSelect';\nimport { CombinedScheduleHeaderStylesNames } from '../ScheduleHeader/ScheduleHeader';\nimport { ScheduleHeaderBase } from '../ScheduleHeader/ScheduleHeaderBase';\nimport { ViewSelectProps } from '../ScheduleHeader/ViewSelect/ViewSelect';\nimport { getYearViewEvents } from './get-year-view-events/get-year-view-events';\nimport { handleYearViewKeyDown, YearViewControlsRef } from './handle-year-view-key-down';\nimport { YearViewMonth, YearViewMonthSettings } from './YearViewMonth';\nimport classes from './YearView.module.css';\n\nexport type YearViewStylesNames =\n  | 'yearView'\n  | 'yearViewMonths'\n  | 'yearViewMonth'\n  | 'yearViewWeekday'\n  | 'yearViewDay'\n  | 'yearViewWeek'\n  | 'yearViewWeekNumber'\n  | 'yearViewWeekdays'\n  | 'yearViewWeekdaysCorner'\n  | 'yearViewMonthCaption'\n  | 'yearViewDayIndicators'\n  | 'yearViewDayIndicator'\n  | CombinedScheduleHeaderStylesNames;\n\nexport type YearViewCssVariables = {\n  yearView: '--year-view-radius';\n};\n\nexport interface YearViewProps\n  extends YearViewMonthSettings, BoxProps, StylesApiProps<YearViewFactory>, ElementProps<'div'> {\n  __staticSelector?: string;\n\n  /** Date to display, Date object or date string in `YYYY-MM-DD 00:00:00` format */\n  date: Date | string;\n\n  /** Called with the new date value when a date is selected */\n  onDateChange?: (value: DateStringValue) => void;\n\n  /** Events to display, must be a stable reference */\n  events?: ScheduleEventData[];\n\n  /** Key of `theme.radius` or any valid CSS value to set `border-radius` @default theme.defaultRadius */\n  radius?: MantineRadius;\n\n  /** If set, highlights the current day @default true */\n  highlightToday?: boolean;\n\n  /** If set, the header is displayed @default true */\n  withHeader?: boolean;\n\n  /** Props passed down to `MonthYearSelect` component in the header */\n  monthYearSelectProps?: Partial<MonthYearSelectProps>;\n\n  /** Called when view level select button is clicked */\n  onViewChange?: (view: ScheduleViewLevel) => void;\n\n  /** Props passed to previous month control */\n  previousControlProps?: React.ComponentProps<'button'> & DataAttributes;\n\n  /** Props passed to next month control */\n  nextControlProps?: React.ComponentProps<'button'> & DataAttributes;\n\n  /** Props passed to today control */\n  todayControlProps?: React.ComponentProps<'button'> & DataAttributes;\n\n  /** Props passed to view level select */\n  viewSelectProps?: Partial<ViewSelectProps> & DataAttributes;\n\n  /** Interaction mode: 'default' allows all interactions, 'static' disables event interactions @default default */\n  mode?: ScheduleMode;\n\n  /** Max number of generated recurring instances per recurring series @default 2000 */\n  recurrenceExpansionLimit?: number;\n}\n\nexport type YearViewFactory = Factory<{\n  props: YearViewProps;\n  ref: HTMLDivElement;\n  stylesNames: YearViewStylesNames;\n  vars: YearViewCssVariables;\n}>;\n\nconst defaultProps = {\n  __staticSelector: 'YearView',\n  monthLabelFormat: 'MMMM',\n  withWeekDays: true,\n  highlightToday: true,\n  withHeader: true,\n  withOutsideDays: true,\n  mode: 'default',\n} satisfies Partial<YearViewProps>;\n\nconst varsResolver = createVarsResolver<YearViewFactory>((_theme, { radius }) => ({\n  yearView: { '--year-view-radius': radius !== undefined ? getRadius(radius) : undefined },\n}));\n\nexport const YearView = factory<YearViewFactory>((_props) => {\n  const props = useProps('YearView', defaultProps, _props);\n  const {\n    // YearView props\n    date,\n    onDateChange,\n    events,\n\n    // YearViewMonth settings\n    monthLabelFormat,\n    withWeekNumbers,\n    withWeekDays,\n    locale,\n    firstDayOfWeek,\n    weekdayFormat,\n    weekendDays,\n    onMonthClick,\n    onDayClick,\n    onWeekNumberClick,\n    getDayProps,\n    getWeekNumberProps,\n    highlightToday,\n    labels,\n    withOutsideDays,\n\n    // ScheduleHeader props\n    withHeader,\n    monthYearSelectProps,\n    onViewChange,\n    previousControlProps,\n    nextControlProps,\n    todayControlProps,\n    viewSelectProps,\n\n    // System props\n    __staticSelector,\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    attributes,\n    radius,\n    mode,\n    recurrenceExpansionLimit,\n    ...others\n  } = props;\n\n  const ctx = useDatesContext();\n\n  const getStyles = useStyles<YearViewFactory>({\n    name: __staticSelector,\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    vars,\n    varsResolver,\n    attributes,\n    rootSelector: 'yearView',\n  });\n\n  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<YearViewFactory>({\n    classNames,\n    styles,\n    props,\n  });\n\n  const stylesApiProps = {\n    classNames: resolvedClassNames,\n    styles: resolvedStyles,\n    attributes,\n    __staticSelector,\n    radius,\n  };\n\n  const expandedEvents = expandRecurringEvents({\n    events,\n    rangeStart: dayjs(date).startOf('year').toDate(),\n    rangeEnd: dayjs(date).endOf('year').toDate(),\n    expansionLimit: recurrenceExpansionLimit,\n  });\n\n  const groupedEvents = getYearViewEvents({ date, events: expandedEvents });\n\n  // [monthIndex][weekIndex][dayIndex]\n  const daysRef = useRef<HTMLButtonElement[][][]>([]) as YearViewControlsRef;\n\n  const getFirstDayIndex = (month: string): { weekIndex: number; dayIndex: number } | undefined => {\n    const weeks = getMonthDays({\n      month: dayjs(month).format('YYYY-MM-DD'),\n      firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),\n      consistentWeeks: true,\n    });\n\n    for (let weekIndex = 0; weekIndex < weeks.length; weekIndex++) {\n      const week = weeks[weekIndex];\n      for (let dayIndex = 0; dayIndex < week.length; dayIndex++) {\n        const dayDate = week[dayIndex];\n        if (isSameMonth(dayDate, month)) {\n          return { weekIndex, dayIndex };\n        }\n      }\n    }\n\n    return undefined;\n  };\n\n  let globalMonthIndex = 0;\n  const months = getMonthsByQuarter(dayjs(date).format('YYYY-MM-DD'))\n    .flat()\n    .map((month) => {\n      const currentMonthIndex = globalMonthIndex;\n      globalMonthIndex++;\n\n      return (\n        <YearViewMonth\n          key={month}\n          month={month}\n          getStyles={getStyles}\n          monthLabelFormat={monthLabelFormat}\n          withWeekNumbers={withWeekNumbers}\n          withWeekDays={withWeekDays}\n          locale={locale}\n          firstDayOfWeek={firstDayOfWeek}\n          weekdayFormat={\n            weekdayFormat ||\n            ((date) => dayjs(date).locale(ctx.getLocale(locale)).format('dd').slice(0, 1))\n          }\n          weekendDays={weekendDays}\n          getDayProps={getDayProps}\n          getWeekNumberProps={getWeekNumberProps}\n          onMonthClick={onMonthClick}\n          onDayClick={onDayClick}\n          onWeekNumberClick={onWeekNumberClick}\n          highlightToday={highlightToday}\n          groupedEvents={groupedEvents}\n          mode={mode}\n          withOutsideDays={withOutsideDays}\n          firstDayIndex={getFirstDayIndex(month)}\n          __getDayRef={(weekIndex, dayIndex, node) => {\n            if (!Array.isArray(daysRef.current[currentMonthIndex])) {\n              daysRef.current[currentMonthIndex] = [];\n            }\n            if (!Array.isArray(daysRef.current[currentMonthIndex][weekIndex])) {\n              daysRef.current[currentMonthIndex][weekIndex] = [];\n            }\n            daysRef.current[currentMonthIndex][weekIndex][dayIndex] = node;\n          }}\n          __onDayKeyDown={(event, payload) => {\n            handleYearViewKeyDown({\n              controlsRef: daysRef,\n              monthIndex: currentMonthIndex,\n              weekIndex: payload.weekIndex,\n              dayIndex: payload.dayIndex,\n              event,\n            });\n          }}\n        />\n      );\n    });\n\n  return (\n    <Box {...getStyles('yearView')} mod={{ static: mode === 'static' }} {...others}>\n      {withHeader && (\n        <ScheduleHeaderBase\n          view=\"year\"\n          navigationHandlers={{\n            previous: () => toDateString(dayjs(date).subtract(1, 'year').startOf('year')),\n            next: () => toDateString(dayjs(date).add(1, 'year').startOf('year')),\n            today: () => toDateString(dayjs()),\n          }}\n          control={{\n            monthYearSelect: {\n              locale,\n              withMonths: false,\n              yearValue: dayjs(date).get('year'),\n              monthValue: dayjs(date).get('month'),\n              onYearChange: (year) =>\n                onDateChange?.(toDateString(dayjs(date).set('year', year).startOf('year'))),\n              ...monthYearSelectProps,\n            },\n          }}\n          labels={labels}\n          onDateChange={onDateChange}\n          onViewChange={onViewChange}\n          previousControlProps={previousControlProps}\n          nextControlProps={nextControlProps}\n          todayControlProps={todayControlProps}\n          viewSelectProps={viewSelectProps}\n          stylesApiProps={stylesApiProps}\n        />\n      )}\n\n      <div {...getStyles('yearViewMonths')}>{months}</div>\n    </Box>\n  );\n});\n\nYearView.displayName = '@mantine/schedule/YearView';\nYearView.classes = classes;\nYearView.varsResolver = varsResolver;\n\nexport namespace YearView {\n  export type Props = YearViewProps;\n  export type Factory = YearViewFactory;\n  export type StylesNames = YearViewStylesNames;\n  export type CssVariables = YearViewCssVariables;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4GA,MAAM,eAAe;CACnB,kBAAkB;CAClB,kBAAkB;CAClB,cAAc;CACd,gBAAgB;CAChB,YAAY;CACZ,iBAAiB;CACjB,MAAM;AACR;AAEA,MAAM,gBAAA,GAAA,cAAA,mBAAA,EAAoD,QAAQ,EAAE,cAAc,EAChF,UAAU,EAAE,sBAAsB,WAAW,KAAA,KAAA,GAAA,cAAA,UAAA,CAAsB,MAAM,IAAI,KAAA,EAAU,EACzF,EAAE;AAEF,MAAa,YAAA,GAAA,cAAA,QAAA,EAAqC,WAAW;CAC3D,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,YAAY,cAAc,MAAM;CACvD,MAAM,EAEJ,MACA,cACA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