import { getToken as r } from "@das-fed/utils/common-info";
const s = (t) => {
  try {
    return new URL(t, location.origin).origin === location.origin;
  } catch {
    return !0;
  }
}, h = (t) => {
  if (!t) return "";
  if (!s(t)) return t;
  try {
    const e = new URL(t, location.origin);
    return e.searchParams.has("showLayout") || e.searchParams.set("showLayout", "false"), e.searchParams.has("ignoreAuth") || e.searchParams.set("ignoreAuth", "true"), e.toString();
  } catch {
    const e = /([?&])showLayout=/.test(t), a = /([?&])ignoreAuth=/.test(t), o = [];
    if (e || o.push("showLayout=false"), a || o.push("ignoreAuth=true"), o.length === 0) return t;
    const n = t.includes("?") ? "&" : "?";
    return t + n + o.join("&");
  }
}, c = (t) => {
  if (!t) return "";
  if (!s(t)) return t;
  try {
    const e = new URL(t, location.origin);
    return e.searchParams.get("showWatermark") !== "false" && e.searchParams.set("showWatermark", "false"), e.toString();
  } catch {
    return t.includes("showWatermark=false") ? t : t.indexOf("?") !== -1 ? t + "&showWatermark=false" : t + "?showWatermark=false";
  }
}, f = (t) => {
  const e = r();
  return t.includes("?") ? `${t}&token=${e}` : `${t}?token=${e}`;
};
export {
  s as isRelativeOrSameDomain,
  h as setShowLayout,
  c as setShowWatermark,
  f as withToken
};
