import * as e from "react";
import y from "../../../rc-util/es/hooks/useMergedState.mjs";
import R from "../config-provider/index.mjs";
import { ConfigContext as z } from "../config-provider/context.mjs";
function E(r) {
  return (s) => /* @__PURE__ */ e.createElement(R, {
    theme: {
      token: {
        motion: !1,
        zIndexPopupBase: 0
      }
    }
  }, /* @__PURE__ */ e.createElement(r, Object.assign({}, s)));
}
const H = (r, s, c, l) => E((o) => {
  const {
    prefixCls: g,
    style: v
  } = o, i = e.useRef(null), [P, b] = e.useState(0), [h, O] = e.useState(0), [u, C] = y(!1, {
    value: o.open
  }), {
    getPrefixCls: x
  } = e.useContext(z), f = x(s || "select", g);
  e.useEffect(() => {
    if (C(!0), typeof ResizeObserver < "u") {
      const p = new ResizeObserver((t) => {
        const n = t[0].target;
        b(n.offsetHeight + 8), O(n.offsetWidth);
      }), d = setInterval(() => {
        var t;
        const n = c ? `.${c(f)}` : `.${f}-dropdown`, m = (t = i.current) === null || t === void 0 ? void 0 : t.querySelector(n);
        m && (clearInterval(d), p.observe(m));
      }, 10);
      return () => {
        clearInterval(d), p.disconnect();
      };
    }
  }, []);
  let a = Object.assign(Object.assign({}, o), {
    style: Object.assign(Object.assign({}, v), {
      margin: 0
    }),
    open: u,
    visible: u,
    getPopupContainer: () => i.current
  });
  l && (a = l(a));
  const j = {
    paddingBottom: P,
    position: "relative",
    minWidth: h
  };
  return /* @__PURE__ */ e.createElement("div", {
    ref: i,
    style: j
  }, /* @__PURE__ */ e.createElement(r, Object.assign({}, a)));
});
export {
  H as default,
  E as withPureRenderTheme
};
