import * as a from "react";
import _ from "../../../../classnames/index.mjs";
import M from "../../../../rc-util/es/Dom/isVisible.mjs";
import B from "../../../../rc-util/es/hooks/useLayoutEffect.mjs";
import D from "../../../../rc-util/es/omit.mjs";
import L from "../../grid/row.mjs";
import { FormContext as T, NoStyleItemContext as H } from "../context.mjs";
import W from "../FormItemInput.mjs";
import z from "../FormItemLabel.mjs";
import w from "../hooks/useDebounce.mjs";
import { getStatus as A } from "../util.mjs";
import K from "./StatusProvider.mjs";
var U = globalThis && globalThis.__rest || function(e, o) {
  var m = {};
  for (var t in e)
    Object.prototype.hasOwnProperty.call(e, t) && o.indexOf(t) < 0 && (m[t] = e[t]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var n = 0, t = Object.getOwnPropertySymbols(e); n < t.length; n++)
      o.indexOf(t[n]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[n]) && (m[t[n]] = e[t[n]]);
  return m;
};
function se(e) {
  const {
    prefixCls: o,
    className: m,
    rootClassName: t,
    style: n,
    help: u,
    errors: b,
    warnings: v,
    validateStatus: E,
    meta: s,
    hasFeedback: d,
    hidden: x,
    children: O,
    fieldId: I,
    required: g,
    isRequired: F,
    onSubItemMetaChange: N
  } = e, V = U(e, ["prefixCls", "className", "rootClassName", "style", "help", "errors", "warnings", "validateStatus", "meta", "hasFeedback", "hidden", "children", "fieldId", "required", "isRequired", "onSubItemMetaChange"]), r = `${o}-item`, {
    requiredMark: $
  } = a.useContext(T), c = a.useRef(null), f = w(b), p = w(v), y = u != null, C = !!(y || b.length || v.length), P = !!c.current && M(c.current), [h, S] = a.useState(null);
  B(() => {
    if (C && c.current) {
      const l = getComputedStyle(c.current);
      S(parseInt(l.marginBottom, 10));
    }
  }, [C, P]);
  const q = (l) => {
    l || S(null);
  }, i = function() {
    let l = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !1;
    const k = l ? f : s.errors, R = l ? p : s.warnings;
    return A(k, R, s, "", !!d, E);
  }(), j = _(r, m, t, {
    [`${r}-with-help`]: y || f.length || p.length,
    // Status
    [`${r}-has-feedback`]: i && d,
    [`${r}-has-success`]: i === "success",
    [`${r}-has-warning`]: i === "warning",
    [`${r}-has-error`]: i === "error",
    [`${r}-is-validating`]: i === "validating",
    [`${r}-hidden`]: x
  });
  return /* @__PURE__ */ a.createElement("div", {
    className: j,
    style: n,
    ref: c
  }, /* @__PURE__ */ a.createElement(L, Object.assign({
    className: `${r}-row`
  }, D(V, [
    "_internalItemRender",
    "colon",
    "dependencies",
    "extra",
    "fieldKey",
    "getValueFromEvent",
    "getValueProps",
    "htmlFor",
    "id",
    // It is deprecated because `htmlFor` is its replacement.
    "initialValue",
    "isListField",
    "label",
    "labelAlign",
    "labelCol",
    "labelWrap",
    "messageVariables",
    "name",
    "normalize",
    "noStyle",
    "preserve",
    "requiredMark",
    "rules",
    "shouldUpdate",
    "trigger",
    "tooltip",
    "validateFirst",
    "validateTrigger",
    "valuePropName",
    "wrapperCol",
    "validateDebounce"
  ])), /* @__PURE__ */ a.createElement(z, Object.assign({
    htmlFor: I
  }, e, {
    requiredMark: $,
    required: g ?? F,
    prefixCls: o
  })), /* @__PURE__ */ a.createElement(W, Object.assign({}, e, s, {
    errors: f,
    warnings: p,
    prefixCls: o,
    status: i,
    help: u,
    marginBottom: h,
    onErrorVisibleChanged: q
  }), /* @__PURE__ */ a.createElement(H.Provider, {
    value: N
  }, /* @__PURE__ */ a.createElement(K, {
    prefixCls: o,
    meta: s,
    errors: s.errors,
    warnings: s.warnings,
    hasFeedback: d,
    // Already calculated
    validateStatus: i
  }, O)))), !!h && /* @__PURE__ */ a.createElement("div", {
    className: `${r}-margin-offset`,
    style: {
      marginBottom: -h
    }
  }));
}
export {
  se as default
};
