import G from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import w from "../../@babel/runtime/helpers/esm/extends.mjs";
import _ from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import Ee from "../../@babel/runtime/helpers/esm/typeof.mjs";
import k from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import De from "../../classnames/index.mjs";
import K from "../../rc-util/es/hooks/useMergedState.mjs";
import l from "../../rc-util/es/KeyCode.mjs";
import { warningOnce as P } from "../../rc-util/es/warning.mjs";
import * as a from "react";
import { useCellRender as Ze } from "./hooks/useCellRender.mjs";
import Ve from "./PanelContext.mjs";
import et from "./panels/DatePanel/index.mjs";
import tt from "./panels/DatetimePanel/index.mjs";
import nt from "./panels/DecadePanel/index.mjs";
import rt from "./panels/MonthPanel/index.mjs";
import { MONTH_COL_COUNT as at } from "./panels/MonthPanel/MonthBody.mjs";
import ot from "./panels/QuarterPanel/index.mjs";
import lt from "./panels/TimePanel/index.mjs";
import it from "./panels/WeekPanel/index.mjs";
import ct from "./panels/YearPanel/index.mjs";
import ut from "./RangeContext.mjs";
import { isEqual as _e, WEEK_DAY_COUNT as st } from "./utils/dateUtil.mjs";
import dt from "./utils/getExtraFooter.mjs";
import ft from "./utils/getRanges.mjs";
import { setDateTime as mt, getLowerBoundTime as pt, setTime as vt } from "./utils/timeUtil.mjs";
import { PickerModeMap as gt } from "./utils/uiUtil.mjs";
var St = ["date", "month"];
function Lt(b) {
  var E, n = b, U = n.prefixCls, m = U === void 0 ? "rc-picker" : U, ke = n.className, be = n.style, W = n.locale, i = n.generateConfig, C = n.value, L = n.defaultValue, xe = n.pickerValue, j = n.defaultPickerValue, u = n.disabledDate, Me = n.mode, Y = n.picker, p = Y === void 0 ? "date" : Y, q = n.tabIndex, F = q === void 0 ? 0 : q, Ie = n.showNow, v = n.showTime, Te = n.showToday, ye = n.renderExtraFooter, Oe = n.hideHeader, Q = n.onSelect, z = n.onChange, J = n.onPanelChange, Ae = n.onMouseDown, X = n.onPickerValueChange, Z = n.onOk, Be = n.components, He = n.direction, ee = n.hourStep, x = ee === void 0 ? 1 : ee, te = n.minuteStep, M = te === void 0 ? 1 : te, ne = n.secondStep, I = ne === void 0 ? 1 : ne, re = n.dateRender, ae = n.monthCellRender, $e = n.cellRender, oe = p === "date" && !!v || p === "time", le = 24 % x === 0, ie = 60 % M === 0, ce = 60 % I === 0;
  process.env.NODE_ENV !== "production" && (P(!C || i.isValidate(C), "Invalidate date pass to `value`."), P(!C || i.isValidate(C), "Invalidate date pass to `defaultValue`."), P(le, "`hourStep` ".concat(x, " is invalid. It should be a factor of 24.")), P(ie, "`minuteStep` ".concat(M, " is invalid. It should be a factor of 60.")), P(ce, "`secondStep` ".concat(I, " is invalid. It should be a factor of 60.")), P(!j, "'defaultPickerValue' is deprecated. Please use 'defaultValue' instead."), P(!re, "'dateRender' is deprecated. Please use 'cellRender' instead."), P(!ae, "'monthCellRender' is deprecated. Please use 'cellRender' instead."));
  var R = a.useContext(Ve), ue = R.operationRef, se = R.onSelect, Ge = R.hideRanges, de = R.defaultOpenValue, D = a.useContext(ut), fe = D.inRange, T = D.panelPosition, y = D.rangedValue, O = D.hoverRangedValue, f = a.useRef({}), me = a.useRef(!0), Ke = K(null, {
    value: C,
    defaultValue: L,
    postState: function(e) {
      return !e && de && p === "time" ? de : e;
    }
  }), pe = k(Ke, 2), g = pe[0], Ue = pe[1], We = K(null, {
    value: xe,
    defaultValue: j || g,
    postState: function(e) {
      var t = i.getNow();
      if (!e)
        return t;
      if (!g && v) {
        var o = Ee(v) === "object" ? v.defaultValue : L;
        return mt(i, Array.isArray(e) ? e[0] : e, o || t);
      }
      return Array.isArray(e) ? e[0] : e;
    }
  }), ve = k(We, 2), N = ve[0], ge = ve[1], S = function(e) {
    ge(e), X && X(e);
  }, Se = function(e) {
    var t = gt[p];
    return t ? t(e) : e;
  }, Le = K(function() {
    return p === "time" ? "time" : Se("date");
  }, {
    value: Me
  }), he = k(Le, 2), c = he[0], Pe = he[1];
  a.useEffect(function() {
    Pe(p);
  }, [p]);
  var je = a.useState(function() {
    return c;
  }), Ce = k(je, 2), Ye = Ce[0], qe = Ce[1], Fe = function(e, t) {
    var o = Se(e || c);
    qe(c), Pe(o), J && (c !== o || _e(i, N, N)) && J(t, o);
  }, s = function(e, t) {
    var o = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
    (c === p || o) && (Ue(e), Q && Q(e), se && se(e, t), z && !_e(i, e, g) && !(u != null && u(e)) && z(e));
  }, Qe = function(e) {
    if (St.includes(c)) {
      var t, o, $ = c === "date";
      switch (e === l.PAGE_UP || e === l.PAGE_DOWN ? o = $ ? i.addMonth : i.addYear : o = $ ? i.addDate : i.addMonth, e) {
        case l.LEFT:
        case l.PAGE_UP:
          t = o(N, -1);
          break;
        case l.RIGHT:
        case l.PAGE_DOWN:
          t = o(N, 1);
          break;
        case l.UP:
        case l.DOWN:
          t = o(N, Number("".concat(e === l.UP ? "-" : "").concat($ ? st : at)));
          break;
      }
      if (t)
        return !(u != null && u(t));
    }
    return !0;
  }, we = function(e) {
    if (f.current && f.current.onKeyDown) {
      var t = !0, o = e.which;
      if ([l.LEFT, l.RIGHT, l.UP, l.DOWN, l.PAGE_UP, l.PAGE_DOWN, l.ENTER].includes(o) && (e.preventDefault(), o !== l.ENTER && F === 0 && (t = Qe(o))), t)
        return f.current.onKeyDown(e);
    }
    return P(!1, "Panel not correct handle keyDown event. Please help to fire issue about this."), !1;
  }, ze = function(e) {
    f.current && f.current.onBlur && f.current.onBlur(e);
  };
  ue && T !== "right" && (ue.current = {
    onKeyDown: we,
    onClose: function() {
      f.current && f.current.onClose && f.current.onClose();
    }
  }), a.useEffect(function() {
    C && !me.current && ge(C);
  }, [C]), a.useEffect(function() {
    me.current = !1;
  }, []);
  var h, Je = Ze({
    cellRender: $e,
    monthCellRender: ae,
    dateRender: re
  }), d = _(_({}, b), {}, {
    cellRender: Je,
    operationRef: f,
    prefixCls: m,
    viewDate: N,
    value: g,
    onViewDateChange: S,
    sourceMode: Ye,
    onPanelChange: Fe,
    disabledDate: u
  });
  switch (delete d.onChange, delete d.onSelect, c) {
    case "decade":
      h = /* @__PURE__ */ a.createElement(nt, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    case "year":
      h = /* @__PURE__ */ a.createElement(ct, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    case "month":
      h = /* @__PURE__ */ a.createElement(rt, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    case "quarter":
      h = /* @__PURE__ */ a.createElement(ot, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    case "week":
      h = /* @__PURE__ */ a.createElement(it, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    case "time":
      delete d.showTime, h = /* @__PURE__ */ a.createElement(lt, w({}, d, Ee(v) === "object" ? v : null, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
      break;
    default:
      v ? h = /* @__PURE__ */ a.createElement(tt, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      })) : h = /* @__PURE__ */ a.createElement(et, w({}, d, {
        onSelect: function(e, t) {
          S(e), s(e, t);
        }
      }));
  }
  var A, V, Xe = function() {
    var e = i.getNow(), t = pt(i.getHour(e), i.getMinute(e), i.getSecond(e), le ? x : 1, ie ? M : 1, ce ? I : 1), o = vt(
      i,
      e,
      t[0],
      // hour
      t[1],
      // minute
      t[2]
      // second
    );
    s(o, "submit");
  };
  Ge || (A = dt(m, c, ye), v && c !== "date" ? V = null : V = ft({
    prefixCls: m,
    components: Be,
    needConfirmButton: oe,
    okDisabled: !g || u && u(g),
    locale: W,
    showNow: Ie,
    onNow: oe && Xe,
    onOk: function() {
      g && (s(g, "submit", !0), Z && Z(g));
    }
  }));
  var B;
  if (Te && c === "date" && p === "date" && !v) {
    var Re = i.getNow(), Ne = "".concat(m, "-today-btn"), H = u && u(Re);
    B = /* @__PURE__ */ a.createElement("a", {
      className: De(Ne, H && "".concat(Ne, "-disabled")),
      "aria-disabled": H,
      onClick: function() {
        H || s(Re, "mouse", !0);
      }
    }, W.today);
  }
  return /* @__PURE__ */ a.createElement(Ve.Provider, {
    value: _(_({}, R), {}, {
      mode: c,
      hideHeader: "hideHeader" in b ? Oe : R.hideHeader,
      hidePrevBtn: fe && T === "right",
      hideNextBtn: fe && T === "left"
    })
  }, /* @__PURE__ */ a.createElement("div", {
    tabIndex: F,
    className: De("".concat(m, "-panel"), ke, (E = {}, G(E, "".concat(m, "-panel-has-range"), y && y[0] && y[1]), G(E, "".concat(m, "-panel-has-range-hover"), O && O[0] && O[1]), G(E, "".concat(m, "-panel-rtl"), He === "rtl"), E)),
    style: be,
    onKeyDown: we,
    onBlur: ze,
    onMouseDown: Ae
  }, h, A || V || B ? /* @__PURE__ */ a.createElement("div", {
    className: "".concat(m, "-footer")
  }, A, V, B) : null));
}
export {
  Lt as default
};
