import { jsx } from "react/jsx-runtime";
import { useState, useEffect } from "react";
import { fetchHostAppData } from "../fetch-host-app-data/index.js";
import { WaitMessageLauncher } from "../wait-message/wait-message-launcher.js";
const renderWithHostData = (data) => {
  const {
    ComponentToRender,
    guestAppId,
    hostedAppUrl = document.referrer
  } = data;
  const HostAppDataWrapper = () => {
    const [loading, setLoading] = useState(true);
    useEffect(() => {
      if (hostedAppUrl) {
        fetchHostAppData(hostedAppUrl, guestAppId).then(() => {
          setLoading(false);
        }).catch(() => {
        });
      } else {
        setLoading(false);
      }
    }, []);
    return loading ? /* @__PURE__ */ jsx(WaitMessageLauncher, {}) : /* @__PURE__ */ jsx(ComponentToRender, {});
  };
  return HostAppDataWrapper;
};
export {
  renderWithHostData
};
