// @bun
var{defineProperty:E,getOwnPropertyNames:H,getOwnPropertyDescriptor:I}=Object,J=Object.prototype.hasOwnProperty;function N(q){return this[q]}var R=(q)=>{var w=(G??=new WeakMap).get(q),z;if(w)return w;if(w=E({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var A of H(q))if(!J.call(w,A))E(w,A,{get:N.bind(q,A),enumerable:!(z=I(q,A))||z.enumerable})}return G.set(q,w),w},G;var O=(q)=>q;function P(q,w){this[q]=O.bind(null,w)}var T=(q,w)=>{for(var z in w)E(q,z,{get:w[z],enumerable:!0,configurable:!0,set:P.bind(w,z)})};var U=(q,w)=>()=>(q&&(w=q(q=0)),w);class Q{specs=new Map;latestByLocale=new Map;locales=new Set;domains=new Set;constructor(q){if(q)for(let w of q)this.register(w)}register(q){let w=this.makeKey(q.meta.key,q.meta.version,q.locale);this.specs.set(w,q);let z=`${q.meta.key}:${q.locale}`,A=this.latestByLocale.get(z);if(!A||this.isNewerVersion(q.meta.version,A.meta.version))this.latestByLocale.set(z,q);this.locales.add(q.locale),this.domains.add(q.meta.domain)}get(q,w,z){return this.specs.get(this.makeKey(q,w,z))}getLatest(q,w){return this.latestByLocale.get(`${q}:${w}`)}getMessage(q,w,z,A){let B=A?this.get(q,A,z):this.getLatest(q,z);if(!B)return;return B.messages[w]}getWithFallback(q,w,z,A,B){let D=B?this.get(q,B,z):this.getLatest(q,z);if(D){let C=D.messages[w];if(C)return{spec:D,message:C,locale:z,fromFallback:!1};A=A??D.fallback}if(A&&A!==z){let C=B?this.get(q,B,A):this.getLatest(q,A);if(C){let F=C.messages[w];if(F)return{spec:C,message:F,locale:A,fromFallback:!0}}}return}getValue(q,w,z,A){return this.getWithFallback(q,w,z)?.message.value??A??w}listLocales(q){let w=[];for(let[z,A]of this.specs.entries())if(z.startsWith(`${q}:`)){if(!w.includes(A.locale))w.push(A.locale)}return w}list(){return[...this.specs.values()]}listByLocale(q){return[...this.specs.values()].filter((w)=>w.locale===q)}listByDomain(q){return[...this.specs.values()].filter((w)=>w.meta.domain===q)}has(q,w,z){if(z)return this.specs.has(this.makeKey(q,z,w));return this.latestByLocale.has(`${q}:${w}`)}getLocales(){return this.locales}getDomains(){return this.domains}getStats(){let q=0;for(let w of this.specs.values())q+=Object.keys(w.messages).length;return{totalSpecs:this.specs.size,locales:[...this.locales],domains:[...this.domains],totalMessages:q}}clear(){this.specs.clear(),this.latestByLocale.clear(),this.locales.clear(),this.domains.clear()}makeKey(q,w,z){return`${q}:${w}:${z}`}isNewerVersion(q,w){let z=(D)=>{let C=D.split(".").map(Number);return{major:C[0]??0,minor:C[1]??0,patch:C[2]??0}},A=z(q),B=z(w);if(A.major!==B.major)return A.major>B.major;if(A.minor!==B.minor)return A.minor>B.minor;return A.patch>B.patch}}export{Q as TranslationRegistry};
