const e=new Set,t=new Map;let n,o="ltr",a="en";const r="undefined"!=typeof MutationObserver&&"undefined"!=typeof document&&void 0!==document.documentElement;if(r){const i=new MutationObserver(update);o=document.documentElement.dir||"ltr",a=document.documentElement.lang||navigator.language,i.observe(document.documentElement,{attributes:!0,attributeFilter:["dir","lang"]})}export function registerTranslation(...e){e.map((e=>{const o=e.$code.toLowerCase();t.has(o)?t.set(o,Object.assign(Object.assign({},t.get(o)),e)):t.set(o,e),n||(n=e)})),update()}export function update(){r&&(o=document.documentElement.dir||"ltr",a=document.documentElement.lang||navigator.language),[...e.keys()].map((e=>{"function"==typeof e.requestUpdate&&e.requestUpdate()}))}export class LocalizeController{constructor(e){this.host=e,this.host.addController(this)}hostConnected(){e.add(this.host)}hostDisconnected(){e.delete(this.host)}dir(){return`${this.host.dir||o}`.toLowerCase()}lang(){return`${this.host.lang||a}`.toLowerCase()}getTranslationData(e){var n,o;const a=new Intl.Locale(e.replace(/_/g,"-")),r=null==a?void 0:a.language.toLowerCase(),i=null!==(o=null===(n=null==a?void 0:a.region)||void 0===n?void 0:n.toLowerCase())&&void 0!==o?o:"";return{locale:a,language:r,region:i,primary:t.get(`${r}-${i}`),secondary:t.get(r)}}exists(e,t){var o;const{primary:a,secondary:r}=this.getTranslationData(null!==(o=t.lang)&&void 0!==o?o:this.lang());return t=Object.assign({includeFallback:!1},t),!!(a&&a[e]||r&&r[e]||t.includeFallback&&n&&n[e])}term(e,...t){const{primary:o,secondary:a}=this.getTranslationData(this.lang());let r;if(o&&o[e])r=o[e];else if(a&&a[e])r=a[e];else{if(!n||!n[e])return console.error(`No translation found for: ${String(e)}`),String(e);r=n[e]}return"function"==typeof r?r(...t):r}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)}}