import { getQuery as o, withQuery as a } from "ufo";
function i(t) {
  try {
    return new URL(t).origin !== window.location.origin;
  } catch {
    return !1;
  }
}
function c(t, e) {
  try {
    if (!i(t))
      return t;
    const n = o(t), r = {
      // 自身站点的 hostname
      utm_source: window.location.hostname,
      // 标记导航点击
      utm_medium: `${e}_nav`,
      // 全局导航统一标签
      utm_campaign: `global_${e}_menu`,
      // 目标站点标识
      utm_content: new URL(t).hostname,
      ...n
    };
    return a(t, r);
  } catch (n) {
    return console.error("Failed to generate UTM URL:", n), t;
  }
}
export {
  c as getUTMUrl
};
