import { o as $ } from "./rolldown-runtime.js";
import { i as L } from "./vendor/react.js";
var a = /* @__PURE__ */ $(L()), g = {};
function A(e, t) {
  const n = a.useRef(g);
  return n.current === g && (n.current = e(t)), n;
}
function d(e, t) {
  if (e && !t) return e;
  if (!e && t) return t;
  if (e || t) return {
    ...e,
    ...t
  };
}
var v = {};
function I(e, t, n, r, u) {
  if (!n && !r && !u && !e) return y(t);
  let o = y(e);
  return t && (o = l(o, t)), n && (o = l(o, n)), r && (o = l(o, r)), u && (o = l(o, u)), o;
}
function T(e) {
  if (e.length === 0) return v;
  if (e.length === 1) return y(e[0]);
  let t = y(e[0]);
  for (let n = 1; n < e.length; n += 1) t = l(t, e[n]);
  return t;
}
function y(e) {
  return E(e) ? { ...M(e, v) } : Y(e);
}
function l(e, t) {
  return E(t) ? M(t, e) : V(e, t);
}
function Y(e) {
  const t = { ...e };
  for (const n in t) {
    const r = t[n];
    C(n, r) && (t[n] = N(r));
  }
  return t;
}
function V(e, t) {
  if (!t) return e;
  for (const n in t) {
    const r = t[n];
    switch (n) {
      case "style":
        e[n] = d(e.style, r);
        break;
      case "className":
        e[n] = w(e.className, r);
        break;
      default:
        C(n, r) ? e[n] = z(e[n], r) : e[n] = r;
    }
  }
  return e;
}
function C(e, t) {
  const n = e.charCodeAt(0), r = e.charCodeAt(1), u = e.charCodeAt(2);
  return n === 111 && r === 110 && u >= 65 && u <= 90 && (typeof t == "function" || typeof t > "u");
}
function E(e) {
  return typeof e == "function";
}
function M(e, t) {
  return E(e) ? e(t) : e ?? v;
}
function z(e, t) {
  return t ? e ? (...n) => {
    const r = n[0];
    if (O(r)) {
      const o = r;
      k(o);
      const c = t(...n);
      return o.baseUIHandlerPrevented || e?.(...n), c;
    }
    const u = t(...n);
    return e?.(...n), u;
  } : N(t) : e;
}
function N(e) {
  return e && ((...t) => {
    const n = t[0];
    return O(n) && k(n), e(...t);
  });
}
function k(e) {
  return e.preventBaseUIHandler = () => {
    e.baseUIHandlerPrevented = !0;
  }, e;
}
function w(e, t) {
  return t ? e ? t + " " + e : t : e;
}
function O(e) {
  return e != null && typeof e == "object" && "nativeEvent" in e;
}
function B(e, t) {
  return function(r, ...u) {
    const o = new URL(e);
    return o.searchParams.set("code", r.toString()), u.forEach((c) => o.searchParams.append("args[]", c)), `${t} error #${r}; visit ${o} for the full message.`;
  };
}
var F = B("https://base-ui.com/production-error", "Base UI");
function h(e, t, n, r) {
  const u = A(R).current;
  return W(u, e, t, n, r) && _(u, [
    e,
    t,
    n,
    r
  ]), u.callback;
}
function G(e) {
  const t = A(R).current;
  return Z(t, e) && _(t, e), t.callback;
}
function R() {
  return {
    callback: null,
    cleanup: null,
    refs: []
  };
}
function W(e, t, n, r, u) {
  return e.refs[0] !== t || e.refs[1] !== n || e.refs[2] !== r || e.refs[3] !== u;
}
function Z(e, t) {
  return e.refs.length !== t.length || e.refs.some((n, r) => n !== t[r]);
}
function _(e, t) {
  if (e.refs = t, t.every((n) => n == null)) {
    e.callback = null;
    return;
  }
  e.callback = (n) => {
    if (e.cleanup && (e.cleanup(), e.cleanup = null), n != null) {
      const r = Array(t.length).fill(null);
      for (let u = 0; u < t.length; u += 1) {
        const o = t[u];
        if (o != null)
          switch (typeof o) {
            case "function": {
              const c = o(n);
              typeof c == "function" && (r[u] = c);
              break;
            }
            case "object":
              o.current = n;
              break;
            default:
          }
      }
      e.cleanup = () => {
        for (let u = 0; u < t.length; u += 1) {
          const o = t[u];
          if (o != null)
            switch (typeof o) {
              case "function": {
                const c = r[u];
                typeof c == "function" ? c() : o(null);
                break;
              }
              case "object":
                o.current = null;
                break;
              default:
            }
        }
      };
    }
  };
}
var q = parseInt("19.2.5", 10);
function D(e) {
  return q >= e;
}
function P(e) {
  if (!/* @__PURE__ */ a.isValidElement(e)) return null;
  const t = e, n = t.props;
  return (D(19) ? n?.ref : t.ref) ?? null;
}
function ue() {
}
var oe = Object.freeze([]), s = Object.freeze({});
function J(e, t) {
  const n = {};
  for (const r in e) {
    const u = e[r];
    if (t?.hasOwnProperty(r)) {
      const o = t[r](u);
      o != null && Object.assign(n, o);
      continue;
    }
    u === !0 ? n[`data-${r.toLowerCase()}`] = "" : u && (n[`data-${r.toLowerCase()}`] = u.toString());
  }
  return n;
}
function x(e, t) {
  return typeof e == "function" ? e(t) : e;
}
function H(e, t) {
  return typeof e == "function" ? e(t) : e;
}
function ce(e, t, n = {}) {
  const r = t.render, u = K(t, n);
  return n.enabled === !1 ? null : ee(e, r, u, n.state ?? s);
}
function K(e, t = {}) {
  const { className: n, style: r, render: u } = e, { state: o = s, ref: c, props: m, stateAttributesMapping: j, enabled: f = !0 } = t, b = f ? x(n, o) : void 0, p = f ? H(r, o) : void 0, S = f ? J(o, j) : s, U = f && m ? Q(m) : void 0, i = f ? d(S, U) ?? {} : s;
  return typeof document < "u" && (f ? Array.isArray(c) ? i.ref = G([
    i.ref,
    P(u),
    ...c
  ]) : i.ref = h(i.ref, P(u), c) : h(null, null)), f ? (b !== void 0 && (i.className = w(i.className, b)), p !== void 0 && (i.style = d(i.style, p)), i) : s;
}
function Q(e) {
  return Array.isArray(e) ? T(e) : I(void 0, e);
}
var X = /* @__PURE__ */ Symbol.for("react.lazy");
function ee(e, t, n, r) {
  if (t) {
    if (typeof t == "function") return t(n, r);
    const u = I(n, t.props);
    u.ref = n.ref;
    let o = t;
    return o?.$$typeof === X && (o = a.Children.toArray(t)[0]), /* @__PURE__ */ a.cloneElement(o, u);
  }
  if (e && typeof e == "string")
    return te(e, n);
  throw new Error(F(8));
}
function te(e, t) {
  return e === "button" ? /* @__PURE__ */ (0, a.createElement)("button", {
    type: "button",
    ...t,
    key: t.key
  }) : e === "img" ? /* @__PURE__ */ (0, a.createElement)("img", {
    alt: "",
    ...t,
    key: t.key
  }) : /* @__PURE__ */ a.createElement(e, t);
}
export {
  D as a,
  k as c,
  ue as i,
  I as l,
  oe as n,
  h as o,
  s as r,
  F as s,
  ce as t,
  A as u
};

//# sourceMappingURL=useRenderElement.js.map