import M from "../../../../@babel/runtime/helpers/esm/extends.mjs";
import F from "../../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import w from "../../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import O from "../../../../@babel/runtime/helpers/esm/typeof.mjs";
import G from "../../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import U from "../../../../classnames/index.mjs";
import d from "../../../../rc-util/es/KeyCode.mjs";
import * as c from "react";
import { tuple as W } from "../../utils/miscUtil.mjs";
import { setDateTime as k } from "../../utils/timeUtil.mjs";
import q from "../DatePanel/index.mjs";
import z from "../TimePanel/index.mjs";
var T = W("date", "time"), x = function(m, g, n) {
  var l = new Set(g);
  if (l.has(m)) {
    for (var a = 0; a <= n; a++)
      if (!l.has(a) && a >= m)
        return a;
  }
  return m;
};
function ae(r) {
  var m = r.prefixCls, g = r.operationRef, n = r.generateConfig, l = r.value, a = r.defaultValue, v = r.disabledTime, S = r.showTime, C = r.onSelect, D = r.cellRender, A = "".concat(m, "-datetime-panel"), j = c.useState(null), B = G(j, 2), i = B[0], h = B[1], E = c.useRef({}), R = c.useRef({}), K = O(S) === "object" ? w({}, S) : {};
  function H(o) {
    var t = T.indexOf(i) + o, u = T[t] || null;
    return u;
  }
  var V = function(t) {
    R.current.onBlur && R.current.onBlur(t), h(null);
  };
  g.current = {
    onKeyDown: function(t) {
      if (t.which === d.TAB) {
        var u = H(t.shiftKey ? -1 : 1);
        return h(u), u && t.preventDefault(), !0;
      }
      if (i) {
        var e = i === "date" ? E : R;
        return e.current && e.current.onKeyDown && e.current.onKeyDown(t), !0;
      }
      return [d.LEFT, d.RIGHT, d.UP, d.DOWN].includes(t.which) ? (h("date"), !0) : !1;
    },
    onBlur: V,
    onClose: V
  };
  var I = function(t, u) {
    var e = t;
    if (u === "date") {
      var p, y, P, f = (v == null ? void 0 : v(l || K.defaultValue)) || {}, s = x(n.getHour(e), ((p = f.disabledHours) === null || p === void 0 ? void 0 : p.call(f)) || [-1], 23), N = x(n.getMinute(e), ((y = f.disabledMinutes) === null || y === void 0 ? void 0 : y.call(f, s)) || [-1], 59), Y = x(n.getSecond(e), ((P = f.disabledSeconds) === null || P === void 0 ? void 0 : P.call(f, s, N)) || [-1], 59);
      e = n.setHour(e, s), e = n.setMinute(e, N), e = n.setSecond(e, Y);
    } else
      u === "time" && !l && a && (e = n.setYear(e, n.getYear(a)), e = n.setMonth(e, n.getMonth(a)), e = n.setDate(e, n.getDate(a)));
    C && C(e, "mouse");
  }, L = v ? v(l || null) : {};
  return /* @__PURE__ */ c.createElement("div", {
    className: U(A, F({}, "".concat(A, "-active"), i))
  }, /* @__PURE__ */ c.createElement(q, M({}, r, {
    cellRender: D,
    operationRef: E,
    active: i === "date",
    onSelect: function(t) {
      I(k(n, t, !l && O(S) === "object" ? S.defaultValue : null), "date");
    }
  })), /* @__PURE__ */ c.createElement(z, M({}, r, {
    cellRender: D ? function(o, t) {
      return D(o, w(w({}, t), {}, {
        type: "time"
      }));
    } : void 0,
    format: void 0
  }, K, L, {
    disabledTime: null,
    defaultValue: void 0,
    operationRef: R,
    active: i === "time",
    onSelect: function(t) {
      I(t, "time");
    }
  })));
}
export {
  ae as default
};
