import R from "../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/formatErrorMessage.js";
import * as P from "react";
import { createElement as d } from "react";
import { useMergedRefs as p, useMergedRefsN as b } from "../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/useMergedRefs.js";
import { getReactElementRef as y } from "../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/getReactElementRef.js";
import { mergeObjects as g } from "../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/mergeObjects.js";
import { getStateAttributesProps as A } from "./getStateAttributesProps.js";
import { resolveClassName as M } from "./resolveClassName.js";
import { resolveStyle as k } from "./resolveStyle.js";
import { EMPTY_OBJECT as f } from "../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/empty.js";
import { mergePropsN as v, mergeClassNames as C, mergeProps as O } from "../merge-props/mergeProps.js";
function Y(r, e, t = {}) {
  const i = e.render, o = w(e, t);
  if (t.enabled === !1)
    return null;
  const m = t.state ?? f;
  return B(r, i, o, m);
}
function w(r, e = {}) {
  const {
    className: t,
    style: i,
    render: o
  } = r, {
    state: m = f,
    ref: u,
    props: a,
    stateAttributesMapping: E,
    enabled: s = !0
  } = e, l = s ? M(t, m) : void 0, c = s ? k(i, m) : void 0, N = s ? A(m, E) : f, n = s ? g(N, Array.isArray(a) ? v(a) : a) ?? f : f;
  return typeof document < "u" && (s ? Array.isArray(u) ? n.ref = b([n.ref, y(o), ...u]) : n.ref = p(n.ref, y(o), u) : p(null, null)), s ? (l !== void 0 && (n.className = C(n.className, l)), c !== void 0 && (n.style = g(n.style, c)), n) : f;
}
function B(r, e, t, i) {
  if (e) {
    if (typeof e == "function")
      return e(t, i);
    const o = O(t, e.props);
    return o.ref = t.ref, /* @__PURE__ */ P.cloneElement(e, o);
  }
  if (r && typeof r == "string")
    return S(r, t);
  throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: Render element or function are not defined." : R(8));
}
function S(r, e) {
  return r === "button" ? /* @__PURE__ */ d("button", {
    type: "button",
    ...e,
    key: e.key
  }) : r === "img" ? /* @__PURE__ */ d("img", {
    alt: "",
    ...e,
    key: e.key
  }) : /* @__PURE__ */ P.createElement(r, e);
}
export {
  Y as useRenderElement
};
