import{r as n,j as e}from"./vendor-react-Ci7aBfa0.js";import{f as U,h as W,e as B,b as J}from"./index-DseDRO2X.js";import{b as Q,p as V,S as _}from"./SEO-_JstgKNN.js";import{P as H}from"./ProductReviews-DGQ6Kf8-.js";import{n as K}from"./utils-BhlM5UoR.js";import{s as X}from"./prerender-CvGl2zE9.js";import{t as Y}from"./vendor-ui-BPcTRgsV.js";import{d as Z,L as p}from"./vendor-Dk4E_gAD.js";import{b as S,m as ee,n as se,W as te,M as ae,V as ie,R as re,e as le,d as ne}from"./vendor-icons-D7yCv6uo.js";import"./vendor-helmet-nH3Guqws.js";function ge(){const{id:u}=Z(),{addItem:F}=U(),[o,b]=n.useState(1),[g,P]=n.useState(0),[c,j]=n.useState([]),[t,L]=n.useState(null),[N,C]=n.useState([]),[I,k]=n.useState([]),[h,v]=n.useState(!0);n.useEffect(()=>{window.scrollTo(0,0),u&&D(u)},[u]),n.useEffect(()=>{h||X()},[h]);async function D(s){try{v(!0);const[i,m]=await Promise.all([W(s),B()]);L(i),k((m||[]).filter(r=>r.active!==!1));const a=await J({category:i.category});C(a.filter(r=>r.id!==s).slice(0,4))}catch{Y.error("Produit non trouvé")}finally{v(!1)}}const $=s=>{j(i=>i.find(a=>a.serviceId===s.id)?i.filter(a=>a.serviceId!==s.id):[...i.filter(a=>a.type!==s.type),{serviceId:s.id,name:s.name,price:s.price,type:s.type}])},O=()=>{t&&F({productId:t.id,name:t.name,price:t.salePrice||t.price,quantity:o,image:t.image,type:"product",options:c.length>0?c:void 0})},E=I.filter(s=>["INSTALLATION","PLATEFORME","SIM"].includes(s.type)).filter(s=>s.type!=="INSTALLATION"||!Array.isArray(s.compatibleWith)||s.compatibleWith.includes(t?.category)).map(s=>({id:s.id,name:s.name,price:s.price,priceUnit:s.priceUnit,description:s.description,type:s.type})),M=[{type:"INSTALLATION",title:"Installation professionnelle",description:"Facultative. Disponible au retrait ou à l’adresse de votre choix.",icon:te},{type:"PLATEFORME",title:"Plateforme de suivi",description:"Facultative. Choisissez l’offre adaptée à votre usage.",icon:ae},{type:"SIM",title:"Carte SIM et connexion",description:"Facultative. Vous pouvez fournir votre SIM ou choisir une offre AbidjanGPS.",icon:ie}];if(h)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(!t)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(p,{to:"/boutique",className:"text-[#D45A00] hover:underline",children:"Retour à la boutique"})]})});const x=t.salePrice||t.price,y=(x+c.reduce((s,i)=>s+i.price,0))*o,T=["Bonjour AbidjanGPS, je souhaite finaliser cette commande :",`Produit : ${t.name}`,`Quantité : ${o}`,`Options : ${c.length?c.map(s=>`${s.name}${s.price?` (+${s.price.toLocaleString()} FCFA)`:""}`).join(", "):"Aucune"}`,`Total estimé : ${y.toLocaleString()} FCFA`].join(`
`),f=t.images?typeof t.images=="string"?JSON.parse(t.images):t.images:[t.image],A=K(t.specs),l=typeof t.stock=="number"?t.stock:10,d=l<=0,w=l>0&&l<=(t.stockAlert??3),q=d?"OutOfStock":w?"LimitedAvailability":"InStock",R=Q([{name:"Accueil",url:"/"},{name:"Boutique",url:"/boutique"},{name:t.name,url:`/produit/${t.id}`}]),z=V(t.name,t.description,x,t.image,t.sku,q,`https://abidjangps.com/produit/${t.id}`);return e.jsxs("main",{className:"min-h-screen pt-20 md:pt-24 pb-16 bg-white",children:[e.jsx(_,{title:`${t.name} — Traceur GPS Abidjan`,description:`${t.description} Achetez à ${x.toLocaleString()} FCFA. Installation disponible en option.`,url:`/produit/${t.id}`,type:"product",price:x,image:t.image,jsonLd:[z,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(p,{to:"/",className:"hover:text-[#D45A00]",children:"Accueil"}),e.jsx(S,{className:"w-4 h-4 inline mx-1"}),e.jsx(p,{to:"/boutique",className:"hover:text-[#D45A00]",children:"Boutique"}),e.jsx(S,{className:"w-4 h-4 inline mx-1"}),e.jsx("span",{className:"text-[#333333] font-medium",children:t.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:f[g]||t.image,alt:`${t.name} à Abidjan`,className:"w-full h-full object-cover",loading:"lazy"})}),f.length>1&&e.jsx("div",{className:"flex flex-wrap gap-3",children:f.map((s,i)=>e.jsx("button",{onClick:()=>P(i),className:`w-20 h-20 rounded-lg overflow-hidden border-2 transition-colors ${g===i?"border-[#D45A00]":"border-transparent"}`,children:e.jsx("img",{src:s,alt:`${t.name} - vue ${i+1}`,className:"w-full h-full object-cover",loading:"lazy"})},i))})]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-[#333333] mb-2",children:t.name}),e.jsx("div",{className:"flex flex-col gap-1 mb-4",children:t.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:[t.salePrice.toLocaleString()," FCFA"]}),e.jsxs("p",{className:"text-xl text-gray-400 line-through","aria-label":"Ancien prix",children:[t.price.toLocaleString()," FCFA"]})]})]}):e.jsxs("p",{className:"text-3xl md:text-4xl font-bold text-[#D45A00]",children:[t.price.toLocaleString()," FCFA"]})}),e.jsx("p",{className:"text-gray-600 mb-3 leading-relaxed",children:(t.longDescription||t.description).replace("Installation professionnelle incluse.","Installation professionnelle disponible en option.")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:"Ajoutez seulement les services dont vous avez besoin. Livraison ou retrait seront choisis au panier."}),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:d,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(ee,{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:d,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(se,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"mb-4",children:d?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.jsx("div",{className:"space-y-4 mb-6",children:M.map(s=>{const i=s.icon,m=E.filter(a=>a.type===s.type);return m.length===0?null:e.jsxs("section",{className:"bg-[#F2F2F2] rounded-xl p-5",children:[e.jsxs("h3",{className:"font-semibold text-[#333333] flex items-center gap-2",children:[e.jsx(i,{className:"w-5 h-5 text-[#D45A00]"})," ",s.title]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 mb-3",children:s.description}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-lg border-2 cursor-pointer transition-all border-transparent bg-white",children:[e.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-gray-300 flex items-center justify-center"}),e.jsx("input",{type:"radio",name:s.type,className:"sr-only",checked:!c.some(a=>a.type===s.type),onChange:()=>j(a=>a.filter(r=>r.type!==s.type))}),e.jsx("span",{className:"text-sm text-[#333333]",children:"Aucune option"})]}),m.map(a=>{const r=c.some(G=>G.serviceId===a.id);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-full border-2 flex items-center justify-center ${r?"bg-[#D45A00] border-[#D45A00]":"border-gray-300"}`,children:r&&e.jsx(re,{className:"w-3 h-3 text-white"})}),e.jsx("input",{type:"radio",name:s.type,className:"sr-only",checked:r,onChange:()=>$(a)}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-sm text-[#333333]",children:a.name}),e.jsx("span",{className:"block text-xs text-gray-500 mt-0.5",children:a.description})]}),e.jsxs("span",{className:"font-semibold text-[#D45A00] text-sm text-right",children:[a.price===0?"Gratuit":`+${a.price.toLocaleString()} FCFA`,a.priceUnit&&e.jsx("span",{className:"block text-xs font-normal text-gray-500",children:a.priceUnit})]})]},a.id)})]})]},s.type)})}),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:[y.toLocaleString()," FCFA"]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{onClick:O,disabled:d,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(le,{className:"w-5 h-5"})," ",d?"Indisponible":"Ajouter au panier"]}),e.jsxs("a",{href:`https://wa.me/2250170090932?text=${encodeURIComponent(T)}`,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(ne,{className:"w-5 h-5"})," Commander sur WhatsApp"]})]}),A.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:A.map((s,i)=>e.jsxs("tr",{className:i%2===0?"bg-[#F2F2F2]":"bg-white",children:[e.jsx("td",{className:"px-4 py-3 font-medium text-[#333333] capitalize",children:s.label}),e.jsx("td",{className:"px-4 py-3 text-gray-600 break-all",children:s.value})]},i))})})})]})]})]}),N.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:N.map(s=>e.jsxs(p,{to:`/produit/${s.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:s.image,alt:s.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:s.name}),e.jsxs("p",{className:"text-lg font-bold text-[#D45A00] mt-1",children:[(s.salePrice||s.price).toLocaleString()," FCFA"]})]})]},s.id))})]}),e.jsx(H,{productId:t.id})]})]})}export{ge as default};