{"version":3,"file":"MonthYearSelect.cjs","names":["useScheduleHeaderLabels","getYearsList","UnstyledButton","getLabel","getMonthsList","Popover","HeaderControl","formatDate","classes"],"sources":["../../../../src/components/ScheduleHeader/MonthYearSelect/MonthYearSelect.tsx"],"sourcesContent":["import {\n  BoxProps,\n  createScopedKeydownHandler,\n  createVarsResolver,\n  DataAttributes,\n  ElementProps,\n  factory,\n  Factory,\n  getRadius,\n  MantineRadius,\n  Popover,\n  PopoverProps,\n  StylesApiProps,\n  UnstyledButton,\n  useProps,\n  useStyles,\n} from '@mantine/core';\nimport { useDatesContext } from '@mantine/dates';\nimport { useDisclosure } from '@mantine/hooks';\nimport { getLabel, ScheduleLabelsOverride } from '../../../labels';\nimport { DateLabelFormat } from '../../../types';\nimport { formatDate, getMonthsList, getYearsList } from '../../../utils';\nimport { HeaderControl } from '../HeaderControl/HeaderControl';\nimport { useScheduleHeaderLabels } from '../ScheduleHeaderContext';\nimport classes from './MonthYearSelect.module.css';\n\nexport type MonthYearSelectStylesNames =\n  | 'monthYearSelectTarget'\n  | 'monthYearSelectDropdown'\n  | 'monthYearSelectControl'\n  | 'monthYearSelectList'\n  | 'monthYearSelectLabel';\n\nexport type MonthYearSelectCssVariables = {\n  monthYearSelectDropdown: '--control-radius';\n};\n\nexport interface MonthYearSelectProps\n  extends BoxProps, StylesApiProps<MonthYearSelectFactory>, ElementProps<'button'> {\n  __staticSelector?: string;\n\n  /** Locale passed down to dayjs, overrides value defined on `DatesProvider` */\n  locale?: string;\n\n  /** Props passed down to the underlying Popover component */\n  popoverProps?: PopoverProps;\n\n  /** Start year for year selection, calculated from the current date by default */\n  startYear?: number;\n\n  /** End year for year selection, calculated from the current date by default */\n  endYear?: number;\n\n  /** Current year value (e.g. `2025`) */\n  yearValue?: number;\n\n  /** Current month value (0-11) */\n  monthValue?: number;\n\n  /** Called with year value (e.g. `2025`) when year is selected in the dropdown */\n  onYearChange?: (year: number) => void;\n\n  /** Called with month value (0-11) when month is selected in the dropdown */\n  onMonthChange?: (month: number) => void;\n\n  /** Format for displaying months in the dropdown, dayjs format or custom formatter function @default 'MMM' */\n  monthsListFormat?: DateLabelFormat;\n\n  /** Format for displaying month label in the control, dayjs format @default 'MMMM YYYY' */\n  labelFormat?: DateLabelFormat;\n\n  /** Key of `theme.radius` or any valid CSS value to set `border-radius` @default theme.defaultRadius */\n  radius?: MantineRadius;\n\n  /** Props passed down to year controls */\n  getYearControlProps?: (year: number) => React.ComponentProps<'button'> & DataAttributes;\n\n  /** Props passed down to month controls */\n  getMonthControlProps?: (month: number) => React.ComponentProps<'button'> & DataAttributes;\n\n  /** If set to false, months are not displayed in the dropdown @default true */\n  withMonths?: boolean;\n\n  /** Labels override */\n  labels?: ScheduleLabelsOverride;\n}\n\nexport type MonthYearSelectFactory = Factory<{\n  props: MonthYearSelectProps;\n  ref: HTMLButtonElement;\n  stylesNames: MonthYearSelectStylesNames;\n  vars: MonthYearSelectCssVariables;\n}>;\n\nconst defaultProps = {\n  __staticSelector: 'MonthYearSelect',\n  withMonths: true,\n} satisfies Partial<MonthYearSelectProps>;\n\nconst varsResolver = createVarsResolver<MonthYearSelectFactory>((_theme, { radius }) => ({\n  monthYearSelectDropdown: {\n    '--control-radius': radius === undefined ? undefined : getRadius(radius),\n  },\n}));\n\nexport const MonthYearSelect = factory<MonthYearSelectFactory>((_props) => {\n  const props = useProps('MonthYearSelect', defaultProps, _props);\n  const {\n    __staticSelector,\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    attributes,\n    popoverProps,\n    startYear,\n    endYear,\n    onYearChange,\n    onMonthChange,\n    locale,\n    monthsListFormat,\n    monthValue,\n    yearValue,\n    labelFormat,\n    radius,\n    getMonthControlProps,\n    getYearControlProps,\n    withMonths,\n    id,\n    labels,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<MonthYearSelectFactory>({\n    name: __staticSelector,\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    varsResolver,\n    rootSelector: 'monthYearSelectTarget',\n  });\n\n  const [opened, handlers] = useDisclosure(false);\n  const resolvedLabels = useScheduleHeaderLabels(labels);\n\n  const today = new Date();\n  const ctx = useDatesContext();\n  const _startYear = startYear ?? today.getFullYear() - 5;\n  const _endYear = endYear ?? today.getFullYear() + 5;\n  const hasActiveYear = yearValue !== undefined && yearValue >= _startYear && yearValue <= _endYear;\n\n  const years = getYearsList({ startYear: _startYear, endYear: _endYear }).map((year, index) => {\n    const controlProps = getYearControlProps?.(year);\n    return (\n      <UnstyledButton\n        key={year}\n        onClick={() => {\n          onYearChange?.(year);\n          if (!withMonths) {\n            handlers.close();\n          }\n        }}\n        mod={{ type: 'year', active: year === yearValue }}\n        aria-label={`${getLabel('selectYear', resolvedLabels)} ${year}`}\n        tabIndex={hasActiveYear ? (year === yearValue ? 0 : -1) : index === 0 ? 0 : -1}\n        {...controlProps}\n        onKeyDown={createScopedKeydownHandler({\n          siblingSelector: '[data-type=\"year\"]:not(:disabled)',\n          parentSelector: '[data-list]',\n          activateOnFocus: false,\n          loop: true,\n          orientation: 'vertical',\n          onKeyDown: controlProps?.onKeyDown,\n        })}\n        {...getStyles('monthYearSelectControl', {\n          className: controlProps?.className,\n          style: controlProps?.style,\n        })}\n      >\n        {year}\n      </UnstyledButton>\n    );\n  });\n\n  const months = withMonths\n    ? getMonthsList({\n        locale: ctx.getLocale(locale),\n        format: monthsListFormat || 'MMMM',\n      }).map((month) => {\n        const controlProps = getMonthControlProps?.(month.month);\n        return (\n          <UnstyledButton\n            key={month.name}\n            onClick={() => onMonthChange?.(month.month)}\n            mod={{ type: 'month', active: month.month === monthValue }}\n            tabIndex={month.month === monthValue ? 0 : -1}\n            onKeyDown={createScopedKeydownHandler({\n              siblingSelector: '[data-type=\"month\"]:not(:disabled)',\n              parentSelector: '[data-list]',\n              activateOnFocus: false,\n              loop: true,\n              orientation: 'vertical',\n              onKeyDown: controlProps?.onKeyDown,\n            })}\n            {...controlProps}\n            {...getStyles('monthYearSelectControl', {\n              className: controlProps?.className,\n              style: controlProps?.style,\n            })}\n            aria-label={`${getLabel('selectMonth', resolvedLabels)} ${month.name}`}\n          >\n            {month.name}\n          </UnstyledButton>\n        );\n      })\n    : null;\n\n  return (\n    <Popover\n      position=\"bottom-start\"\n      __staticSelector={__staticSelector}\n      trapFocus\n      transitionProps={{ transition: 'pop', duration: 120 }}\n      radius={radius || 'var(--schedule-radius, var(--mantine-radius-default))'}\n      shadow=\"md\"\n      offset={3}\n      width={withMonths ? undefined : 'target'}\n      opened={opened}\n      onChange={handlers.set}\n      id={id}\n      {...popoverProps}\n    >\n      <Popover.Target>\n        <HeaderControl\n          {...getStyles('monthYearSelectTarget')}\n          __staticSelector={__staticSelector}\n          radius={radius}\n          data-with-months={withMonths || undefined}\n          onClick={handlers.toggle}\n          {...others}\n        >\n          {formatDate({\n            locale: ctx.getLocale(locale),\n            date: new Date(yearValue ?? today.getFullYear(), monthValue ?? today.getMonth()),\n            format: labelFormat || (withMonths ? 'MMMM YYYY' : 'YYYY'),\n          })}\n        </HeaderControl>\n      </Popover.Target>\n\n      <Popover.Dropdown\n        data-with-months={withMonths || undefined}\n        {...getStyles('monthYearSelectDropdown')}\n      >\n        {withMonths && (\n          <div data-list {...getStyles('monthYearSelectList')}>\n            <div {...getStyles('monthYearSelectLabel')}>{getLabel('month', resolvedLabels)}</div>\n            {months}\n          </div>\n        )}\n        <div data-list {...getStyles('monthYearSelectList')}>\n          {withMonths && (\n            <div {...getStyles('monthYearSelectLabel')}>{getLabel('year', resolvedLabels)}</div>\n          )}\n          {years}\n        </div>\n      </Popover.Dropdown>\n    </Popover>\n  );\n});\n\nMonthYearSelect.displayName = '@mantine/schedule/MonthYearSelect';\nMonthYearSelect.classes = classes;\nMonthYearSelect.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;;;;;;AA8FA,MAAM,eAAe;CACnB,kBAAkB;CAClB,YAAY;AACd;AAEA,MAAM,gBAAA,GAAA,cAAA,mBAAA,EAA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