import{checkArg as t}from"./utilities/checkArg.js";export const INVARIANT="inv";let e="inv";export function get(){return e}export function set(r){t("locale",r).isNotMissing().isNotEmpty(),e=r}export function detectLocale(){return navigator.language||"inv"}export function getMatchingLocales(t){let e;try{e=parseLocale(function(t){const e=parseLocale(t);let r=e.language;e.script&&(r+=`-${e.script}`);e.territory&&(r+=`-${e.territory}`);return r}(t))}catch{return[]}const r=[t];if(e.script){const t=`${e.language}-${e.script}`;r.includes(t)||r.push(t)}if(e.territory){const t=`${e.language}-${e.territory}`;r.includes(t)||r.push(t)}return r.includes(e.language)||r.push(e.language),r.push("inv"),r}export function parseLocale(t){if("string"!=typeof t)throw new Error("Invalid locale.");const e=t.split("-");if(e.length<1||e.length>3||e.some((t=>0===t.length)))throw new Error(`Invalid locale: ${t}`);const r={language:e[0].toLowerCase()};return 2===e.length?2===e[1].length?r.territory=e[1].toUpperCase():r.script=e[1][0].toUpperCase()+e[1].slice(1).toLowerCase():3===e.length&&(r.script=e[1][0].toUpperCase()+e[1].slice(1).toLowerCase(),r.territory=e[2].toUpperCase()),r}