import{ot as e}from"./vue.esm-bundler-DcNPjsgv.js";function t(){let t=e(!1),n=e(null),r=window.BuyMeCoffeeAdmin||{};function i(e){let t=new FormData;function n(e,r=``){e&&typeof e==`object`&&!(e instanceof File)?Object.keys(e).forEach(t=>{let i=r?`${r}[${t}]`:t;n(e[t],i)}):t.append(r,e??``)}return n(e),t}function a(e){let t=new URLSearchParams;function n(e,r=``){e&&typeof e==`object`&&!(e instanceof File)?Object.keys(e).forEach(t=>{let i=r?`${r}[${t}]`:t;n(e[t],i)}):r&&t.append(r,e??``)}return n(e),t}async function o(e,t={},n){let o=r.ajaxurl;if(!o)throw Error(`AJAX URL not configured`);let l={method:e,signal:n};if(e===`GET`){let e=a(t).toString(),n=e?`${o}?${e}`:o,r=await fetch(n,l);if(!r.ok)throw Error(await c(r));return s(r)}l.body=i(t);let u=await fetch(o,l);if(!u.ok)throw Error(await c(u));return s(u)}async function s(e){let t=await e.text();if(!t)throw Error(`The server returned an empty response. Please refresh and try again.`);try{return JSON.parse(t)}catch{throw Error(`The server returned an invalid response. Please refresh and try again.`)}}async function c(e){try{let t=await e.clone().json();return t?.data?.message||t?.message||`HTTP ${e.status}`}catch{try{return await e.text()||`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}}async function l(e,i={},a){let s={action:`buymecoffee_admin_ajax`,buymecoffee_nonce:r.buymecoffee_nonce,route:e,data:i};t.value=!0,n.value=null;try{return await o(`GET`,s,a)}catch(e){throw e.name!==`AbortError`&&(n.value=e.message),e}finally{t.value=!1}}async function u(e,i={},a){let s={action:`buymecoffee_admin_ajax`,buymecoffee_nonce:r.buymecoffee_nonce,route:e,data:i};t.value=!0,n.value=null;try{return await o(`POST`,s,a)}catch(e){throw e.name!==`AbortError`&&(n.value=e.message),e}finally{t.value=!1}}async function d(e={},r){t.value=!0,n.value=null;try{return await o(`GET`,e,r)}catch(e){throw e.name!==`AbortError`&&(n.value=e.message),e}finally{t.value=!1}}async function f(e={},r){t.value=!0,n.value=null;try{return await o(`POST`,e,r)}catch(e){throw e.name!==`AbortError`&&(n.value=e.message),e}finally{t.value=!1}}return{loading:t,error:n,adminGet:l,adminPost:u,get:d,post:f}}export{t};