import { Env as s } from "./accelbyte-widgets108.mjs";
import { UrlHelper as n, DesktopChecker as U } from "@accelbyte/sdk";
import h from "validator/lib/isURL.js";
const a = class {
  static silentUrlBuilder(r) {
    try {
      return new URL(r);
    } catch {
      return null;
    }
  }
  static silentSearchParamsBuilder(r) {
    try {
      return new URLSearchParams(r);
    } catch {
      return new URLSearchParams("");
    }
  }
  static makeAbsolutePath(r) {
    return `/${n.trimSlashFromStringStart(r)}`;
  }
  static transformToValidURLOrUndefined(r) {
    try {
      if (r)
        return new URL(r);
    } catch {
    }
  }
  static isValidUrl(r) {
    return typeof r != "string" ? !1 : h(r, {
      protocols: ["http", "https"],
      require_tld: !1
    }) && r;
  }
  static isImageURL(r) {
    return !!this.isValidUrl(r) && r.match(/\.(jpeg|jpg|gif|png)$/) != null;
  }
  static getCurrentPathWithNoBaseName() {
    return window.location.pathname.slice(s.PLAYER_PORTAL_BASE_URL.length);
  }
  static getRedirectUrl(r, t) {
    return U.isDesktopApp() ? `${r}${n.trimSlashFromStringStart(t)}` : `${n.combineURLPaths(r, t)}`;
  }
  static getRouterRedirection(r, t) {
    const e = new URL(r), l = new URL(t), o = e.origin === window.location.origin, c = e.origin === l.origin;
    return o || s.IS_DEV_MODE && c ? `${e.pathname}${e.search}` : null;
  }
};
let i = a;
i.stripColonFromProtocol = (r) => r[r.length - 1] === ":" ? r.slice(0, r.length - 1) : r;
i.checkUrlValidity = (r, t = !0) => a.isValidUrl2(r, t) ? null : `${r} is not a valid URL.`;
i.isValidUrl2 = (r, t = !0) => {
  try {
    return Boolean(new URL(r));
  } catch (e) {
    return t && console.error(e), !1;
  }
};
i.fixUrl = (r) => a.isValidUrl2(r, !1) ? r : `https://${r}`;
i.buildURLSearchParamsFromObject = (r) => {
  const t = {};
  for (const e in r)
    r[e] && (t[e] = `${r[e]}`);
  return new URLSearchParams(t);
};
export {
  i as UrlUtils
};
