var l=new Set,i=new Map,s,c="ltr",u="en",m=typeof MutationObserver!="undefined"&&typeof document!="undefined"&&typeof document.documentElement!="undefined";if(m){let o=new MutationObserver(f);c=document.documentElement.dir||"ltr",u=document.documentElement.lang||navigator.language,o.observe(document.documentElement,{attributes:!0,attributeFilter:["dir","lang"]})}function b(...o){o.map(e=>{let t=e.$code.toLowerCase();i.has(t)?i.set(t,Object.assign(Object.assign({},i.get(t)),e)):i.set(t,e),s||(s=e)}),f()}function f(){m&&(c=document.documentElement.dir||"ltr",u=document.documentElement.lang||navigator.language),[...l.keys()].map(o=>{typeof o.requestUpdate=="function"&&o.requestUpdate()})}var g=class{constructor(e){this.host=e,this.host.addController(this)}hostConnected(){l.add(this.host)}hostDisconnected(){l.delete(this.host)}dir(){return`${this.host.dir||c}`.toLowerCase()}lang(){return`${this.host.lang||u}`.toLowerCase()}getTranslationData(e){var t,n;let r;try{r=new Intl.Locale(e.replace(/_/g,"-"))}catch(v){return{locale:void 0,language:"",region:"",primary:void 0,secondary:void 0}}let a=r.language.toLowerCase(),d=(n=(t=r.region)===null||t===void 0?void 0:t.toLowerCase())!==null&&n!==void 0?n:"",h=i.get(`${a}-${d}`),p=i.get(a);return{locale:r,language:a,region:d,primary:h,secondary:p}}exists(e,t){var n;let{primary:r,secondary:a}=this.getTranslationData((n=t.lang)!==null&&n!==void 0?n:this.lang());return t=Object.assign({includeFallback:!1},t),!!(r&&r[e]||a&&a[e]||t.includeFallback&&s&&s[e])}term(e,...t){let{primary:n,secondary:r}=this.getTranslationData(this.lang()),a;if(n&&n[e])a=n[e];else if(r&&r[e])a=r[e];else if(s&&s[e])a=s[e];else return console.error(`No translation found for: ${String(e)}`),String(e);return typeof a=="function"?a(...t):a}date(e,t){return e=new Date(e),new Intl.DateTimeFormat(this.lang(),t).format(e)}number(e,t){return e=Number(e),isNaN(e)?"":new Intl.NumberFormat(this.lang(),t).format(e)}relativeTime(e,t,n){return new Intl.RelativeTimeFormat(this.lang(),n).format(e,t)}};export{b as a,g as b};
