import{a as o}from"./api-client-QIUkDUfA.js";class s{constructor(){var r,t,e;this.endpoints={basketAdd:window.addToBasketUrl,basketSummary:(r=window.routes)==null?void 0:r.basketSummary,basketUpdate:(t=window.routes)==null?void 0:t.basketUpdate,basketRemove:(e=window.routes)==null?void 0:e.basketRemove,productCalculate:window.calculateProductUrl,domainCheck:window.domainCheckUrl}}_buildUrl(r,t={}){let e=this.endpoints[r];if(!e)throw new Error(`Unknown endpoint: ${r}`);return Object.keys(t).forEach(a=>{e=e.replace(`:${a}`,t[a])}),e}async addToBasket(r,t={}){try{return await o.post(this.endpoints.basketAdd,r,{headers:t})}catch(e){throw console.error("Basket add failed:",e),new Error("Sepete ekleme başarısız oldu")}}async getBasketSummary(){try{return await o.get(this.endpoints.basketSummary)}catch(r){throw console.error("Basket summary failed:",r),new Error("Sepet özeti alınamadı")}}async updateBasketItem(r,t){try{const e=this._buildUrl("basketUpdate",{index:r});return await o.put(e,t)}catch(e){throw console.error("Basket update failed:",e),new Error("Sepet güncellenemedi")}}async removeBasketItem(r){try{const t=this._buildUrl("basketRemove",{index:r});return await o.delete(t)}catch(t){throw console.error("Basket remove failed:",t),new Error("Sepetten çıkarma başarısız oldu")}}async calculateProductPrice(r,t={}){try{const e=this._buildUrl("productCalculate",{id:r});return await o.post(e,t)}catch(e){throw console.error("Product calculation failed:",e),new Error("Fiyat hesaplanamadı")}}async checkDomain(r){try{return await o.post(this.endpoints.domainCheck,r)}catch(t){throw console.error("Domain check failed:",t),new Error("Domain sorgulanamadı")}}async safeApiCall(r,t=null,e=null){t&&(t.style.display="block");try{const a=await r();return e&&e.style.display!=="none"&&(e.style.display="none"),a}catch(a){throw e&&(e.textContent=a.message,e.style.display="block"),a}finally{t&&(t.style.display="none")}}}window.storeApi=new s;const c=window.storeApi;export{c as s};
