import * as r from "react";
import H from "../../../classnames/index.mjs";
import L, { responsiveArray as g } from "../_util/responsiveObserver.mjs";
import "../config-provider/index.mjs";
import q from "./RowContext.mjs";
import { useRowStyle as F } from "./style/index.mjs";
import { ConfigContext as K } from "../config-provider/context.mjs";
var Q = globalThis && globalThis.__rest || function(e, o) {
  var c = {};
  for (var t in e)
    Object.prototype.hasOwnProperty.call(e, t) && o.indexOf(t) < 0 && (c[t] = e[t]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var s = 0, t = Object.getOwnPropertySymbols(e); s < t.length; s++)
      o.indexOf(t[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[s]) && (c[t[s]] = e[t[s]]);
  return c;
};
function E(e, o) {
  const [c, t] = r.useState(typeof e == "string" ? e : ""), s = () => {
    if (typeof e == "string" && t(e), typeof e == "object")
      for (let a = 0; a < g.length; a++) {
        const u = g[a];
        if (!o[u])
          continue;
        const m = e[u];
        if (m !== void 0) {
          t(m);
          return;
        }
      }
  };
  return r.useEffect(() => {
    s();
  }, [JSON.stringify(e), o]), c;
}
const N = /* @__PURE__ */ r.forwardRef((e, o) => {
  const {
    prefixCls: c,
    justify: t,
    align: s,
    className: a,
    style: u,
    children: m,
    gutter: p = 0,
    wrap: d
  } = e, $ = Q(e, ["prefixCls", "justify", "align", "className", "style", "children", "gutter", "wrap"]), {
    getPrefixCls: G,
    direction: V
  } = r.useContext(K), [_, k] = r.useState({
    xs: !0,
    sm: !0,
    md: !0,
    lg: !0,
    xl: !0,
    xxl: !0
  }), [h, z] = r.useState({
    xs: !1,
    sm: !1,
    md: !1,
    lg: !1,
    xl: !1,
    xxl: !1
  }), j = E(s, h), S = E(t, h), J = r.useRef(p), v = L();
  r.useEffect(() => {
    const l = v.subscribe((x) => {
      z(x);
      const n = J.current || 0;
      (!Array.isArray(n) && typeof n == "object" || Array.isArray(n) && (typeof n[0] == "object" || typeof n[1] == "object")) && k(x);
    });
    return () => v.unsubscribe(l);
  }, []);
  const M = () => {
    const l = [void 0, void 0];
    return (Array.isArray(p) ? p : [p, void 0]).forEach((n, A) => {
      if (typeof n == "object")
        for (let w = 0; w < g.length; w++) {
          const O = g[w];
          if (_[O] && n[O] !== void 0) {
            l[A] = n[O];
            break;
          }
        }
      else
        l[A] = n;
    }), l;
  }, f = G("row", c), [I, P, T] = F(f), i = M(), B = H(f, {
    [`${f}-no-wrap`]: d === !1,
    [`${f}-${S}`]: S,
    [`${f}-${j}`]: j,
    [`${f}-rtl`]: V === "rtl"
  }, a, P, T), y = {}, b = i[0] != null && i[0] > 0 ? i[0] / -2 : void 0;
  b && (y.marginLeft = b, y.marginRight = b), [, y.rowGap] = i;
  const [C, R] = i, D = r.useMemo(() => ({
    gutter: [C, R],
    wrap: d
  }), [C, R, d]);
  return I(/* @__PURE__ */ r.createElement(q.Provider, {
    value: D
  }, /* @__PURE__ */ r.createElement("div", Object.assign({}, $, {
    className: B,
    style: Object.assign(Object.assign({}, y), u),
    ref: o
  }), m)));
});
process.env.NODE_ENV !== "production" && (N.displayName = "Row");
const te = N;
export {
  te as default
};
