import "@seamless/logger";
import { a as p, L as d } from "./initialize-logger.mjs";
import { g as L } from "./shared-logger.mjs";
function P({
  path: e,
  hash: n,
  baseUrl: r,
  searchParams: h,
  localeOverride: a,
  preserveExistingParams: u = !1
}) {
  const s = R(e);
  if (s instanceof URL)
    return s;
  const { hash: c, pathname: l } = U(s), t = new URL(m(r));
  u || (t.search = "");
  let i = w(t.pathname);
  a && (i = a.country ? `${a.language}_${a.country}` : a.language), t.pathname = i ? `/${i}${l}` : l, t.hash = "";
  const o = n ?? c;
  return o && (t.hash = o.startsWith("#") ? o : `#${o}`), h && Object.entries(h).forEach(([g, f]) => {
    t.searchParams.set(g, String(f));
  }), t;
}
function m(e) {
  if (e)
    return e;
  const n = globalThis.window;
  if (n !== void 0)
    return n.location.href;
  throw new Error("buildOneWebURL requires baseUrl when window is not available.");
}
function w(e) {
  const n = e.split("/").find(Boolean);
  if (!n)
    return;
  if (n.length === 2)
    return n;
  const r = n.split("_");
  return r.length === 2 && r[0]?.length === 2 && r[1]?.length === 2 ? n : void 0;
}
function R(e) {
  try {
    const n = new URL(e);
    return L()(
      'buildOneWebURL received a full URL instead of a pathname. Please provide only the path portion (e.g., "/passengercars/my-area") for proper locale handling. Returning the URL as-is without locale or query parameter processing.',
      {
        args: [e],
        group: d.UTILS,
        level: p.WARN
      }
    ), n;
  } catch {
    return e.startsWith("/") ? e : `/${e}`;
  }
}
function U(e) {
  const n = e.indexOf("#");
  return n === -1 ? { pathname: e } : {
    pathname: e.slice(0, n),
    hash: e.slice(n)
  };
}
export {
  P as b
};
//# sourceMappingURL=build-oneweb-url.mjs.map
