import { defineComponent, inject, withDirectives, cloneVNode, Fragment, Text, Comment, createVNode } from "vue";
import { NOOP as n$1, isObject as i } from "../../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import { FORWARD_REF_INJECTION_KEY as n, useForwardRefDirective as s } from "../../../hooks/use-forward-ref/index.mjs";
import { useNamespace as q } from "../../../hooks/use-namespace/index.mjs";
const o = "ElOnlyChild", T = defineComponent({
  name: o,
  setup(r, {
    slots: n$2,
    attrs: e
  }) {
    var i2;
    const l = inject(n), s$1 = s((i2 = l == null ? void 0 : l.setForwardRef) != null ? i2 : n$1);
    return () => {
      var c;
      const t = (c = n$2.default) == null ? void 0 : c.call(n$2, e);
      if (!t)
        return null;
      if (t.length > 1)
        return null;
      const u = f(t);
      return u ? withDirectives(cloneVNode(u, e), [[s$1]]) : null;
    };
  }
});
function f(r) {
  if (!r)
    return null;
  const n2 = r;
  for (const e of n2) {
    if (i(e))
      switch (e.type) {
        case Comment:
          continue;
        case Text:
        case "svg":
          return d(e);
        case Fragment:
          return f(e.children);
        default:
          return e;
      }
    return d(e);
  }
  return null;
}
function d(r) {
  const n2 = q("only-child");
  return createVNode("span", {
    class: n2.e("content")
  }, [r]);
}
export {
  T as OnlyChild
};
