import K from "../../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import Q from "../../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import se from "../../../../rc-util/es/hooks/useMemo.mjs";
import * as i from "react";
import ce from "../../hooks/useTimeSelection.mjs";
import { leftPad as W } from "../../utils/miscUtil.mjs";
import C from "./TimeUnitColumn.mjs";
function fe(n, o) {
  if (n.length !== o.length)
    return !0;
  for (var r = 0; r < n.length; r += 1)
    if (n[r].disabled !== o[r].disabled)
      return !0;
  return !1;
}
function p(n, o, r, x) {
  for (var b = [], u = r >= 1 ? r | 0 : 1, d = n; d <= o; d += u)
    b.push({
      label: W(d, 2),
      value: d,
      disabled: (x || []).includes(d)
    });
  return b;
}
function ge(n) {
  var o = n.generateConfig, r = n.prefixCls, x = n.operationRef, b = n.activeColumnIndex, u = n.value, d = n.showHour, X = n.showMinute, Y = n.showSecond, s = n.use12Hours, A = n.hourStep, Z = A === void 0 ? 1 : A, I = n.minuteStep, L = I === void 0 ? 1 : I, N = n.secondStep, ee = N === void 0 ? 1 : N, O = n.disabledHours, U = n.disabledMinutes, j = n.disabledSeconds, P = n.disabledTime, ne = n.hideDisabledOptions, M = n.onSelect, g = n.cellRender, y = n.locale, R = [], te = "".concat(r, "-content"), ae = "".concat(r, "-time-panel"), l, _ = u ? o.getHour(u) : -1, c = _, h = u ? o.getMinute(u) : -1, H = u ? o.getSecond(u) : -1, f = o.getNow(), oe = i.useMemo(function() {
    if (P) {
      var e = P(f);
      return [e.disabledHours, e.disabledMinutes, e.disabledSeconds];
    }
    return [O, U, j];
  }, [O, U, j, P, f]), E = Q(oe, 3), z = E[0], T = E[1], $ = E[2], B = p(0, 23, Z, z && z()), S = se(function() {
    return B;
  }, B, fe);
  s && (l = c >= 12, c %= 12);
  var re = i.useMemo(function() {
    if (!s)
      return [!1, !1];
    var e = [!0, !0];
    return S.forEach(function(a) {
      var t = a.disabled, m = a.value;
      t || (m >= 12 ? e[1] = !1 : e[0] = !1);
    }), e;
  }, [s, S]), V = Q(re, 2), ue = V[0], ie = V[1], le = i.useMemo(function() {
    return s ? S.filter(l ? function(e) {
      return e.value >= 12;
    } : function(e) {
      return e.value < 12;
    }).map(function(e) {
      var a = e.value % 12, t = a === 0 ? "12" : W(a, 2);
      return K(K({}, e), {}, {
        label: t,
        value: a
      });
    }) : S;
  }, [s, l, S]), q = p(0, 59, L, T && T(_)), F = p(0, 59, ee, $ && $(_, h)), w = ce({
    value: u,
    generateConfig: o,
    disabledMinutes: T,
    disabledSeconds: $,
    minutes: q,
    seconds: F,
    use12Hours: s
  });
  x.current = {
    onUpDown: function(a) {
      var t = R[b];
      if (t)
        for (var m = t.units.findIndex(function(de) {
          return de.value === t.value;
        }), v = t.units.length, k = 1; k < v; k += 1) {
          var J = t.units[(m + a * k + v) % v];
          if (J.disabled !== !0) {
            t.onSelect(J.value);
            break;
          }
        }
    }
  };
  function D(e, a, t, m, v) {
    e !== !1 && R.push({
      node: /* @__PURE__ */ i.cloneElement(a, {
        prefixCls: ae,
        value: t,
        active: b === R.length,
        onSelect: v,
        units: m,
        hideDisabledOptions: ne
      }),
      onSelect: v,
      value: t,
      units: m
    });
  }
  D(d, /* @__PURE__ */ i.createElement(C, {
    key: "hour",
    type: "hour",
    info: {
      today: f,
      locale: y,
      cellRender: g
    }
  }), c, le, function(e) {
    M(w(l, e, h, H), "mouse");
  }), D(X, /* @__PURE__ */ i.createElement(C, {
    key: "minute",
    type: "minute",
    info: {
      today: f,
      locale: y,
      cellRender: g
    }
  }), h, q, function(e) {
    M(w(l, c, e, H), "mouse");
  }), D(Y, /* @__PURE__ */ i.createElement(C, {
    key: "second",
    type: "second",
    info: {
      today: f,
      locale: y,
      cellRender: g
    }
  }), H, F, function(e) {
    M(w(l, c, h, e), "mouse");
  });
  var G = -1;
  return typeof l == "boolean" && (G = l ? 1 : 0), D(s === !0, /* @__PURE__ */ i.createElement(C, {
    key: "meridiem",
    type: "meridiem",
    info: {
      today: f,
      locale: y,
      cellRender: g
    }
  }), G, [{
    label: "AM",
    value: 0,
    disabled: ue
  }, {
    label: "PM",
    value: 1,
    disabled: ie
  }], function(e) {
    M(w(!!e, c, h, H), "mouse");
  }), /* @__PURE__ */ i.createElement("div", {
    className: te
  }, R.map(function(e) {
    var a = e.node;
    return a;
  }));
}
export {
  ge as default
};
