"use client";
import * as u from "react";
import { createElement as g } from "react";
const v = {};
function A(e, n) {
  const t = u.useRef(v);
  return t.current === v && (t.current = e(n)), t;
}
let m;
process.env.NODE_ENV !== "production" && (m = /* @__PURE__ */ new Set());
function U(...e) {
  if (process.env.NODE_ENV !== "production") {
    const n = e.join(" ");
    m.has(n) || (m.add(n), console.warn(`Base UI: ${n}`));
  }
}
function V(e, n) {
  return function(c, ...r) {
    const o = new URL(e);
    return o.searchParams.set("code", c.toString()), r.forEach((i) => o.searchParams.append("args[]", i)), `${n} error #${c}; visit ${o} for the full message.`;
  };
}
const j = V("https://base-ui.com/production-error", "Base UI");
function w(e, n, t, c) {
  const r = A(C).current;
  return M(r, e, n, t, c) && I(r, [e, n, t, c]), r.callback;
}
function _(e) {
  const n = A(C).current;
  return T(n, e) && I(n, e), n.callback;
}
function C() {
  return {
    callback: null,
    cleanup: null,
    refs: []
  };
}
function M(e, n, t, c, r) {
  return e.refs[0] !== n || e.refs[1] !== t || e.refs[2] !== c || e.refs[3] !== r;
}
function T(e, n) {
  return e.refs.length !== n.length || e.refs.some((t, c) => t !== n[c]);
}
function I(e, n) {
  if (e.refs = n, n.every((t) => t == null)) {
    e.callback = null;
    return;
  }
  e.callback = (t) => {
    if (e.cleanup && (e.cleanup(), e.cleanup = null), t != null) {
      const c = Array(n.length).fill(null);
      for (let r = 0; r < n.length; r += 1) {
        const o = n[r];
        if (o != null)
          switch (typeof o) {
            case "function": {
              const i = o(t);
              typeof i == "function" && (c[r] = i);
              break;
            }
            case "object": {
              o.current = t;
              break;
            }
          }
      }
      e.cleanup = () => {
        for (let r = 0; r < n.length; r += 1) {
          const o = n[r];
          if (o != null)
            switch (typeof o) {
              case "function": {
                const i = c[r];
                typeof i == "function" ? i() : o(null);
                break;
              }
              case "object": {
                o.current = null;
                break;
              }
            }
        }
      };
    }
  };
}
const $ = parseInt(u.version, 10);
function L(e) {
  return $ >= e;
}
function N(e) {
  if (!/* @__PURE__ */ u.isValidElement(e))
    return null;
  const n = e, t = n.props;
  return (L(19) ? t?.ref : n.ref) ?? null;
}
function h(e, n) {
  if (e && !n)
    return e;
  if (!e && n)
    return n;
  if (e || n)
    return {
      ...e,
      ...n
    };
}
function S(e, n) {
  const t = {};
  for (const c in e) {
    const r = e[c];
    if (n?.hasOwnProperty(c)) {
      const o = n[c](r);
      o != null && Object.assign(t, o);
      continue;
    }
    r === !0 ? t[`data-${c.toLowerCase()}`] = "" : r && (t[`data-${c.toLowerCase()}`] = r.toString());
  }
  return t;
}
function B(e, n) {
  return typeof e == "function" ? e(n) : e;
}
function D(e, n) {
  return typeof e == "function" ? e(n) : e;
}
const d = {};
function Y(e, n, t, c, r) {
  let o = {
    ...E(e, d)
  };
  return n && (o = l(o, n)), t && (o = l(o, t)), c && (o = l(o, c)), r && (o = l(o, r)), o;
}
function z(e) {
  if (e.length === 0)
    return d;
  if (e.length === 1)
    return E(e[0], d);
  let n = {
    ...E(e[0], d)
  };
  for (let t = 1; t < e.length; t += 1)
    n = l(n, e[t]);
  return n;
}
function l(e, n) {
  return P(n) ? n(e) : F(e, n);
}
function F(e, n) {
  if (!n)
    return e;
  for (const t in n) {
    const c = n[t];
    switch (t) {
      case "style": {
        e[t] = h(e.style, c);
        break;
      }
      case "className": {
        e[t] = R(e.className, c);
        break;
      }
      default:
        G(t, c) ? e[t] = W(e[t], c) : e[t] = c;
    }
  }
  return e;
}
function G(e, n) {
  const t = e.charCodeAt(0), c = e.charCodeAt(1), r = e.charCodeAt(2);
  return t === 111 && c === 110 && r >= 65 && r <= 90 && (typeof n == "function" || typeof n > "u");
}
function P(e) {
  return typeof e == "function";
}
function E(e, n) {
  return P(e) ? e(n) : e ?? d;
}
function W(e, n) {
  return n ? e ? (t) => {
    if (J(t)) {
      const r = t;
      Z(r);
      const o = n(r);
      return r.baseUIHandlerPrevented || e?.(r), o;
    }
    const c = n(t);
    return e?.(t), c;
  } : n : e;
}
function Z(e) {
  return e.preventBaseUIHandler = () => {
    e.baseUIHandlerPrevented = !0;
  }, e;
}
function R(e, n) {
  return n ? e ? n + " " + e : n : e;
}
function J(e) {
  return e != null && typeof e == "object" && "nativeEvent" in e;
}
function ee() {
}
const ne = Object.freeze([]), f = Object.freeze({});
function te(e, n, t = {}) {
  const c = n.render, r = K(n, t);
  if (t.enabled === !1)
    return null;
  const o = t.state ?? f;
  return x(e, c, r, o);
}
function K(e, n = {}) {
  const {
    className: t,
    style: c,
    render: r
  } = e, {
    state: o = f,
    ref: i,
    props: p,
    stateAttributesMapping: k,
    enabled: a = !0
  } = n, y = a ? B(t, o) : void 0, b = a ? D(c, o) : void 0, O = a ? S(o, k) : f, s = a ? h(O, Array.isArray(p) ? z(p) : p) ?? f : f;
  return typeof document < "u" && (a ? Array.isArray(i) ? s.ref = _([s.ref, N(r), ...i]) : s.ref = w(s.ref, N(r), i) : w(null, null)), a ? (y !== void 0 && (s.className = R(s.className, y)), b !== void 0 && (s.style = h(s.style, b)), s) : f;
}
const q = /* @__PURE__ */ Symbol.for("react.lazy");
function x(e, n, t, c) {
  if (n) {
    if (typeof n == "function")
      return process.env.NODE_ENV !== "production" && H(n), n(t, c);
    const r = Y(t, n.props);
    r.ref = t.ref;
    let o = n;
    if (o?.$$typeof === q && (o = u.Children.toArray(n)[0]), process.env.NODE_ENV !== "production" && !/* @__PURE__ */ u.isValidElement(o))
      throw new Error(["Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.", "A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.", "https://base-ui.com/r/invalid-render-prop"].join(`
`));
    return /* @__PURE__ */ u.cloneElement(o, r);
  }
  if (e && typeof e == "string")
    return Q(e, t);
  throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: Render element or function are not defined." : j(8));
}
function H(e) {
  const n = e.name;
  if (n.length === 0)
    return;
  const t = n.charCodeAt(0);
  t < 65 || t > 90 || U(`The \`render\` prop received a function named \`${n}\` that starts with an uppercase letter.`, "This usually means a React component was passed directly as `render={Component}`.", "Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.", "If this is an intentional render callback, rename it to start with a lowercase letter.", "Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.", "https://base-ui.com/r/invalid-render-prop");
}
function Q(e, n) {
  return e === "button" ? /* @__PURE__ */ g("button", {
    type: "button",
    ...n,
    key: n.key
  }) : e === "img" ? /* @__PURE__ */ g("img", {
    alt: "",
    ...n,
    key: n.key
  }) : /* @__PURE__ */ u.createElement(e, n);
}
export {
  f as E,
  ee as N,
  A as a,
  ne as b,
  w as c,
  Z as d,
  j as f,
  L as i,
  Y as m,
  te as u,
  U as w
};
