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 u(t, n) {
  try {
    if (!i(t))
      return t;
    const e = o(t), r = {
      // 自身站点的 hostname
      utm_source: window.location.hostname,
      // 标记导航点击
      utm_medium: `${n}_nav`,
      // 全局导航统一标签
      utm_campaign: "default",
      // 目标站点标识
      utm_content: new URL(t).hostname,
      ...e
    };
    return a(t, r);
  } catch (e) {
    return console.error("Failed to generate UTM URL:", e), t;
  }
}
export {
  u as getUTMUrl
};
