var e={baseURL:window.smb2bAdmin?.apiUrl||`/wp-json/smb2b/v1`,nonce:window.smb2bAdmin?.nonce||``,headers:{"Content-Type":`application/json`,"X-WP-Nonce":window.smb2bAdmin?.nonce||``}},t=30*1e3,n=new class{constructor(){this.baseURL=e.baseURL,this.headers=e.headers,this._cache=new Map,this._inflight=new Map}async request(e,t={}){try{let n=`${this.baseURL}${e}`,r=await fetch(n,{...t,headers:this.headers}),i=r.headers.get(`content-type`),a=i&&i.includes(`application/json`);if(!r.ok){let e=`API Error: ${r.status} ${r.statusText}`;if(a)try{let t=await r.json();e=t.message||t.error||e}catch{}let t=Error(e);throw t.status=r.status,t}let o;if(a)o=await r.json();else{let e=(await r.text()).match(/\{[\s\S]*\}|\[[\s\S]*\]/);if(e)try{o=JSON.parse(e[0])}catch{throw Error(`Expected JSON response but received: ${i||`unknown`}`)}}return o}catch(e){throw window.smb2bAdmin&&window.smb2bAdmin.debug&&console.error(`API Request Failed:`,e),e}}async get(e,{fresh:n=!1}={}){if(!n){let n=this._cache.get(e);if(n&&Date.now()-n.at<t)return n.data;if(this._inflight.has(e))return this._inflight.get(e)}let r=this.request(e,{method:`GET`}).then(t=>(this._cache.set(e,{at:Date.now(),data:t}),t)).finally(()=>{this._inflight.delete(e)});return this._inflight.set(e,r),r}clearCache(){this._cache.clear()}async post(e,t){return this.clearCache(),this.request(e,{method:`POST`,body:JSON.stringify(t)})}async put(e,t){return this.clearCache(),this.request(e,{method:`PUT`,body:JSON.stringify(t)})}async delete(e){return this.clearCache(),this.request(e,{method:`DELETE`})}};export{n as t};