{"version":3,"file":"YearLevelGroup.cjs","names":["factory","useProps","useDirection","useRef","usePendingControlFocus","YearLevel","handleControlKeyDown","LevelsGroup"],"sources":["../../../src/components/YearLevelGroup/YearLevelGroup.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRef } from 'react';\nimport {\n  BoxProps,\n  ElementProps,\n  factory,\n  Factory,\n  StylesApiProps,\n  useDirection,\n  useProps,\n} from '@mantine/core';\nimport { usePendingControlFocus } from '../../hooks';\nimport { DateStringValue } from '../../types';\nimport { ControlEdgeCrossPayload, handleControlKeyDown } from '../../utils';\nimport { LevelsGroup, LevelsGroupStylesNames } from '../LevelsGroup';\nimport { YearLevel, YearLevelSettings, YearLevelStylesNames } from '../YearLevel';\n\nexport type YearLevelGroupStylesNames = YearLevelStylesNames | LevelsGroupStylesNames;\n\nexport interface YearLevelGroupProps\n  extends\n    BoxProps,\n    Omit<YearLevelSettings, 'withPrevious' | 'withNext' | '__onControlKeyDown' | '__getControlRef'>,\n    Omit<StylesApiProps<YearLevelGroupFactory>, 'classNames' | 'styles'>,\n    ElementProps<'div'> {\n  classNames?: Partial<Record<string, string>>;\n  styles?: Partial<Record<string, React.CSSProperties>>;\n  __staticSelector?: string;\n\n  /** Number of columns displayed next to each other */\n  numberOfColumns?: number;\n\n  /** Displayed year */\n  year: DateStringValue;\n\n  /** Function that returns level control `aria-label` */\n  levelControlAriaLabel?: ((year: DateStringValue) => string) | string;\n\n  /** Determines whether the calendar should take the full width of its container @default false */\n  fullWidth?: boolean;\n\n  /** Called when date is changed via native level select */\n  __onDateChange?: (date: DateStringValue) => void;\n\n  /** Disables native level selects when date changes would not take effect */\n  __disableNativeLevelSelect?: boolean;\n}\n\nexport type YearLevelGroupFactory = Factory<{\n  props: YearLevelGroupProps;\n  ref: HTMLDivElement;\n  stylesNames: YearLevelGroupStylesNames;\n}>;\n\nconst defaultProps = {\n  numberOfColumns: 1,\n} satisfies Partial<YearLevelGroupProps>;\n\nexport const YearLevelGroup = factory<YearLevelGroupFactory>((_props) => {\n  const props = useProps('YearLevelGroup', defaultProps, _props);\n  const { dir } = useDirection();\n  const {\n    // YearLevel settings\n    year,\n    locale,\n    minDate,\n    maxDate,\n    monthsListFormat,\n    getMonthControlProps,\n    __onControlClick,\n    __onControlMouseEnter,\n    withCellSpacing,\n\n    // CalendarHeader settings\n    __preventFocus,\n    nextIcon,\n    previousIcon,\n    nextLabel,\n    previousLabel,\n    onNext,\n    onPrevious,\n    onLevelClick,\n    nextDisabled,\n    previousDisabled,\n    hasNextLevel,\n    headerControlsOrder,\n    withNativeLevelSelect,\n    yearsSelectRange,\n\n    // Other settings\n    classNames,\n    styles,\n    unstyled,\n    __staticSelector,\n    __stopPropagation,\n    __onDateChange,\n    __disableNativeLevelSelect,\n    numberOfColumns,\n    levelControlAriaLabel,\n    yearLabelFormat,\n    size,\n    fullWidth,\n    vars,\n    attributes,\n    ...others\n  } = props;\n\n  const controlsRef = useRef<HTMLButtonElement[][][]>([]);\n\n  const requestControlFocus = usePendingControlFocus({ controlsRef, period: year });\n\n  const _previousDisabled =\n    typeof previousDisabled === 'boolean'\n      ? previousDisabled\n      : minDate\n        ? !dayjs(year).startOf('year').isAfter(minDate)\n        : false;\n\n  const _nextDisabled =\n    typeof nextDisabled === 'boolean'\n      ? nextDisabled\n      : maxDate\n        ? !dayjs(year)\n            .add(numberOfColumns - 1, 'years')\n            .endOf('year')\n            .isBefore(maxDate)\n        : false;\n\n  const handleEdgeCross = ({ edge, direction, cellIndex }: ControlEdgeCrossPayload) => {\n    const handler = edge === 'previous' ? onPrevious : onNext;\n    const disabled = edge === 'previous' ? _previousDisabled : _nextDisabled;\n\n    if (!handler || disabled) {\n      return;\n    }\n\n    requestControlFocus({\n      direction,\n      levelIndex: edge === 'previous' ? 'last' : 0,\n      rowIndex: edge === 'previous' ? 'last' : 0,\n      cellIndex:\n        direction === 'up' || direction === 'down' ? cellIndex : edge === 'previous' ? 'last' : 0,\n    });\n    handler();\n  };\n\n  const years = Array(numberOfColumns)\n    .fill(0)\n    .map((_, yearIndex) => {\n      const currentYear = dayjs(year).add(yearIndex, 'years').format('YYYY-MM-DD');\n\n      return (\n        <YearLevel\n          key={yearIndex}\n          size={size}\n          monthsListFormat={monthsListFormat}\n          year={currentYear}\n          withNext={yearIndex === numberOfColumns - 1}\n          withPrevious={yearIndex === 0}\n          yearLabelFormat={yearLabelFormat}\n          __stopPropagation={__stopPropagation}\n          __onControlClick={__onControlClick}\n          __onControlMouseEnter={__onControlMouseEnter}\n          __onControlKeyDown={(event, payload) =>\n            handleControlKeyDown({\n              levelIndex: yearIndex,\n              rowIndex: payload.rowIndex,\n              cellIndex: payload.cellIndex,\n              event,\n              controlsRef,\n              onEdgeCross: handleEdgeCross,\n              dir,\n            })\n          }\n          __getControlRef={(rowIndex, cellIndex, node) => {\n            if (!Array.isArray(controlsRef.current[yearIndex])) {\n              controlsRef.current[yearIndex] = [];\n            }\n\n            if (!Array.isArray(controlsRef.current[yearIndex][rowIndex])) {\n              controlsRef.current[yearIndex][rowIndex] = [];\n            }\n\n            controlsRef.current[yearIndex][rowIndex][cellIndex] = node;\n          }}\n          levelControlAriaLabel={\n            typeof levelControlAriaLabel === 'function'\n              ? levelControlAriaLabel(currentYear)\n              : levelControlAriaLabel\n          }\n          locale={locale}\n          minDate={minDate}\n          maxDate={maxDate}\n          __preventFocus={__preventFocus}\n          nextIcon={nextIcon}\n          previousIcon={previousIcon}\n          nextLabel={nextLabel}\n          previousLabel={previousLabel}\n          onNext={onNext}\n          onPrevious={onPrevious}\n          onLevelClick={onLevelClick}\n          nextDisabled={nextDisabled}\n          previousDisabled={previousDisabled}\n          hasNextLevel={hasNextLevel}\n          withNativeLevelSelect={withNativeLevelSelect}\n          yearsSelectRange={yearsSelectRange}\n          __onDateChange={__onDateChange}\n          __disableNativeLevelSelect={__disableNativeLevelSelect}\n          getMonthControlProps={getMonthControlProps}\n          classNames={classNames}\n          styles={styles}\n          unstyled={unstyled}\n          __staticSelector={__staticSelector || 'YearLevelGroup'}\n          withCellSpacing={withCellSpacing}\n          headerControlsOrder={headerControlsOrder}\n          fullWidth={fullWidth}\n          attributes={attributes}\n        />\n      );\n    });\n\n  return (\n    <LevelsGroup\n      classNames={classNames}\n      styles={styles}\n      __staticSelector={__staticSelector || 'YearLevelGroup'}\n      size={size}\n      unstyled={unstyled}\n      fullWidth={fullWidth}\n      attributes={attributes}\n      {...others}\n    >\n      {years}\n    </LevelsGroup>\n  );\n});\n\nYearLevelGroup.classes = { ...YearLevel.classes, ...LevelsGroup.classes };\nYearLevelGroup.displayName = '@mantine/dates/YearLevelGroup';\n"],"mappings":";;;;;;;;;;;;AAsDA,MAAM,eAAe,EACnB,iBAAiB,EACnB;AAEA,MAAa,kBAAA,GAAiBA,cAAAA,QAAAA,EAAgC,WAAW;CACvE,MAAM,SAAA,GAAQC,cAAAA,SAAAA,CAAS,kBAAkB,cAAc,MAAM;CAC7D,MAAM,EAAE,SAAA,GAAQC,cAAAA,aAAAA,CAAa;CAC7B,MAAM,EAEJ,MACA,QACA,SACA,SACA,kBACA,sBACA,kBACA,uBACA,iBAGA,gBACA,UACA,cACA,WACA,eACA,QACA,YACA,cACA,cACA,kBACA,cACA,qBACA,uBACA,kBAGA,YACA,QACA,UACA,kBACA,mBACA,gBACA,4BACA,iBACA,uBACA,iBACA,MACA,WACA,MACA,YACA,GAAG,WACD;CAEJ,MAAM,eAAA,GAAcC,MAAAA,OAAAA,CAAgC,CAAC,CAAC;CAEtD,MAAM,sBAAsBC,kCAAAA,uBAAuB;EAAE;EAAa,QAAQ;CAAK,CAAC;CAEhF,MAAM,oBACJ,OAAO,qBAAqB,YACxB,mBACA,UACE,EAAA,GAAC,MAAA,QAAA,CAAM,IAAI,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,QAAQ,OAAO,IAC5C;CAER,MAAM,gBACJ,OAAO,iBAAiB,YACpB,eACA,UACE,EAAA,GAAC,MAAA,QAAA,CAAM,IAAI,CAAC,CACT,IAAI,kBAAkB,GA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