import{INVARIANT as e,get as t,getMatchingLocales as s}from"../locale.js";import{checkArg as i}from"../utilities/checkArg.js";import{format as n}from"../utilities/format/string.js";const a=new Map;a.set("inv",{"gcx.api.data.convert.import-field-alias":"field{0}","gcx.api.mapping.kml-sublayer-extension.schema.id":"ID","gcx.api.mapping.kml-sublayer-extension.schema.name":"Name","gcx.api.mapping.kml-sublayer-extension.schema.description":"Description","gcx.api.mapping.kml-sublayer-extension.schema.visibility":"Visibility","gcx.api.mapping.kml-sublayer-extension.schema.balloonStyleText":"Popup Description","gcx.api.mapping.kml-sublayer-extension.schema.styleUrl":"Style Url"});export class LanguageRegistry{defaultLocale=e;_registeredStrings=new Map;localeKeyJoin="\0KEY\0";add(e){i("resources",e).isNotMissing();for(const t of e.values.keys()){const s=this._createUniqueKey(t,e.locale);this._registeredStrings.set(s,e.values.get(t))}}get(e,...t){let s;i("options",e).isNotMissing(),s="string"==typeof e?{key:e}:{...e};const o=this._getLocales(s.locale);let r;for(const e of o){const i=this._createUniqueKey(s.key,e);if(r=this._registeredStrings.get(i)??a.get(e)?.[s.key],"string"==typeof r){const e={...s,format:r,locale:s.locale};return n(e,...t)}}}has(e){let t;t="string"==typeof e?{key:e}:{...e};const s=this._getLocales(t.locale);for(const e of s){const s=this._createUniqueKey(t.key,e);if(this._registeredStrings.has(s)||void 0!==a.get(e)?.[t.key])return!0}return!1}_createUniqueKey(e,t){return`${t}${this.localeKeyJoin}${e}`}_getLocales(i){const n=s(i??t());if(!n.includes(this.defaultLocale)){const t=n.indexOf(e),i=s(this.defaultLocale);t<0?n.push(...i):n.splice(t,0,...i)}return n.includes(e)||n.push(e),n}}const o=new LanguageRegistry;export function registerLanguageResources(e){o.add(e)}export function setDefaultLocale(e){o.defaultLocale=e}export function translate(e,...t){return o.get(e,...t)}export function isRegisteredLanguageResource(e,t){return o.has({key:e,locale:t})}