import { jsx as h } from "react/jsx-runtime";
import { useThrottleFn as x } from "ahooks";
import { useRef as b, useState as v, useEffect as a } from "react";
const z = 8;
function C({ children: m, inline: i = !1, ...R }) {
  const n = b(null), s = b(null), [c, l] = v(!1), [g, f] = v(0), { run: d } = x(
    () => {
      if (i) {
        f(0), c || l(!0);
        return;
      }
      if (!n.current || !s.current) return;
      const e = n.current.parentElement;
      if (!e) return;
      const t = e.getBoundingClientRect(), u = s.current.getBoundingClientRect(), p = window.innerWidth, w = 32;
      let r = (t.width - u.width) / 2;
      const o = t.left + r;
      o < 0 ? r = r - o + w : o + u.width > p && (r -= o + u.width - p + w), f(r), c || l(!0);
    },
    {
      wait: 100
    }
  );
  return a(() => {
    const e = new ResizeObserver(() => {
      d();
    });
    return e.observe(n.current), () => e.disconnect();
  }, []), a(() => {
    const e = n.current?.parentElement;
    let t = null;
    return e && (t = new ResizeObserver(() => {
      d();
    }), t.observe(e)), () => t?.disconnect();
  }, []), a(() => {
    const e = () => {
      d();
    };
    return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
  }, []), /* @__PURE__ */ h(
    "div",
    {
      ref: n,
      className: "navmenu-sub__container",
      style: {
        width: "100%",
        paddingTop: `${z}px`,
        transform: `translateX(${g}px)`,
        overflow: c ? "visible" : "hidden"
      },
      ...R,
      children: /* @__PURE__ */ h(
        "div",
        {
          style: {
            display: i ? "block" : "inline-block",
            boxShadow: i ? "none" : "0px 40px 60px rgba(0, 0, 0, 0.08)"
          },
          ref: s,
          children: m
        }
      )
    }
  );
}
export {
  C as SubContainer,
  C as default
};
