import Cn from "../../@babel/runtime/helpers/esm/classCallCheck.mjs";
import hn from "../../@babel/runtime/helpers/esm/createClass.mjs";
import $ from "../../@babel/runtime/helpers/esm/assertThisInitialized.mjs";
import Pn from "../../@babel/runtime/helpers/esm/inherits.mjs";
import xn from "../../@babel/runtime/helpers/esm/createSuper.mjs";
import he from "../../@babel/runtime/helpers/esm/extends.mjs";
import s from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import y from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import g from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import F from "../../classnames/index.mjs";
import Ce from "../../rc-util/es/hooks/useMergedState.mjs";
import { warningOnce as H } from "../../rc-util/es/warning.mjs";
import Dn from "../../rc-util/es/pickAttrs.mjs";
import * as t from "react";
import Mn from "./hooks/useHoverValue.mjs";
import Rn from "./hooks/usePickerInput.mjs";
import kn from "./hooks/usePresets.mjs";
import wn from "./hooks/useTextValueMapping.mjs";
import _n from "./hooks/useValueTexts.mjs";
import yn from "./PanelContext.mjs";
import En from "./PickerPanel.mjs";
import Nn from "./PickerTrigger.mjs";
import bn from "./PresetPanel.mjs";
import { parseValue as In, isEqual as Sn, formatValue as Vn } from "./utils/dateUtil.mjs";
import { toArray as On } from "./utils/miscUtil.mjs";
import { elementsContains as Tn, getInputSize as Ln, getDefaultFormat as Kn } from "./utils/uiUtil.mjs";
import { legacyPropsWarning as An } from "./utils/warnUtil.mjs";
import { getClearIcon as Bn } from "./utils/getClearIcon.mjs";
function $n(l) {
  var i, n = l, a = n.prefixCls, o = a === void 0 ? "rc-picker" : a, E = n.id, C = n.name, Pe = n.tabIndex, xe = n.style, De = n.className, Me = n.dropdownClassName, Re = n.dropdownAlign, ke = n.popupStyle, we = n.transitionName, f = n.generateConfig, M = n.locale, _e = n.inputReadOnly, U = n.allowClear, ye = n.autoFocus, z = n.showTime, j = n.picker, h = j === void 0 ? "date" : j, Ee = n.format, Ne = n.use12Hours, be = n.value, Ie = n.defaultValue, Se = n.presets, Ve = n.open, Oe = n.defaultOpen, q = n.defaultOpenValue, W = n.suffixIcon, Te = n.clearIcon, R = n.disabled, N = n.disabledDate, Le = n.placeholder, Ke = n.getPopupContainer, G = n.pickerRef, J = n.panelRender, Q = n.onChange, X = n.onOpenChange, Ae = n.onFocus, V = n.onBlur, Be = n.onMouseDown, $e = n.onMouseUp, Fe = n.onMouseEnter, He = n.onMouseLeave, Ue = n.onContextMenu, O = n.onClick, T = n.onKeyDown, L = n.onSelect, b = n.direction, Y = n.autoComplete, ze = Y === void 0 ? "off" : Y, Z = n.inputRender, ee = n.changeOnBlur, k = t.useRef(null), ne = h === "date" && !!z || h === "time", je = kn(Se);
  process.env.NODE_ENV !== "production" && An(l);
  var P = On(Kn(Ee, h, z, Ne)), te = t.useRef(null), re = t.useRef(null), oe = t.useRef(null), qe = Ce(null, {
    value: be,
    defaultValue: Ie
  }), ae = g(qe, 2), p = ae[0], We = ae[1], Ge = t.useState(p), ue = g(Ge, 2), x = ue[0], D = ue[1], m = t.useRef(null), Je = Ce(!1, {
    value: Ve,
    defaultValue: Oe,
    postState: function(e) {
      return R ? !1 : e;
    },
    onChange: function(e) {
      X && X(e), !e && m.current && m.current.onClose && m.current.onClose();
    }
  }), le = g(Je, 2), d = le[0], Qe = le[1], Xe = _n(x, {
    formatList: P,
    generateConfig: f,
    locale: M
  }), ie = g(Xe, 2), I = ie[0], Ye = ie[1], Ze = wn({
    valueTexts: I,
    onTextChange: function(e) {
      var u = In(e, {
        locale: M,
        formatList: P,
        generateConfig: f
      });
      u && (!N || !N(u)) && D(u);
    }
  }), K = g(Ze, 3), w = K[0], ce = K[1], S = K[2], _ = function(e) {
    D(e), We(e), Q && !Sn(f, p, e) && Q(e, e ? Vn(e, {
      generateConfig: f,
      locale: M,
      format: P[0]
    }) : "");
  }, v = function(e) {
    R && e || Qe(e);
  }, en = function(e) {
    return d && m.current && m.current.onKeyDown ? m.current.onKeyDown(e) : (H(!1, "Picker not correct forward KeyDown operation. Please help to fire issue about this."), !1);
  }, nn = function() {
    for (var e = arguments.length, u = new Array(e), c = 0; c < e; c++)
      u[c] = arguments[c];
    O == null || O.apply(void 0, u), k.current && (k.current.focus(), v(!0));
  }, tn = function(e) {
    ee && _(x), V == null || V(e);
  }, rn = Rn({
    blurToCancel: ne,
    changeOnBlur: ee,
    open: d,
    value: w,
    triggerOpen: v,
    forwardKeyDown: en,
    isClickOutside: function(e) {
      return !Tn([te.current, re.current, oe.current], e);
    },
    onSubmit: function() {
      return (
        // When user typing disabledDate with keyboard and enter, this value will be empty
        !x || // Normal disabled check
        N && N(x) ? !1 : (_(x), v(!1), S(), !0)
      );
    },
    onCancel: function() {
      v(!1), D(p), S();
    },
    onKeyDown: function(e, u) {
      T == null || T(e, u);
    },
    onFocus: Ae,
    onBlur: tn
  }), se = g(rn, 2), on = se[0], fe = se[1], an = fe.focused, pe = fe.typing;
  t.useEffect(function() {
    d || (D(p), !I.length || I[0] === "" ? ce("") : Ye !== w && S());
  }, [d, I]), t.useEffect(function() {
    d || S();
  }, [h]), t.useEffect(function() {
    D(p);
  }, [p]), G && (G.current = {
    focus: function() {
      var e;
      (e = k.current) === null || e === void 0 || e.focus();
    },
    blur: function() {
      var e;
      (e = k.current) === null || e === void 0 || e.blur();
    }
  });
  var un = Mn(w, {
    formatList: P,
    generateConfig: f,
    locale: M
  }), A = g(un, 3), me = A[0], ln = A[1], de = A[2], cn = y(y({}, l), {}, {
    className: void 0,
    style: void 0,
    pickerValue: void 0,
    onPickerValueChange: void 0,
    onChange: null
  }), B = /* @__PURE__ */ t.createElement("div", {
    className: "".concat(o, "-panel-layout")
  }, /* @__PURE__ */ t.createElement(bn, {
    prefixCls: o,
    presets: je,
    onClick: function(e) {
      _(e), v(!1);
    }
  }), /* @__PURE__ */ t.createElement(En, he({}, cn, {
    generateConfig: f,
    className: F(s({}, "".concat(o, "-panel-focused"), !pe)),
    value: x,
    locale: M,
    tabIndex: -1,
    onSelect: function(e) {
      L == null || L(e), D(e);
    },
    direction: b,
    onPanelChange: function(e, u) {
      var c = l.onPanelChange;
      de(!0), c == null || c(e, u);
    }
  })));
  J && (B = J(B));
  var sn = /* @__PURE__ */ t.createElement("div", {
    className: "".concat(o, "-panel-container"),
    ref: te,
    onMouseDown: function(e) {
      e.preventDefault();
    }
  }, B), ve;
  W && (ve = /* @__PURE__ */ t.createElement("span", {
    className: "".concat(o, "-suffix"),
    onMouseDown: function(e) {
      e.preventDefault();
    }
  }, W)), process.env.NODE_ENV !== "production" && H(!l.clearIcon, "`clearIcon` will be removed in future. Please use `allowClear` instead.");
  var fn = Bn(o, U, Te), pn = /* @__PURE__ */ t.createElement("span", {
    onMouseDown: function(e) {
      e.preventDefault(), e.stopPropagation();
    },
    onMouseUp: function(e) {
      e.preventDefault(), e.stopPropagation(), _(null), v(!1);
    },
    className: "".concat(o, "-clear"),
    role: "button"
  }, fn), mn = !!U && p && !R, ge = y(y(y({
    id: E,
    tabIndex: Pe,
    disabled: R,
    readOnly: _e || typeof P[0] == "function" || !pe,
    value: me || w,
    onChange: function(e) {
      ce(e.target.value);
    },
    autoFocus: ye,
    placeholder: Le,
    ref: k,
    title: w
  }, on), {}, {
    size: Ln(h, P[0], f),
    name: C
  }, Dn(l, {
    aria: !0,
    data: !0
  })), {}, {
    autoComplete: ze
  }), dn = Z ? Z(ge) : /* @__PURE__ */ t.createElement("input", ge);
  process.env.NODE_ENV !== "production" && H(!q, "`defaultOpenValue` may confuse user for the current value status. Please use `defaultValue` instead.");
  var vn = function(e, u) {
    (u === "submit" || u !== "key" && !ne) && (_(e), v(!1));
  }, gn = b === "rtl" ? "bottomRight" : "bottomLeft";
  return /* @__PURE__ */ t.createElement(yn.Provider, {
    value: {
      operationRef: m,
      hideHeader: h === "time",
      onSelect: vn,
      open: d,
      defaultOpenValue: q,
      onDateMouseEnter: ln,
      onDateMouseLeave: de
    }
  }, /* @__PURE__ */ t.createElement(Nn, {
    visible: d,
    popupElement: sn,
    popupStyle: ke,
    prefixCls: o,
    dropdownClassName: Me,
    dropdownAlign: Re,
    getPopupContainer: Ke,
    transitionName: we,
    popupPlacement: gn,
    direction: b
  }, /* @__PURE__ */ t.createElement("div", {
    ref: oe,
    className: F(o, De, (i = {}, s(i, "".concat(o, "-disabled"), R), s(i, "".concat(o, "-focused"), an), s(i, "".concat(o, "-rtl"), b === "rtl"), i)),
    style: xe,
    onMouseDown: Be,
    onMouseUp: $e,
    onMouseEnter: Fe,
    onMouseLeave: He,
    onContextMenu: Ue,
    onClick: nn
  }, /* @__PURE__ */ t.createElement("div", {
    className: F("".concat(o, "-input"), s({}, "".concat(o, "-input-placeholder"), !!me)),
    ref: re
  }, dn, ve, mn && pn))));
}
var dt = /* @__PURE__ */ function(l) {
  Pn(n, l);
  var i = xn(n);
  function n() {
    var a;
    Cn(this, n);
    for (var o = arguments.length, E = new Array(o), C = 0; C < o; C++)
      E[C] = arguments[C];
    return a = i.call.apply(i, [this].concat(E)), s($(a), "pickerRef", /* @__PURE__ */ t.createRef()), s($(a), "focus", function() {
      a.pickerRef.current && a.pickerRef.current.focus();
    }), s($(a), "blur", function() {
      a.pickerRef.current && a.pickerRef.current.blur();
    }), a;
  }
  return hn(n, [{
    key: "render",
    value: function() {
      return /* @__PURE__ */ t.createElement($n, he({}, this.props, {
        pickerRef: this.pickerRef
      }));
    }
  }]), n;
}(t.Component);
export {
  dt as default
};
