{"version":3,"file":"DecadeLevelGroup.cjs","names":["DecadeLevel","handleControlKeyDown","LevelsGroup"],"sources":["../../../src/components/DecadeLevelGroup/DecadeLevelGroup.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRef } from 'react';\nimport { BoxProps, ElementProps, factory, Factory, StylesApiProps, useProps } from '@mantine/core';\nimport { DateStringValue } from '../../types';\nimport { handleControlKeyDown } from '../../utils';\nimport { DecadeLevel, DecadeLevelSettings, DecadeLevelStylesNames } from '../DecadeLevel';\nimport { LevelsGroup, LevelsGroupStylesNames } from '../LevelsGroup';\n\nexport type DecadeLevelGroupStylesNames = LevelsGroupStylesNames | DecadeLevelStylesNames;\n\nexport interface DecadeLevelGroupProps\n  extends\n    BoxProps,\n    Omit<StylesApiProps<DecadeLevelGroupFactory>, 'classNames' | 'styles'>,\n    Omit<\n      DecadeLevelSettings,\n      'withPrevious' | 'withNext' | '__onControlKeyDown' | '__getControlRef'\n    >,\n    ElementProps<'div'> {\n  classNames?: Partial<Record<string, string>>;\n  styles?: Partial<Record<string, React.CSSProperties>>;\n  __staticSelector?: string;\n\n  /** Number of columns to display next to each other */\n  numberOfColumns?: number;\n\n  /** Displayed decade */\n  decade: DateStringValue;\n\n  /** Function that returns level control `aria-label` based on year date */\n  levelControlAriaLabel?: ((decade: DateStringValue) => string) | string;\n\n  /** Determines whether the calendar should take the full width of its container @default false */\n  fullWidth?: boolean;\n}\n\nexport type DecadeLevelGroupFactory = Factory<{\n  props: DecadeLevelGroupProps;\n  ref: HTMLDivElement;\n  stylesNames: DecadeLevelGroupStylesNames;\n}>;\n\nconst defaultProps = {\n  numberOfColumns: 1,\n} satisfies Partial<DecadeLevelGroupProps>;\n\nexport const DecadeLevelGroup = factory<DecadeLevelGroupFactory>((_props) => {\n  const props = useProps('DecadeLevelGroup', defaultProps, _props);\n  const {\n    // DecadeLevel settings\n    decade,\n    locale,\n    minDate,\n    maxDate,\n    yearsListFormat,\n    getYearControlProps,\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    nextDisabled,\n    previousDisabled,\n    headerControlsOrder,\n\n    // Other settings\n    classNames,\n    styles,\n    unstyled,\n    __staticSelector,\n    __stopPropagation,\n    numberOfColumns,\n    levelControlAriaLabel,\n    decadeLabelFormat,\n    size,\n    fullWidth,\n    vars,\n    attributes,\n    ...others\n  } = props;\n\n  const controlsRef = useRef<HTMLButtonElement[][][]>([]);\n\n  const decades = Array(numberOfColumns)\n    .fill(0)\n    .map((_, decadeIndex) => {\n      const currentDecade = dayjs(decade)\n        .add(decadeIndex * 10, 'years')\n        .format('YYYY-MM-DD');\n\n      return (\n        <DecadeLevel\n          key={decadeIndex}\n          size={size}\n          yearsListFormat={yearsListFormat}\n          decade={currentDecade}\n          withNext={decadeIndex === numberOfColumns - 1}\n          withPrevious={decadeIndex === 0}\n          decadeLabelFormat={decadeLabelFormat}\n          __onControlClick={__onControlClick}\n          __onControlMouseEnter={__onControlMouseEnter}\n          __onControlKeyDown={(event, payload) =>\n            handleControlKeyDown({\n              levelIndex: decadeIndex,\n              rowIndex: payload.rowIndex,\n              cellIndex: payload.cellIndex,\n              event,\n              controlsRef,\n            })\n          }\n          __getControlRef={(rowIndex, cellIndex, node) => {\n            if (!Array.isArray(controlsRef.current[decadeIndex])) {\n              controlsRef.current[decadeIndex] = [];\n            }\n\n            if (!Array.isArray(controlsRef.current[decadeIndex][rowIndex])) {\n              controlsRef.current[decadeIndex][rowIndex] = [];\n            }\n\n            controlsRef.current[decadeIndex][rowIndex][cellIndex] = node;\n          }}\n          levelControlAriaLabel={\n            typeof levelControlAriaLabel === 'function'\n              ? levelControlAriaLabel(currentDecade)\n              : levelControlAriaLabel\n          }\n          locale={locale}\n          minDate={minDate}\n          maxDate={maxDate}\n          __preventFocus={__preventFocus}\n          __stopPropagation={__stopPropagation}\n          nextIcon={nextIcon}\n          previousIcon={previousIcon}\n          nextLabel={nextLabel}\n          previousLabel={previousLabel}\n          onNext={onNext}\n          onPrevious={onPrevious}\n          nextDisabled={nextDisabled}\n          previousDisabled={previousDisabled}\n          getYearControlProps={getYearControlProps}\n          __staticSelector={__staticSelector || 'DecadeLevelGroup'}\n          classNames={classNames}\n          styles={styles}\n          unstyled={unstyled}\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 || 'DecadeLevelGroup'}\n      size={size}\n      unstyled={unstyled}\n      fullWidth={fullWidth}\n      attributes={attributes}\n      {...others}\n    >\n      {decades}\n    </LevelsGroup>\n  );\n});\n\nDecadeLevelGroup.classes = { ...LevelsGroup.classes, ...DecadeLevel.classes };\nDecadeLevelGroup.displayName = '@mantine/dates/DecadeLevelGroup';\n"],"mappings":";;;;;;;;;;;AA0CA,MAAM,eAAe,EACnB,iBAAiB,EACnB;AAEA,MAAa,oBAAA,GAAA,cAAA,QAAA,EAAqD,WAAW;CAE3E,MAAM,EAEJ,QACA,QACA,SACA,SACA,iBACA,qBACA,kBACA,uBACA,iBAGA,gBACA,UACA,cACA,WACA,eACA,QACA,YACA,cACA,kBACA,qBAGA,YACA,QACA,UACA,kBACA,mBACA,iBACA,uBACA,mBACA,MACA,WACA,MACA,YACA,GAAG,YAAA,GAAA,cAAA,SAAA,CAtCkB,oBAAoB,cAAc,MAuCjD;CAER,MAAM,eAAA,GAAA,MAAA,OAAA,CAA8C,CAAC,CAAC;CAEtD,MAAM,UAAU,MAAM,eAAe,CAAC,CACnC,KAAK,CAAC,CAAC,CACP,KAAK,GAAG,gBAAgB;EACvB,MAAM,iBAAA,GAAA,MAAA,QAAA,CAAsB,MAAM,CAAC,CAChC,IAAI,cAAc,IAAI,OAAO,CAAC,CAC9B,OAAO,YAAY;EAEtB,OACE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