"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 Day = require("../Day/Day.cjs");
const WeekdaysRow = require("../WeekdaysRow/WeekdaysRow.cjs");
const getDateInTabOrder = require("./get-date-in-tab-order/get-date-in-tab-order.cjs");
const getMonthDays = require("./get-month-days/get-month-days.cjs");
const getWeekNumber = require("./get-week-number/get-week-number.cjs");
const isAfterMinDate = require("./is-after-min-date/is-after-min-date.cjs");
const isBeforeMaxDate = require("./is-before-max-date/is-before-max-date.cjs");
const isSameMonth = require("./is-same-month/is-same-month.cjs");
const Month_module_css = require("./Month.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 useResolvedStylesApi = 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-resolved-styles-api/use-resolved-styles-api.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 createVarsResolver = 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/create-vars-resolver/create-vars-resolver.cjs");
const getSize = 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/utils/get-size/get-size.cjs");
const defaultProps = {
  withCellSpacing: true
};
const varsResolver = createVarsResolver.createVarsResolver((_, { size }) => ({
  weekNumber: {
    "--wn-fz": getSize.getFontSize(size),
    "--wn-size": getSize.getSize(size, "wn-size")
  }
}));
const Month = factory.factory((_props, ref) => {
  const props = useProps.useProps("Month", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    __staticSelector,
    locale,
    firstDayOfWeek,
    weekdayFormat,
    month,
    weekendDays,
    getDayProps,
    excludeDate,
    minDate,
    maxDate,
    renderDay,
    hideOutsideDates,
    hideWeekdays,
    getDayAriaLabel,
    static: isStatic,
    __getDayRef,
    __onDayKeyDown,
    __onDayClick,
    __onDayMouseEnter,
    __preventFocus,
    __stopPropagation,
    withCellSpacing,
    size,
    highlightToday,
    withWeekNumbers,
    ...others
  } = props;
  const getStyles = useStyles.useStyles({
    name: __staticSelector || "Month",
    classes: Month_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver,
    rootSelector: "month"
  });
  const ctx = useDatesContext.useDatesContext();
  const dates = getMonthDays.getMonthDays({
    month,
    firstDayOfWeek: ctx.getFirstDayOfWeek(firstDayOfWeek),
    consistentWeeks: ctx.consistentWeeks
  });
  const dateInTabOrder = getDateInTabOrder.getDateInTabOrder(
    dates,
    minDate,
    maxDate,
    getDayProps,
    excludeDate,
    hideOutsideDates,
    month
  );
  const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi.useResolvedStylesApi({
    classNames,
    styles,
    props
  });
  const rows = dates.map((row, rowIndex) => {
    const cells = row.map((date, cellIndex) => {
      const outside = !isSameMonth.isSameMonth(date, month);
      const ariaLabel = (getDayAriaLabel == null ? void 0 : getDayAriaLabel(date)) || dayjs(date).locale(locale || ctx.locale).format("D MMMM YYYY");
      const dayProps = getDayProps == null ? void 0 : getDayProps(date);
      const isDateInTabOrder = dayjs(date).isSame(dateInTabOrder, "date");
      return /* @__PURE__ */ jsxRuntime.jsx(
        "td",
        {
          ...getStyles("monthCell"),
          "data-with-spacing": withCellSpacing || void 0,
          children: /* @__PURE__ */ jsxRuntime.jsx(
            Day.Day,
            {
              __staticSelector: __staticSelector || "Month",
              classNames: resolvedClassNames,
              styles: resolvedStyles,
              unstyled,
              "data-mantine-stop-propagation": __stopPropagation || void 0,
              highlightToday,
              renderDay,
              date,
              size,
              weekend: ctx.getWeekendDays(weekendDays).includes(date.getDay()),
              outside,
              hidden: hideOutsideDates ? outside : false,
              "aria-label": ariaLabel,
              static: isStatic,
              disabled: (excludeDate == null ? void 0 : excludeDate(date)) || !isBeforeMaxDate.isBeforeMaxDate(date, maxDate) || !isAfterMinDate.isAfterMinDate(date, minDate),
              ref: (node) => __getDayRef == null ? void 0 : __getDayRef(rowIndex, cellIndex, node),
              ...dayProps,
              onKeyDown: (event) => {
                var _a;
                (_a = dayProps == null ? void 0 : dayProps.onKeyDown) == null ? void 0 : _a.call(dayProps, event);
                __onDayKeyDown == null ? void 0 : __onDayKeyDown(event, { rowIndex, cellIndex, date });
              },
              onMouseEnter: (event) => {
                var _a;
                (_a = dayProps == null ? void 0 : dayProps.onMouseEnter) == null ? void 0 : _a.call(dayProps, event);
                __onDayMouseEnter == null ? void 0 : __onDayMouseEnter(event, date);
              },
              onClick: (event) => {
                var _a;
                (_a = dayProps == null ? void 0 : dayProps.onClick) == null ? void 0 : _a.call(dayProps, event);
                __onDayClick == null ? void 0 : __onDayClick(event, date);
              },
              onMouseDown: (event) => {
                var _a;
                (_a = dayProps == null ? void 0 : dayProps.onMouseDown) == null ? void 0 : _a.call(dayProps, event);
                __preventFocus && event.preventDefault();
              },
              tabIndex: __preventFocus || !isDateInTabOrder ? -1 : 0
            }
          )
        },
        date.toString()
      );
    });
    return /* @__PURE__ */ jsxRuntime.jsxs("tr", { ...getStyles("monthRow"), children: [
      withWeekNumbers && /* @__PURE__ */ jsxRuntime.jsx("td", { ...getStyles("weekNumber"), children: getWeekNumber.getWeekNumber(row) }),
      cells
    ] }, rowIndex);
  });
  return /* @__PURE__ */ jsxRuntime.jsxs(Box.Box, { component: "table", ...getStyles("month"), size, ref, ...others, children: [
    !hideWeekdays && /* @__PURE__ */ jsxRuntime.jsx("thead", { ...getStyles("monthThead"), children: /* @__PURE__ */ jsxRuntime.jsx(
      WeekdaysRow.WeekdaysRow,
      {
        __staticSelector: __staticSelector || "Month",
        locale,
        firstDayOfWeek,
        weekdayFormat,
        size,
        classNames: resolvedClassNames,
        styles: resolvedStyles,
        unstyled,
        withWeekNumbers
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx("tbody", { ...getStyles("monthTbody"), children: rows })
  ] });
});
Month.classes = Month_module_css.default;
Month.displayName = "@mantine/dates/Month";
exports.Month = Month;
