import { Fragment, jsx } from "react/jsx-runtime";
import { useEffect, isValidElement } from "react";
import Head from "next/head";
import Script from "next/script";
import {
  snippetToElements,
  getSnippetElementsFromDOM,
  cleanUpSnippet
} from "../../../../runtimes/react/components/page/HeadSnippet";
const isScriptElement = (element) => isValidElement(element) && element.type === "script";
function HeadSnippet({ snippet }) {
  useEffect(() => {
    return () => {
      const snippetElements = getSnippetElementsFromDOM(snippet);
      if (snippetElements.length > 0)
        return;
      cleanUpSnippet(snippet);
    };
  }, [snippet]);
  const headSnippetElements = snippetToElements(snippet);
  return /* @__PURE__ */ jsx(Fragment, { children: headSnippetElements.map(
    (element, i) => isScriptElement(element) ? /* @__PURE__ */ jsx(Script, { ...element.props, strategy: "beforeInteractive" }, element.key) : /* @__PURE__ */ jsx(Head, { children: element }, isValidElement(element) ? element.key : i)
  ) });
}
export {
  HeadSnippet
};
//# sourceMappingURL=HeadSnippet.js.map