const i="en",g=["en","de","no"],L="PARAGLIDE_LOCALE";const m=["url","cookie","baseLocale"];globalThis.__paraglide={};let d=!1,f=()=>{let e;for(const o of m)if(o==="cookie"?e=b():o==="baseLocale"?e=i:o==="url"&&typeof window<"u"&&(e=p(window.location.href)),e!==void 0){const t=U(e);return d||(d=!0,y(t,{reload:!1})),t}throw new Error("No locale found. Read the docs https://inlang.com/m/gerre34r/library-inlang-paraglideJs/errors#no-locale-found")},y=(e,o)=>{const t={reload:!0,...o};let l;try{l=f()}catch{}let r;for(const n of m)if(n==="cookie"){if(typeof document>"u"||typeof window>"u")continue;const u=window.location.hostname;document.cookie=`${L}=${e}; path=/; max-age=34560000; domain=${u}`}else{if(n==="baseLocale")continue;n==="url"&&typeof window<"u"&&(r=c(window.location.href,{locale:e}).href)}t.reload&&window.location&&e!==l&&(r?window.location.href=r:window.location.reload())},s=()=>typeof window<"u"?window.location.origin:"http://fallback.com";function a(e){return e?g.includes(e):!1}function U(e){if(a(e)===!1)throw new Error(`Invalid locale: ${e}. Expected one of: ${g.join(", ")}`);return e}function b(){if(typeof document>"u"||!document.cookie)return;const e=document.cookie.match(new RegExp(`(^| )${L}=([^;]+)`)),o=e==null?void 0:e[2];if(a(o))return o}let h,w;function p(e){const o=typeof e=="string"?e:e.href;if(h===o)return w;let t;return t=k(e),h=o,w=t,t}function k(e){const t=new URL(e,"http://dummy.com").pathname.split("/").filter(Boolean);if(t.length>0){const l=t[0];if(a(l))return l}return i}function c(e,o){return x(e,o)}function x(e,o){const t=typeof e=="string"?new URL(e,s()):new URL(e),l=(o==null?void 0:o.locale)??f();if(p(t)===l)return t;const n=t.pathname.split("/").filter(Boolean);return n.length>0&&a(n[0])&&n.shift(),l===i?t.pathname="/"+n.join("/"):t.pathname="/"+l+"/"+n.join("/"),t}function j(e){return R(e)}function R(e){const o=typeof e=="string"?new URL(e,s()):new URL(e),t=o.pathname.split("/").filter(Boolean);return t.length>0&&a(t[0])&&(o.pathname="/"+t.slice(1).join("/")),o}function z(e,o){const t=f(),l=(o==null?void 0:o.locale)??t,r=new URL(e,s()),n=c(r,{locale:l});return e.startsWith("/")&&r.origin===n.origin?l!==t&&c(r,{locale:t}).origin!==n.origin?n.href:n.pathname+n.search+n.hash:n.href}export{z as a,j as d,g as l};
