import{Time as t}from"../Time.js";import{checkArg as e}from"../checkArg.js";import{settings as r}from"./FormatSettings.js";import{DateFormatter as o,isValidTimeZone as i,ERR_TIME_ZONE_INVALID as a}from"./date.js";import{NumberFormatter as m}from"./number.js";import{TimeFormatter as n}from"./time.js";export{settings}from"./FormatSettings.js";export function format(t,...e){return s.format(t,...e)}export class StringFormatter{get numberFormat(){return this._numberFormat}set numberFormat(t){this._numberFormat=t}get dateFormat(){return this._dateFormat}set dateFormat(t){this._dateFormat=t}get timeFormat(){return this._timeFormat}set timeFormat(t){this._timeFormat=t}get currency(){return this._currency}set currency(t){this._currency=t}get fractionalDigits(){return this._fractionalDigits}set fractionalDigits(t){this._fractionalDigits=t}get timeZone(){return this._timeZone}set timeZone(t){null!=t&&e("timezone",t).satisfies((t=>i(t)),a(t)),this._timeZone=t}_numberFormat;_dateFormat;_timeFormat;_currency;_fractionalDigits;_timeZone;_numberFormatter=new m;_dateFormatter=new o;_timeFormatter=new n;format(r,...o){const i="string"==typeof r?{format:r}:r;e("options",i).isNotMissing();let{format:a}=i;e("format",a).isNotMissing(),a=a.replace(u,g);return a.replace(c,((r,a,m)=>{const n=parseInt(a);let s,c;try{e(`token ${a}`,a).isInRange(0,o.length-1),s=o[n]}catch(t){const e=parseInt(a,10);if(isNaN(e)||e<0)throw t;console.warn(`Error encountered while formatting string: ${t.message}`)}if("number"==typeof s){const t={locale:i.locale,format:m||i.numberFormat||this.numberFormat,currency:i.currency||this.currency,fractionalDigits:i.fractionalDigits??this.fractionalDigits};c=this._numberFormatter.format(t,s)}else if(s instanceof Date){const t={locale:i.locale,format:m||i.dateFormat||this.dateFormat,timeZone:i.timeZone||this.timeZone,isDateOnly:i.isDateOnly};c=this._dateFormatter.format(t,s)}else if(s instanceof t){const t={locale:i.locale,format:m||i.timeFormat||this.timeFormat};c=this._timeFormatter.format(t,s)}else c=null==s?"":String(s);return c})).replace(l,"{").replace("}}","}")}}const s=new class extends StringFormatter{get numberFormat(){return r.numberFormat}set numberFormat(t){r.numberFormat=t}get dateFormat(){return r.dateFormat}set dateFormat(t){r.dateFormat=t}get timeFormat(){return r.timeFormat}set timeFormat(t){r.timeFormat=t}get timeZone(){return r.timeZone}set timeZone(t){r.timeZone=t}get currency(){return r.currency}set currency(t){r.currency=t}get fractionalDigits(){return r.fractionalDigits}set fractionalDigits(t){r.fractionalDigits=t}},c=/\{([-\d]+)(?::([^}]*))?\}/g,u=/{{/g,g="\0MAGIC\0",l=new RegExp(g,"g");