import { withQuery } from "ufo";
import { useRegistryScript } from "#nuxt-scripts-utils";
import { object, string } from "#nuxt-scripts-validator";
export const GoogleTagManagerOptions = object({ id: string() });
export function useScriptGoogleTagManager(_options) {
  return useRegistryScript(_options?.key || "google-tag-manager", (options) => ({
    scriptInput: {
      src: withQuery("https://www.googletagmanager.com/gtm.js", { id: options?.id })
    },
    schema: import.meta.dev ? void 0 : GoogleTagManagerOptions,
    scriptOptions: {
      use: () => {
        return { dataLayer: window.dataLayer, google_tag_manager: window.google_tag_manager };
      },
      stub: import.meta.client ? void 0 : ({ fn }) => {
        return fn === "dataLayer" ? [] : void 0;
      },
      performanceMarkFeature: "nuxt-third-parties-gtm",
      ...{ tagPriority: 1 }
    },
    // eslint-disable-next-line
    clientInit: import.meta.server ? void 0 : () => {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({ "gtm.start": (/* @__PURE__ */ new Date()).getTime(), event: "gtm.js" });
    }
  }), _options);
}
