/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{makeHandle as n}from"../core/handleUtils.js";import"../core/has.js";let e,t;const a=globalThis.esriConfig?.locale,o=globalThis.document?.documentElement;function r(){const n=o?.getAttribute("lang"),e=globalThis.navigator?.language;return a??n??e??"en"}function i(){return void 0===t&&(t=r()),t}function l(n){e=n||void 0,x()}const c=/^(?<language>[a-z]{2,3})(?:-(?<extlang>[a-z]{3}))?(?:-[A-Z][a-z]{3})?(?:-(?<region>[A-Z]{2}|\d{3}))?(?:-.*)?$/;function u(n=i()){return g(n)?.language}function s(n=i()){const e=g(n);return e?.language&&e?.extlang?n.replace(`${e.language}-`,""):n}function g(n=i()){return c.exec(n)?.groups}function f(n=i()){const e=g(n)?.language;return"he"===e||"ar"===e}const h=[],d=new Map;function p(){const n=Array.from(d.values())[0];d.clear();const e=h.length;if(0!==e)throw h.length=0,new Error(`Unexpected ${e} locale change listeners still active.${n?` For example:\n${n}`:" Set enableListenerTracing in esri/intl/locale.ts to include a stack trace."}`)}function b(e){return h.push(e),n(()=>{h.splice(h.indexOf(e),1)})}const m=[];function v(e){return m.push(e),n(()=>m.splice(m.indexOf(e),1))}function x(){const n=e??r();t!==n&&([...m].forEach(e=>e(n)),t=n,[...h].forEach(e=>e(n)))}if(globalThis.addEventListener?.("languagechange",x),o){new MutationObserver(()=>{x()}).observe(o,{attributeFilter:["lang"]})}export{p as assertNoLocaleChangeListeners,v as beforeLocaleChange,r as getDefaultLocale,i as getLocale,u as getLocaleLanguage,g as getLocaleParts,s as normalizeLocale,b as onLocaleChange,f as prefersRTL,l as setLocale};
