import {
  STORE_EMAIL,
  get,
  set,
  sticker_default
} from "./chunk-VVZ5WFVG.mjs";
import {
  require_jsx_runtime
} from "./chunk-52PUK2GA.mjs";
import {
  require_react,
  require_react_dom
} from "./chunk-P6S5EUFT.mjs";
import {
  __toESM,
  init_buffer,
  init_process
} from "./chunk-AZLL6FY2.mjs";

// src/vividProvider/utils/runtime.tsx
init_process();
init_buffer();
var ReactDOM = __toESM(require_react_dom());

// src/vividProvider/components/VividLoader.tsx
init_process();
init_buffer();
var import_react2 = __toESM(require_react());

// src/analytics/hooks/useUser.ts
init_process();
init_buffer();
var import_react = __toESM(require_react());
var useUser = () => {
  const [email, setEmail] = (0, import_react.useState)(null);
  (0, import_react.useEffect)(() => {
    const loadEmail = async () => {
      var _a;
      const loadedEmail = (_a = await get(STORE_EMAIL)) != null ? _a : null;
      if (loadedEmail)
        setEmail(loadedEmail);
    };
    if (email === null)
      loadEmail();
    else
      set(STORE_EMAIL, email);
  }, [email]);
  return {
    email,
    setEmail
  };
};

// src/vividProvider/components/VividLoader.tsx
var import_jsx_runtime = __toESM(require_jsx_runtime());
var VividProvider = (0, import_react2.lazy)(
  () => import("./VividProvider-XPFJIZQI.mjs").then((v) => ({ default: v.VividProvider }))
);
var Loader = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
  "img",
  {
    style: {
      position: "fixed",
      left: "0.5em",
      bottom: "0.5em",
      width: "4em",
      height: "4em",
      zIndex: 10010,
      filter: "contrast(0.7) grayscale(1) drop-shadow(0 0 15px rgba(0,0,0,0.4))"
    },
    src: sticker_default
  }
);
var VividLoader = () => {
  const { email, setEmail } = useUser();
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: "vivid-root-app", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "font-sans font-normal border-box", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.Suspense, { fallback: Loader, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VividProvider, { email, setEmail }) }) }) });
};

// src/vividProvider/utils/runtime.tsx
var import_jsx_runtime2 = __toESM(require_jsx_runtime());
var run = () => {
  if (typeof document !== "undefined" && !window.hasOwnProperty("VIVID_MOUNTED")) {
    window.VIVID_MOUNTED = true;
    const rootDiv = document.createElement("div");
    document.body.prepend(rootDiv);
    if (ReactDOM.version.slice(0, 2) === "17") {
      ReactDOM.render(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VividLoader, {}), rootDiv);
    } else {
      import("./client-IBO5HO2A.mjs").then((ReactDOMClient) => {
        ReactDOMClient.default.createRoot(rootDiv).render(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(VividLoader, {}));
      });
    }
  }
};
export {
  run
};
