import { jsx as o, jsxs as C, Fragment as y } from "react/jsx-runtime";
import { n as E, z as w, W as P, A as v, D as I, E as k, F as x, B as S } from "./PrizeCard-C2El3VOB.js";
import n from "react";
import { createPortal as B } from "react-dom";
const A = (t) => {
  var i;
  const [f, l] = n.useState(!1), [m, h] = n.useState(!1), s = n.useRef(
    `${t.packageName}-shadow-root-${Math.random().toString(36).substring(2, 11)}`
  ), r = n.useRef(null), a = n.useRef(null), e = n.useRef(null), c = n.useRef(null);
  n.useEffect(() => {
    E(t.language || "en").finally(() => h(!0));
  }, [t.language]), n.useEffect(() => {
    if (r.current)
      return r.current.shadowRoot ? (a.current = r.current.shadowRoot, e.current = a.current.getElementById(
        s.current
      ), e.current || (e.current = document.createElement("div"), e.current.id = s.current, a.current.appendChild(e.current))) : (a.current = r.current.attachShadow({ mode: "open" }), e.current = document.createElement("div"), e.current.id = s.current, a.current.appendChild(e.current)), c.current || (c.current = w({
        key: `${t.packageName}-css`,
        prepend: !0,
        container: a.current
      })), l(!0), () => {
        l(!1);
      };
  }, []);
  const u = t.themeOptions, d = {
    ...u,
    mode: t.template === P.OVERLAY ? "dark" : u == null ? void 0 : u.mode
  }, R = /* @__PURE__ */ o(S, { ref: r }), g = f && m && e.current && c.current ? B(
    /* @__PURE__ */ o(v, { value: c.current, children: /* @__PURE__ */ o(I, { containerRef: r, children: /* @__PURE__ */ o(
      k,
      {
        customTheme: d,
        mode: d == null ? void 0 : d.mode,
        shadowRootElement: e.current,
        children: /* @__PURE__ */ o(
          x,
          {
            shadowRootElement: e.current,
            leadPhoneCountryCode: ((i = t.leads) == null ? void 0 : i.phoneCountryCode) || null,
            language: t.language,
            optionsLayout: null,
            children: t.children
          }
        )
      }
    ) }) }),
    e.current
  ) : null;
  return /* @__PURE__ */ C(y, { children: [
    R,
    g
  ] });
};
export {
  A as P
};
