"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const dayjs = require("dayjs");
const useDatesContext = require("../DatesProvider/use-dates-context.cjs");
const PickerControl = require("../PickerControl/PickerControl.cjs");
const getMonthInTabOrder = require("./get-month-in-tab-order/get-month-in-tab-order.cjs");
const getMonthsData = require("./get-months-data/get-months-data.cjs");
const isMonthDisabled = require("./is-month-disabled/is-month-disabled.cjs");
const MonthsList_module_css = require("./MonthsList.module.css.cjs");
const factory = require("../../../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/factory/factory.cjs");
const useProps = require("../../../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/use-props/use-props.cjs");
const useStyles = require("../../../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/styles-api/use-styles/use-styles.cjs");
const Box = require("../../../../../../../@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/Box/Box.cjs");
const defaultProps = {
  monthsListFormat: "MMM",
  withCellSpacing: true
};
const MonthsList = factory.factory((_props, ref) => {
  const props = useProps.useProps("MonthsList", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    __staticSelector,
    year,
    monthsListFormat,
    locale,
    minDate,
    maxDate,
    getMonthControlProps,
    __getControlRef,
    __onControlKeyDown,
    __onControlClick,
    __onControlMouseEnter,
    __preventFocus,
    __stopPropagation,
    withCellSpacing,
    size,
    ...others
  } = props;
  const getStyles = useStyles.useStyles({
    name: __staticSelector || "MonthsList",
    classes: MonthsList_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    rootSelector: "monthsList"
  });
  const ctx = useDatesContext.useDatesContext();
  const months = getMonthsData.getMonthsData(year);
  const monthInTabOrder = getMonthInTabOrder.getMonthInTabOrder(months, minDate, maxDate, getMonthControlProps);
  const rows = months.map((monthsRow, rowIndex) => {
    const cells = monthsRow.map((month, cellIndex) => {
      const controlProps = getMonthControlProps == null ? void 0 : getMonthControlProps(month);
      const isMonthInTabOrder = dayjs(month).isSame(monthInTabOrder, "month");
      return /* @__PURE__ */ jsxRuntime.jsx(
        "td",
        {
          ...getStyles("monthsListCell"),
          "data-with-spacing": withCellSpacing || void 0,
          children: /* @__PURE__ */ jsxRuntime.jsx(
            PickerControl.PickerControl,
            {
              ...getStyles("monthsListControl"),
              size,
              unstyled,
              __staticSelector: __staticSelector || "MonthsList",
              "data-mantine-stop-propagation": __stopPropagation || void 0,
              disabled: isMonthDisabled.isMonthDisabled(month, minDate, maxDate),
              ref: (node) => __getControlRef == null ? void 0 : __getControlRef(rowIndex, cellIndex, node),
              ...controlProps,
              onKeyDown: (event) => {
                var _a;
                (_a = controlProps == null ? void 0 : controlProps.onKeyDown) == null ? void 0 : _a.call(controlProps, event);
                __onControlKeyDown == null ? void 0 : __onControlKeyDown(event, { rowIndex, cellIndex, date: month });
              },
              onClick: (event) => {
                var _a;
                (_a = controlProps == null ? void 0 : controlProps.onClick) == null ? void 0 : _a.call(controlProps, event);
                __onControlClick == null ? void 0 : __onControlClick(event, month);
              },
              onMouseEnter: (event) => {
                var _a;
                (_a = controlProps == null ? void 0 : controlProps.onMouseEnter) == null ? void 0 : _a.call(controlProps, event);
                __onControlMouseEnter == null ? void 0 : __onControlMouseEnter(event, month);
              },
              onMouseDown: (event) => {
                var _a;
                (_a = controlProps == null ? void 0 : controlProps.onMouseDown) == null ? void 0 : _a.call(controlProps, event);
                __preventFocus && event.preventDefault();
              },
              tabIndex: __preventFocus || !isMonthInTabOrder ? -1 : 0,
              children: dayjs(month).locale(ctx.getLocale(locale)).format(monthsListFormat)
            }
          )
        },
        cellIndex
      );
    });
    return /* @__PURE__ */ jsxRuntime.jsx("tr", { ...getStyles("monthsListRow"), children: cells }, rowIndex);
  });
  return /* @__PURE__ */ jsxRuntime.jsx(Box.Box, { component: "table", ref, size, ...getStyles("monthsList"), ...others, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows }) });
});
MonthsList.classes = MonthsList_module_css.default;
MonthsList.displayName = "@mantine/dates/MonthsList";
exports.MonthsList = MonthsList;
