import * as r from "react";
import x from "../../../classnames/index.mjs";
import w from "../../../rc-util/es/hooks/useMergedState.mjs";
import "../../../rc-util/es/warning.mjs";
import "../../../rc-util/es/raf.mjs";
import "../../../rc-util/es/hooks/useLayoutEffect.mjs";
import te from "../../../rc-picker/es/PickerPanel.mjs";
import "../../../@rc-component/trigger/es/index.mjs";
import "../../../rc-util/node_modules/react-is/index.mjs";
import { devUseWarning as ne } from "../_util/warning.mjs";
import "../config-provider/index.mjs";
import re from "./Header.mjs";
import ae from "../date-picker/locale/en_US.mjs";
import oe from "./style/index.mjs";
import { ConfigContext as se } from "../config-provider/context.mjs";
import ce from "../locale/useLocale.mjs";
function $e(t) {
  function D(a, o) {
    return a && o && t.getYear(a) === t.getYear(o);
  }
  function b(a, o) {
    return D(a, o) && t.getMonth(a) === t.getMonth(o);
  }
  function O(a, o) {
    return b(a, o) && t.getDate(a) === t.getDate(o);
  }
  const j = (a) => {
    const {
      prefixCls: o,
      className: L,
      rootClassName: Y,
      style: z,
      dateFullCellRender: h,
      dateCellRender: C,
      monthFullCellRender: f,
      monthCellRender: R,
      cellRender: d,
      fullCellRender: i,
      headerRender: P,
      value: V,
      defaultValue: A,
      disabledDate: N,
      mode: H,
      validRange: u,
      fullscreen: M = !0,
      onChange: S,
      onPanelChange: $,
      onSelect: y
    } = a, {
      getPrefixCls: U,
      direction: _,
      calendar: m
    } = r.useContext(se), p = U("picker", o), n = `${p}-calendar`, [T, W, q] = oe(p, n), k = t.getNow();
    if (process.env.NODE_ENV !== "production") {
      const e = ne("Calendar");
      e.deprecated(!h, "dateFullCellRender", "fullCellRender"), e.deprecated(!C, "dateCellRender", "cellRender"), e.deprecated(!f, "monthFullCellRender", "fullCellRender"), e.deprecated(!R, "monthCellRender", "cellRender");
    }
    const [c, B] = w(() => V || t.getNow(), {
      defaultValue: A,
      value: V
    }), [v, G] = w("month", {
      value: H
    }), g = r.useMemo(() => v === "year" ? "month" : "date", [v]), J = r.useCallback((e) => (u ? t.isAfter(u[0], e) || t.isAfter(e, u[1]) : !1) || !!(N != null && N(e)), [N, u]), F = (e, l) => {
      $ == null || $(e, l);
    }, K = (e) => {
      B(e), O(e, c) || ((g === "date" && !b(e, c) || g === "month" && !D(e, c)) && F(e, v), S == null || S(e));
    }, I = (e) => {
      G(e), F(c, e);
    }, E = (e, l) => {
      K(e), y == null || y(e, {
        source: l
      });
    }, Q = () => {
      const {
        locale: e
      } = a, l = Object.assign(Object.assign({}, ae), e);
      return l.lang = Object.assign(Object.assign({}, l.lang), (e || {}).lang), l;
    }, X = r.useCallback((e, l) => i ? i(e, l) : h ? h(e) : /* @__PURE__ */ r.createElement("div", {
      className: x(`${p}-cell-inner`, `${n}-date`, {
        [`${n}-date-today`]: O(k, e)
      })
    }, /* @__PURE__ */ r.createElement("div", {
      className: `${n}-date-value`
    }, String(t.getDate(e)).padStart(2, "0")), /* @__PURE__ */ r.createElement("div", {
      className: `${n}-date-content`
    }, d ? d(e, l) : C && C(e))), [h, C, d, i]), Z = r.useCallback((e, l) => {
      if (i)
        return i(e, l);
      if (f)
        return f(e);
      const le = l.locale.shortMonths || t.locale.getShortMonths(l.locale.locale);
      return /* @__PURE__ */ r.createElement("div", {
        className: x(`${p}-cell-inner`, `${n}-date`, {
          [`${n}-date-today`]: b(k, e)
        })
      }, /* @__PURE__ */ r.createElement("div", {
        className: `${n}-date-value`
      }, le[t.getMonth(e)]), /* @__PURE__ */ r.createElement("div", {
        className: `${n}-date-content`
      }, d ? d(e, l) : R && R(e)));
    }, [f, R, d, i]), [s] = ce("Calendar", Q), ee = (e, l) => {
      if (l.type === "date")
        return X(e, l);
      if (l.type === "month")
        return Z(e, Object.assign(Object.assign({}, l), {
          locale: s == null ? void 0 : s.lang
        }));
    };
    return T(/* @__PURE__ */ r.createElement("div", {
      className: x(n, {
        [`${n}-full`]: M,
        [`${n}-mini`]: !M,
        [`${n}-rtl`]: _ === "rtl"
      }, m == null ? void 0 : m.className, L, Y, W, q),
      style: Object.assign(Object.assign({}, m == null ? void 0 : m.style), z)
    }, P ? P({
      value: c,
      type: v,
      onChange: (e) => {
        E(e, "customize");
      },
      onTypeChange: I
    }) : /* @__PURE__ */ r.createElement(re, {
      prefixCls: n,
      value: c,
      generateConfig: t,
      mode: v,
      fullscreen: M,
      locale: s == null ? void 0 : s.lang,
      validRange: u,
      onChange: E,
      onModeChange: I
    }), /* @__PURE__ */ r.createElement(te, {
      value: c,
      prefixCls: p,
      locale: s == null ? void 0 : s.lang,
      generateConfig: t,
      cellRender: ee,
      onSelect: (e) => {
        E(e, g);
      },
      mode: g,
      picker: g,
      disabledDate: J,
      hideHeader: !0
    })));
  };
  return process.env.NODE_ENV !== "production" && (j.displayName = "Calendar"), j;
}
export {
  $e as default
};
