import { withQuery } from "ufo";
import { useRegistryScript } from "../utils.mjs";
import { object, string } from "#nuxt-scripts-validator";
const GoogleTagManagerOptions = object({
  id: string()
});
export function useScriptGoogleTagManager(options) {
  return useRegistryScript("googleTagManager", (options2) => ({
    scriptInput: {
      async: true,
      src: withQuery("https://www.googletagmanager.com/gtm.js", {
        id: options2?.id
      })
    },
    schema: import.meta.dev ? GoogleTagManagerOptions : void 0,
    scriptOptions: {
      use() {
        return { dataLayer: window.dataLayer, google_tag_manager: window.google_tag_manager };
      },
      // allow dataLayer to be accessed on the server
      stub: import.meta.client ? void 0 : ({ fn }) => {
        return fn === "dataLayer" ? [] : void 0;
      }
    },
    clientInit: import.meta.server ? void 0 : () => {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({ "gtm.start": (/* @__PURE__ */ new Date()).getTime(), "event": "gtm.js" });
    }
  }), options);
}
