import * as i from "react";
import * as m from "react-dom";
import { c as v } from "./index-DLcqcWxM.mjs";
import { jsx as p } from "react/jsx-runtime";
import { b as y } from "./index-DOfn3ixy.mjs";
// @__NO_SIDE_EFFECTS__
function E(e) {
  const t = /* @__PURE__ */ h(e), r = i.forwardRef((o, n) => {
    const { children: s, ...c } = o, l = i.Children.toArray(s), u = l.find(R);
    if (u) {
      const d = u.props.children, f = l.map((a) => a === u ? i.Children.count(d) > 1 ? i.Children.only(null) : i.isValidElement(d) ? d.props.children : null : a);
      return /* @__PURE__ */ p(t, { ...c, ref: n, children: i.isValidElement(d) ? i.cloneElement(d, void 0, f) : null });
    }
    return /* @__PURE__ */ p(t, { ...c, ref: n, children: s });
  });
  return r.displayName = `${e}.Slot`, r;
}
// @__NO_SIDE_EFFECTS__
function h(e) {
  const t = i.forwardRef((r, o) => {
    const { children: n, ...s } = r;
    if (i.isValidElement(n)) {
      const c = g(n), l = S(s, n.props);
      return n.type !== i.Fragment && (l.ref = o ? v(o, c) : c), i.cloneElement(n, l);
    }
    return i.Children.count(n) > 1 ? i.Children.only(null) : null;
  });
  return t.displayName = `${e}.SlotClone`, t;
}
var C = /* @__PURE__ */ Symbol("radix.slottable");
function R(e) {
  return i.isValidElement(e) && typeof e.type == "function" && "__radixId" in e.type && e.type.__radixId === C;
}
function S(e, t) {
  const r = { ...t };
  for (const o in t) {
    const n = e[o], s = t[o];
    /^on[A-Z]/.test(o) ? n && s ? r[o] = (...l) => {
      const u = s(...l);
      return n(...l), u;
    } : n && (r[o] = n) : o === "style" ? r[o] = { ...n, ...s } : o === "className" && (r[o] = [n, s].filter(Boolean).join(" "));
  }
  return { ...e, ...r };
}
function g(e) {
  let t = Object.getOwnPropertyDescriptor(e.props, "ref")?.get, r = t && "isReactWarning" in t && t.isReactWarning;
  return r ? e.ref : (t = Object.getOwnPropertyDescriptor(e, "ref")?.get, r = t && "isReactWarning" in t && t.isReactWarning, r ? e.props.ref : e.props.ref || e.ref);
}
var b = [
  "a",
  "button",
  "div",
  "form",
  "h2",
  "h3",
  "img",
  "input",
  "label",
  "li",
  "nav",
  "ol",
  "p",
  "select",
  "span",
  "svg",
  "ul"
], W = b.reduce((e, t) => {
  const r = /* @__PURE__ */ E(`Primitive.${t}`), o = i.forwardRef((n, s) => {
    const { asChild: c, ...l } = n, u = c ? r : t;
    return typeof window < "u" && (window[/* @__PURE__ */ Symbol.for("radix-ui")] = !0), /* @__PURE__ */ p(u, { ...l, ref: s });
  });
  return o.displayName = `Primitive.${t}`, { ...e, [t]: o };
}, {});
function _(e, t) {
  e && m.flushSync(() => e.dispatchEvent(t));
}
function j(e, t, { checkForDefaultPrevented: r = !0 } = {}) {
  return function(n) {
    if (e?.(n), r === !1 || !n.defaultPrevented)
      return t?.(n);
  };
}
var P = i[" useInsertionEffect ".trim().toString()] || y;
function A({
  prop: e,
  defaultProp: t,
  onChange: r = () => {
  },
  caller: o
}) {
  const [n, s, c] = w({
    defaultProp: t,
    onChange: r
  }), l = e !== void 0, u = l ? e : n;
  {
    const f = i.useRef(e !== void 0);
    i.useEffect(() => {
      const a = f.current;
      a !== l && console.warn(
        `${o} is changing from ${a ? "controlled" : "uncontrolled"} to ${l ? "controlled" : "uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
      ), f.current = l;
    }, [l, o]);
  }
  const d = i.useCallback(
    (f) => {
      if (l) {
        const a = D(f) ? f(e) : f;
        a !== e && c.current?.(a);
      } else
        s(f);
    },
    [l, e, s, c]
  );
  return [u, d];
}
function w({
  defaultProp: e,
  onChange: t
}) {
  const [r, o] = i.useState(e), n = i.useRef(r), s = i.useRef(t);
  return P(() => {
    s.current = t;
  }, [t]), i.useEffect(() => {
    n.current !== r && (s.current?.(r), n.current = r);
  }, [r, n]), [r, o, s];
}
function D(e) {
  return typeof e == "function";
}
export {
  W as P,
  E as a,
  j as c,
  _ as d,
  A as u
};
//# sourceMappingURL=index-DCcK_d4W.mjs.map
