import{A as p,l as h}from"./index-BagLllOy.js";const f=()=>{const e="https://api.goh.place/api/v1";return e.endsWith("/api/v1")?e:`${e.replace(/\/$/,"")}/api/v1`},y=f(),u=new Map;async function g(e,t,a=3){const i=p(),c={"Content-Type":"application/json",...i?{"X-App-UUID":i}:{},...t?.headers};for(let o=0;o<a;o++)try{const r=await fetch(e,{...t,headers:c,signal:t?.signal});if(!r.ok){if(r.status>=400&&r.status<500&&r.status!==429){const n=await r.text().catch(()=>r.statusText);throw new Error(`API request failed: ${r.status} ${n}`)}if(o===a-1){const n=await r.text().catch(()=>r.statusText);throw new Error(`API request failed: ${r.status} ${n}`)}await new Promise(n=>setTimeout(n,Math.pow(2,o)*1e3));continue}const d=r.headers.get("content-type");if(d&&d.includes("application/json"))try{return await r.json()}catch(n){throw h.error(`Failed to parse JSON response from ${e}`,{context:"API",error:n}),new Error(`Invalid JSON response from ${e}`)}else return await r.text()}catch(r){if(r instanceof Error&&r.name==="AbortError")throw r;if(o===a-1){const n=r instanceof Error?r.message:String(r);throw h.error(`Error fetching ${e} after ${a} retries: ${n}`,{context:"API",error:r}),r}const d=Math.pow(2,o)*1e3;await new Promise(n=>setTimeout(n,d))}throw new Error("Max retries exceeded")}async function s(e,t){const a=e.startsWith("/")?e:`/${e}`,i=`${y}${a}`,c=`${t?.method||"GET"}:${i}:${JSON.stringify(t?.body||"")}`;if((!t?.method||t.method==="GET")&&u.has(c))return u.get(c);const o=g(i,t);return(!t?.method||t.method==="GET")&&(u.set(c,o),o.finally(()=>{setTimeout(()=>{u.delete(c)},50)})),o}const $={getCountries:()=>s("/countries"),getCities:e=>{const t=e?`?country_id=${e}`:"";return s(`/cities${t}`)},getPlaces:e=>{const t=new URLSearchParams;e?.country_id&&t.append("country_id",e.country_id),e?.city_id&&t.append("city_id",e.city_id);const a=t.toString();return s(`/places${a?`?${a}`:""}`)},getPlace:(e,t)=>{const a=new URLSearchParams;return e&&a.append("place_id",e),t&&a.append("place_slug",t),s(`/place?${a.toString()}`)},searchPlaces:e=>s(`/places/search?name=${encodeURIComponent(e)}`),getShops:e=>{const t=new URLSearchParams;e?.country_id&&t.append("country_id",e.country_id),e?.city_id&&t.append("city_id",e.city_id);const a=t.toString();return s(`/shops${a?`?${a}`:""}`)},getShop:(e,t)=>{const a=new URLSearchParams;return e&&a.append("shop_id",e),t&&a.append("shop_slug",t),s(`/shop?${a.toString()}`)},searchShops:e=>s(`/shops/search?name=${encodeURIComponent(e)}`),getReviews:e=>s("/review/get",{method:"POST",body:JSON.stringify(e)}),getArticles:()=>s("/articles"),getArticle:e=>s(`/article?article_id=${e}`),getFaqs:()=>s("/faqs"),getFaq:e=>s(`/faqs/${e}`),createFeedback:e=>s("/feedback/create",{method:"POST",body:JSON.stringify(e)})};export{$ as a};