(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9284],{2245:(e,t,s)=>{Promise.resolve().then(s.bind(s,9790))},5731:(e,t,s)=>{"use strict";s.d(t,{A:()=>a,F:()=>o});class r{getToken(){return localStorage.getItem("auth_token")}async request(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s={"Content-Type":"application/json",Accept:"application/json"},r=this.getToken();r&&(s.Authorization="Bearer ".concat(r));let o="".concat(this.baseUrl).concat(e);try{let e=await fetch(o,{...t,headers:s});if(console.log("API Response status:",e.status,"for URL:",o),!e.ok){let t=await e.json().catch(()=>({message:"Request failed"}));if(console.error("API Error:",t),422===e.status)throw{response:{status:422,data:t}};if(401===e.status)throw localStorage.removeItem("auth_token"),localStorage.removeItem("auth_user"),{response:{status:401,data:t}};throw Error(t.message||"HTTP error! status: ".concat(e.status))}let r=await e.json();return console.log("API Response data:",r),r}catch(e){throw console.error("API request failed:",e),e}}async get(e){return console.log("API GET request to:","".concat(this.baseUrl).concat(e)),this.request(e,{method:"GET"})}async post(e,t){return this.request(e,{method:"POST",body:t?JSON.stringify(t):void 0})}async put(e,t){return this.request(e,{method:"PUT",body:t?JSON.stringify(t):void 0})}async patch(e,t){return this.request(e,{method:"PATCH",body:t?JSON.stringify(t):void 0})}async delete(e,t){return this.request(e,{method:"DELETE",body:t?JSON.stringify(t):void 0})}constructor(e){this.baseUrl=e}}let o=new r("http://localhost:8000/api"),a=o},9790:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>n});var r=s(5155),o=s(2115),a=s(5731);function n(){var e,t,s,n,l,c;let[i,d]=(0,o.useState)("sony-bravia-hp-perspiciatis-690314ec82b44"),[u,h]=(0,o.useState)(null),[p,g]=(0,o.useState)(null),[m,x]=(0,o.useState)(!1),b=async()=>{if(i){x(!0),g(null),h(null);try{console.log("Testing direct API call to:","/products/".concat(i));let e=await a.F.get("/products/".concat(i));console.log("Raw API response:",e),h(e)}catch(e){console.error("API Error:",e),g(e instanceof Error?e.message:"Unknown error")}finally{x(!1)}}},v=async()=>{if(i){x(!0),g(null),h(null);try{let e="".concat("http://localhost:8000/api","/products/").concat(i);console.log("Testing direct fetch to:",e);let t=await fetch(e),s=await t.json();console.log("Fetch response:",s),h(s)}catch(e){console.error("Fetch Error:",e),g(e instanceof Error?e.message:"Unknown error")}finally{x(!1)}}};return(0,r.jsxs)("div",{className:"container mx-auto p-8",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold mb-6",children:"Product API Debug Tool"}),(0,r.jsxs)("div",{className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Product Slug:"}),(0,r.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),className:"border border-gray-300 rounded px-3 py-2 w-full max-w-md",placeholder:"Enter product slug"})]}),(0,r.jsxs)("div",{className:"space-x-4",children:[(0,r.jsx)("button",{onClick:b,disabled:m||!i,className:"bg-blue-500 text-white px-4 py-2 rounded disabled:opacity-50",children:m?"Testing...":"Test API Client"}),(0,r.jsx)("button",{onClick:v,disabled:m||!i,className:"bg-green-500 text-white px-4 py-2 rounded disabled:opacity-50",children:m?"Testing...":"Test Direct Fetch"})]})]}),p&&(0,r.jsxs)("div",{className:"mt-6 p-4 bg-red-100 border border-red-400 rounded",children:[(0,r.jsx)("h3",{className:"font-bold text-red-800",children:"Error:"}),(0,r.jsx)("p",{className:"text-red-700",children:p})]}),u&&(0,r.jsxs)("div",{className:"mt-6",children:[(0,r.jsx)("h3",{className:"font-bold mb-2",children:"API Response Structure:"}),(0,r.jsxs)("div",{className:"mb-4 p-3 bg-blue-50 rounded",children:[(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Has 'data' wrapper:"})," ",String("data"in u)]}),(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Product ID:"})," ",String((null===(e=u.data)||void 0===e?void 0:e.id)||u.id||"Not found")]}),(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Product Name:"})," ",String((null===(t=u.data)||void 0===t?void 0:t.name)||u.name||"Not found")]}),(0,r.jsxs)("p",{children:[(0,r.jsx)("strong",{children:"Variants Count:"})," ",Array.isArray(null===(s=u.data)||void 0===s?void 0:s.variants)?null===(l=u.data)||void 0===l?void 0:null===(n=l.variants)||void 0===n?void 0:n.length:Array.isArray(u.variants)?null===(c=u.variants)||void 0===c?void 0:c.length:0]})]}),(0,r.jsx)("pre",{className:"bg-gray-100 p-4 rounded overflow-auto text-sm max-h-96",children:JSON.stringify(u,null,2)})]})]})}}},e=>{var t=t=>e(e.s=t);e.O(0,[8441,1684,7358],()=>t(2245)),_N_E=e.O()}]);