import{r as i,j as e}from"./vendor-react-Ci7aBfa0.js";import{u as M,h as B,e as J,a as Q,n as G}from"./index-Bc-jHh02.js";import{b as W,p as _,S as H}from"./SEO-DMWyZzYz.js";import{P as K}from"./ProductReviews-C6I8yLPS.js";import{s as U}from"./prerender-CvGl2zE9.js";import{t as V}from"./vendor-ui-X4tvFhT0.js";import{c as X,L as u}from"./vendor-Clsy4qE9.js";import{b as y,m as Y,n as A,E as Z,e as ee,d as se}from"./vendor-icons-4GGNjGXS.js";import"./vendor-helmet-X7vXU3pT.js";function me(){const{id:h}=X(),{addItem:F}=M(),[o,b]=i.useState(1),[f,S]=i.useState(0),[m,P]=i.useState([]),[s,C]=i.useState(null),[j,k]=i.useState([]),[D,L]=i.useState([]),[p,N]=i.useState(!0);i.useEffect(()=>{window.scrollTo(0,0),h&&$(h)},[h]),i.useEffect(()=>{p||U()},[p]);async function $(t){try{N(!0);const[a,r]=await Promise.all([B(t),J()]);C(a),L((r||[]).filter(n=>n.active!==!1));const x=await Q({category:a.category});k(x.filter(n=>n.id!==t).slice(0,4))}catch{V.error("Produit non trouvé")}finally{N(!1)}}const E=(t,a)=>{P(r=>r.find(n=>n.name===t)?r.filter(n=>n.name!==t):[...r,{name:t,price:a}])},q=()=>{s&&F({productId:s.id,name:s.name,price:s.salePrice||s.price,quantity:o,image:s.image,type:"product",options:m.length>0?m:void 0})},O=D.filter(t=>t.type==="INSTALLATION"||t.type==="ABONNEMENT").map(t=>({name:t.name,price:t.price}));if(p)return e.jsx("div",{className:"min-h-screen pt-24 flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 border-4 border-[#D45A00] border-t-transparent rounded-full animate-spin"})});if(!s)return e.jsx("div",{className:"min-h-screen pt-24 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h1",{className:"text-2xl font-bold text-[#333333] mb-4",children:"Produit non trouvé"}),e.jsx(u,{to:"/boutique",className:"text-[#D45A00] hover:underline",children:"Retour à la boutique"})]})});const d=s.salePrice||s.price,I=(d+m.reduce((t,a)=>t+a.price,0))*o,g=s.images?typeof s.images=="string"?JSON.parse(s.images):s.images:[s.image],v=G(s.specs),l=typeof s.stock=="number"?s.stock:10,c=l<=0,w=l>0&&l<=(s.stockAlert??3),z=c?"OutOfStock":w?"LimitedAvailability":"InStock",R=W([{name:"Accueil",url:"/"},{name:"Boutique",url:"/boutique"},{name:s.name,url:`/produit/${s.id}`}]),T=_(s.name,s.description,d,s.image,s.sku,z,`https://abidjangps.com/produit/${s.id}`,s.rating??4.8,s.reviewCount??500);return e.jsxs("main",{className:"min-h-screen pt-20 md:pt-24 pb-16 bg-white",children:[e.jsx(H,{title:`${s.name} — Traceur GPS Abidjan`,description:`${s.description} Achetez à ${d.toLocaleString()} FCFA. Livraison 2-4h à Abidjan. Installation disponible.`,url:`/produit/${s.id}`,type:"product",price:d,image:s.image,jsonLd:[T,R]}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs("nav",{className:"text-sm text-gray-500 mb-6",children:[e.jsx(u,{to:"/",className:"hover:text-[#D45A00]",children:"Accueil"}),e.jsx(y,{className:"w-4 h-4 inline mx-1"}),e.jsx(u,{to:"/boutique",className:"hover:text-[#D45A00]",children:"Boutique"}),e.jsx(y,{className:"w-4 h-4 inline mx-1"}),e.jsx("span",{className:"text-[#333333] font-medium",children:s.name})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-10 lg:gap-16",children:[e.jsxs("div",{children:[e.jsx("div",{className:"aspect-square bg-[#F2F2F2] rounded-xl overflow-hidden mb-4",children:e.jsx("img",{src:g[f]||s.image,alt:`${s.name} à Abidjan`,className:"w-full h-full object-cover",loading:"lazy"})}),g.length>1&&e.jsx("div",{className:"flex flex-wrap gap-3",children:g.map((t,a)=>e.jsx("button",{onClick:()=>S(a),className:`w-20 h-20 rounded-lg overflow-hidden border-2 transition-colors ${f===a?"border-[#D45A00]":"border-transparent"}`,children:e.jsx("img",{src:t,alt:`${s.name} - vue ${a+1}`,className:"w-full h-full object-cover",loading:"lazy"})},a))})]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-[#333333] mb-2",children:s.name}),e.jsx("div",{className:"flex flex-col gap-1 mb-4",children:s.salePrice?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-green-600 font-medium",children:"Prix promo"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("p",{className:"text-3xl md:text-4xl font-bold text-[#D45A00]",children:[s.salePrice.toLocaleString()," FCFA"]}),e.jsxs("p",{className:"text-xl text-gray-400 line-through","aria-label":"Ancien prix",children:[s.price.toLocaleString()," FCFA"]})]})]}):e.jsxs("p",{className:"text-3xl md:text-4xl font-bold text-[#D45A00]",children:[s.price.toLocaleString()," FCFA"]})}),e.jsx("p",{className:"text-gray-600 mb-6 leading-relaxed",children:s.longDescription||s.description}),e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx("span",{className:"text-sm font-medium text-[#333333]",children:"Quantité :"}),e.jsxs("div",{className:"flex items-center border rounded-lg",children:[e.jsx("button",{onClick:()=>b(Math.max(1,o-1)),disabled:c,className:"w-11 h-11 min-w-11 min-h-11 flex items-center justify-center hover:bg-[#F2F2F2] disabled:opacity-40",children:e.jsx(Y,{className:"w-4 h-4"})}),e.jsx("span",{className:"w-12 text-center font-semibold",children:o}),e.jsx("button",{onClick:()=>b(Math.min(l>0?l:10,o+1)),disabled:c,className:"w-11 h-11 min-w-11 min-h-11 flex items-center justify-center hover:bg-[#F2F2F2] disabled:opacity-40",children:e.jsx(A,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"mb-4",children:c?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-red-50 text-red-700 text-sm font-medium",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500"})," Rupture de stock"]}):w?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-amber-50 text-amber-700 text-sm font-medium",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500"})," Stock limité : ",l," restant",l>1?"s":""]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-green-50 text-green-700 text-sm font-medium",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"})," En stock (",l," disponible",l>1?"s":"",")"]})}),e.jsxs("div",{className:"bg-[#F2F2F2] rounded-xl p-5 mb-6",children:[e.jsxs("h3",{className:"font-semibold text-[#333333] mb-3 flex items-center gap-2",children:[e.jsx(A,{className:"w-5 h-5 text-[#D45A00]"})," Ajoutez des services"]}),e.jsx("div",{className:"space-y-3",children:O.map((t,a)=>{const r=m.some(x=>x.name===t.name);return e.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all ${r?"border-[#D45A00] bg-[#D45A00]/5":"border-transparent bg-white"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${r?"bg-[#D45A00] border-[#D45A00]":"border-gray-300"}`,children:r&&e.jsx(Z,{className:"w-3 h-3 text-white"})}),e.jsx("input",{type:"checkbox",className:"sr-only",checked:r,onChange:()=>E(t.name,t.price)}),e.jsx("span",{className:"flex-1 text-sm text-[#333333]",children:t.name}),e.jsxs("span",{className:"font-semibold text-[#D45A00]",children:["+",t.price.toLocaleString()," FCFA"]})]},a)})})]}),e.jsxs("div",{className:"flex items-center justify-between mb-6 p-4 bg-[#D45A00]/5 rounded-lg",children:[e.jsx("span",{className:"font-medium text-[#333333]",children:"Total :"}),e.jsxs("span",{className:"text-2xl font-bold text-[#D45A00]",children:[I.toLocaleString()," FCFA"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{onClick:q,disabled:c,className:"flex-1 py-4 bg-[#D45A00] text-white rounded-lg font-bold text-lg hover:bg-[#E55A00] transition-all flex items-center justify-center gap-2 disabled:opacity-60 disabled:cursor-not-allowed",children:[e.jsx(ee,{className:"w-5 h-5"})," ",c?"Indisponible":"Ajouter au panier"]}),e.jsxs("a",{href:`https://wa.me/2250170090932?text=Bonjour, je souhaite commander le ${s.name} (${d.toLocaleString()} FCFA)`,target:"_blank",rel:"noopener noreferrer",className:"flex-1 py-4 bg-[#25D366] text-white rounded-lg font-bold text-lg hover:bg-[#128C7E] transition-all flex items-center justify-center gap-2",children:[e.jsx(se,{className:"w-5 h-5"})," Commander sur WhatsApp"]})]}),v.length>0&&e.jsxs("div",{className:"mt-10",children:[e.jsx("h3",{className:"text-xl font-bold text-[#333333] mb-4",children:"Caractéristiques techniques"}),e.jsx("div",{className:"border rounded-xl overflow-hidden overflow-x-auto",children:e.jsx("table",{className:"w-full text-sm min-w-[280px]",children:e.jsx("tbody",{children:v.map((t,a)=>e.jsxs("tr",{className:a%2===0?"bg-[#F2F2F2]":"bg-white",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-[#333333] capitalize",children:t.label}),e.jsx("td",{className:"px-4 py-3 text-gray-600 break-all",children:t.value})]},a))})})})]})]})]}),j.length>0&&e.jsxs("div",{className:"mt-16",children:[e.jsx("h2",{className:"text-2xl font-bold text-[#333333] mb-6",children:"Produits similaires"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6",children:j.map(t=>e.jsxs(u,{to:`/produit/${t.id}`,className:"group bg-white border border-gray-100 rounded-xl overflow-hidden hover:shadow-xl hover:-translate-y-1 transition-all duration-300",children:[e.jsx("div",{className:"aspect-square bg-[#F2F2F2] overflow-hidden",children:e.jsx("img",{src:t.image,alt:t.name,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500",loading:"lazy"})}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"font-semibold text-[#333333] group-hover:text-[#D45A00] transition-colors",children:t.name}),e.jsxs("p",{className:"text-lg font-bold text-[#D45A00] mt-1",children:[(t.salePrice||t.price).toLocaleString()," FCFA"]})]})]},t.id))})]}),e.jsx(K,{productId:s.id})]})]})}export{me as default};