import { useContext, useMemo } from "react";
import merge_1 from "../../../../../../../../lodash@4.17.21/node_modules/lodash/merge.js";
import { dayjs } from "../../../_util/dayjs.js";
import cs from "../../../_util/classNames.js";
import { ConfigContext } from "../../../ConfigProvider/index.js";
import Header from "../header.js";
import Body from "../body.js";
import YearPicker from "../year/index.js";
import { padStart } from "../../../_util/pad.js";
import { jsx, jsxs } from "../../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function MonthPicker(props) {
  var pageShowDate = props.pageShowDate, style = props.style, onMouseEnterCell = props.onMouseEnterCell, onMouseLeaveCell = props.onMouseLeaveCell, dateRender = props.dateRender, disabledDate = props.disabledDate, value = props.value, locale = props.locale, isRangePicker = props.isRangePicker, onSelect = props.onSelect, rangeValues = props.rangeValues, onSuperPrev = props.onSuperPrev, onSuperNext = props.onSuperNext, format = props.format, getHeaderOperations = props.getHeaderOperations, setPageShowDate = props.setPageShowDate, icons = props.icons, panelMode = props.panelMode, originMode = props.originMode, setPanelMode = props.setPanelMode, rest = __rest(props, ["pageShowDate", "style", "onMouseEnterCell", "onMouseLeaveCell", "dateRender", "disabledDate", "value", "locale", "isRangePicker", "onSelect", "rangeValues", "onSuperPrev", "onSuperNext", "format", "getHeaderOperations", "setPageShowDate", "icons", "panelMode", "originMode", "setPanelMode"]);
  var _a = useContext(ConfigContext), globalLocale = _a.locale, getPrefixCls = _a.getPrefixCls, rtl = _a.rtl;
  var DATEPICKER_LOCALE = merge_1(globalLocale.DatePicker, locale);
  var CALENDAR_LOCALE = DATEPICKER_LOCALE.Calendar;
  var prefixCls = getPrefixCls("panel-month");
  var classNames = cs(prefixCls);
  var bodyProps = isRangePicker ? {
    rangeValues
  } : {
    value
  };
  var showYear = pageShowDate.year();
  var rows = useMemo(function() {
    var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"].map(function(month, index) {
      return {
        name: CALENDAR_LOCALE.month.short[month],
        time: dayjs(showYear + "-" + padStart(index + 1, 2, "0"), "YYYY-MM").endOf("month")
      };
    });
    var monthGroup = Array(4);
    for (var i = 0; i < 4; i++) {
      monthGroup[i] = MONTHS.slice(i * 3, 3 * (i + 1));
    }
    return monthGroup;
  }, [showYear, CALENDAR_LOCALE]);
  function renderCalendar() {
    return /* @__PURE__ */ jsx(Body, {
      ...__assign({}, rest, bodyProps, {
        prefixCls: getPrefixCls("picker"),
        rows,
        onSelectDate: onSelect,
        isSameTime: function(current, target) {
          return current.isSame(target, "month");
        },
        onMouseEnterCell,
        onMouseLeaveCell,
        dateRender,
        disabledDate,
        CALENDAR_LOCALE,
        mode: "month",
        originMode,
        format
      })
    });
  }
  var headerOperations = {
    onSuperPrev,
    onSuperNext
  };
  function onChangePanel(mode) {
    setPanelMode(mode);
  }
  if (panelMode === "year") {
    return /* @__PURE__ */ jsx(YearPicker, {
      ...__assign({}, getHeaderOperations(panelMode), {
        pageShowDate,
        onSelect: function(_, date) {
          setPanelMode("month");
          setPageShowDate(date);
        },
        disabledDate
      })
    });
  }
  return /* @__PURE__ */ jsxs("div", {
    className: classNames,
    style,
    children: [/* @__PURE__ */ jsx(Header, {
      ...__assign({}, headerOperations, {
        icons,
        prefixCls: getPrefixCls("picker"),
        value: pageShowDate,
        mode: panelMode,
        onChangePanel,
        rtl
      })
    }), renderCalendar()]
  });
}
MonthPicker.defaultProps = {
  pickerType: "month"
};
export {
  MonthPicker as default
};
//# sourceMappingURL=index.js.map
