1import{r as N,j as e}from"./query-CGHSk7ud.js";import{a as D,u as B,L as E}from"./react-vendor-BsSYYw5-.js";import{r as T,s as q,B as A,v as k}from"./index-BfrGfMD_.js";import{C as x,c as h}from"./card-BRfnYiDn.js";import{V as P}from"./VeilleShell-B3FVZ0j_.js";import{g as z,s as I}from"./seller-type-LaTOqZQy.js";import{c as O}from"./similarity-DUg4OhLx.js";import{A as V}from"./AnalyseIACard-C3_zJROJ.js";import{J as F,ab as H,a2 as $,a4 as K,Q as U,a9 as G,a3 as J,b9 as Q,b8 as W,aH as Y,aA as Z,L as X,a5 as ee,Y as se,bp as te}from"./icons-CxnfC-37.js";import"./supabase-BOCL3uOH.js";import"./charts-B3XiXjwx.js";import"./motion-B9DIfdcM.js";import"./i18n-C4HGKhfx.js";import"./sheet-DHO6GpXq.js";import"./switch-Ckcu1UXh.js";import"./index-BjbBAk1k.js";const ae={leboncoin:"LeBonCoin",lacentrale:"La Centrale",autoscout24:"AutoScout24","mobile.de":"Mobile.de",paruvendu:"ParuVendu"};function _(o){const u=(o||"").toLowerCase();return ae[u]||o||"â"}function le(o){if(!o)return null;const u=Date.parse(o);if(!Number.isFinite(u))return null;const g=Math.max(0,Date.now()-u),s=Math.floor(g/864e5);return s===0?"aujourd'hui":s===1?"hier":s<7?`il y a ${s} j`:s<30?`il y a ${Math.floor(s/7)} sem`:`il y a ${Math.floor(s/30)} mois`}function ye(){T({title:"Détail annonce marché | Inspectoo Scanner",description:"Analyse détaillée d'une annonce identifiée dans l'analyse de marché."});const o=D(),g=B().state||{},s=g.listing,i=g.market,y=N.useMemo(()=>{if(!s)return[];const t=s,l=[s.image,t.thumbnail,t.thumbnail_url,t.photo,t.picture,t.cover],n=c=>{if(c){if(typeof c=="string"){l.push(c);return}if(Array.isArray(c)){c.forEach(n);return}if(typeof c=="object"){const j=c;n(j.url),n(j.src),n(j.image),n(j.thumbnail),n(j.thumbnail_url)}}};return n(t.photos),n(t.images),z(l,s.image||t.thumbnail_url||t.thumbnail||null).slice(0,6)},[s]),[a,L]=N.useState({loading:!1,detail:null,reliability:null,analysis:null,error:null});N.useEffect(()=>{if(!s?.url)return;let t=!1;return L(l=>({...l,loading:!0,error:null})),(async()=>{try{const{data:l,error:n}=await q.functions.invoke("enrich-market-listing",{body:{url:s.url,brand:i?.criteria?.brand||"",model:i?.criteria?.model||"",title:s.title||"",price:s.price??null,mileage:s.mileage??null,year:s.year??null,market_median:i?.median??null}});if(t)return;if(n)throw n;const c=l;L({loading:!1,detail:c?.detail||null,reliability:c?.reliability||null,analysis:c?.analysis||null,error:null})}catch(l){if(t)return;L({loading:!1,detail:null,reliability:null,analysis:null,error:l?.message||"enrich_failed"})}})(),()=>{t=!0}},[s?.url]);const C=N.useMemo(()=>{const t=a.detail?.specs?.seller_type||s?.sellerType||null;return t?String(t).toLowerCase():null},[a.detail,s?.sellerType]),w=N.useMemo(()=>{const t=i?.median||0;return!t||t<1e3?null:Math.max(990,Math.floor(t/100)*100-10)},[i?.median]);if(!s)return e.jsx(P,{title:"Détail annonce",children:e.jsxs("div",{className:"mx-auto max-w-2xl px-4 py-16 text-center",children:[e.jsx("h1",{className:"text-xl font-semibold text-slate-100 mb-2",children:"Annonce introuvable"}),e.jsx("p",{className:"text-slate-400 mb-6",children:"La fiche n'est accessible qu'en provenance de l'analyse de marché."}),e.jsxs(A,{onClick:()=>o("/veille/analyse-marche"),className:"gap-2",children:[e.jsx(F,{className:"h-4 w-4"})," Retour à l'analyse"]})]})});const d=s.removed?s.lastPrice??s.price:s.price,p=i?.median||0,b=p>0&&d?(d-p)/p*100:null,R=b==null?"text-slate-400":b<=-8?"text-emerald-400":b>=10?"text-rose-400":"text-amber-300",M=le(s.lastSeenAt||s.detectedAt||s.publishDate||s.firstSeenAt),r=i?.criteria?O(s,i.criteria,{cluster:i.cluster||void 0}):null,m=i?.p25??i?.min??null,f=i?.p75??i?.max??null,v=(()=>{if(!d||!m||!f||f<=m)return null;const t=c=>Math.max(0,Math.min(100,c)),l=t((d-m)/(f-m)*100),n=p?t((p-m)/(f-m)*100):null;return{pct:l,medPct:n}})();return e.jsx(P,{title:s.title||"Détail annonce",subtitle:_(s.source),showBack:!0,children:e.jsxs("div",{className:"mx-auto max-w-4xl px-4 py-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>o(-1),className:"gap-2 text-slate-300 hover:text-slate-100",children:[e.jsx(F,{className:"h-4 w-4"}
1)," Retour à l'analyse"]}),s.url&&e.jsx(A,{asChild:!0,size:"sm",className:"gap-2",children:e.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",children:["Voir sur ",_(s.source)," ",e.jsx(H,{className:"h-4 w-4"})]})})]}),e.jsx(x,{className:"overflow-hidden border-white/10 bg-white/[0.02]",children:e.jsxs("div",{className:"grid md:grid-cols-2 gap-0",children:[e.jsx("div",{className:"bg-slate-900 aspect-[4/3] md:aspect-auto md:min-h-[280px] flex items-center justify-center overflow-hidden",children:y[0]?e.jsx("img",{src:y[0],alt:s.title,className:`h-full w-full object-cover ${s.removed?"grayscale":""}`,referrerPolicy:"no-referrer"}):e.jsx("div",{className:"text-slate-500 text-sm",children:"Aucune photo"})}),e.jsxs(h,{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx(k,{variant:"outline",className:"border-white/15 text-slate-300",children:_(s.source)}),(()=>{const t=I(C);if(!C)return null;const l=t.emoji==="ð¢"?"border-indigo-500/40 text-indigo-300":"border-emerald-500/40 text-emerald-300";return e.jsxs(k,{variant:"outline",className:l,children:[t.emoji," ",t.label]})})(),s.removed&&e.jsx(k,{className:"bg-rose-500/20 text-rose-300 border-rose-500/30 border",children:"Annonce supprimée"}),M&&e.jsxs("span",{className:"text-xs text-slate-400 inline-flex items-center gap-1",children:[e.jsx($,{className:"h-3 w-3"}),M]})]}),e.jsx("h1",{className:"text-xl md:text-2xl font-semibold text-slate-100 leading-tight",children:s.title||"Annonce"}),s.location&&e.jsxs("p",{className:"mt-1 text-sm text-slate-400 inline-flex items-center gap-1",children:[e.jsx(K,{className:"h-3.5 w-3.5"})," ",s.location]})]}),e.jsxs("div",{className:"flex items-baseline gap-3",children:[e.jsx("span",{className:"text-3xl font-bold text-slate-100 tabular-nums",children:d?`${d.toLocaleString("fr-FR")} â¬`:"â"}),b!=null&&e.jsxs("span",{className:`text-sm font-semibold inline-flex items-center gap-1 ${R}`,children:[b>0?e.jsx(U,{className:"h-3.5 w-3.5"}):e.jsx(G,{className:"h-3.5 w-3.5"}),b>0?"+":"",b.toFixed(0),"% vs médiane"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsx(S,{icon:e.jsx($,{className:"h-4 w-4"}),label:"Année",value:s.year?String(s.year):"â"}),e.jsx(S,{icon:e.jsx(J,{className:"h-4 w-4"}),label:"Km",value:s.mileage?`${s.mileage.toLocaleString("fr-FR")} km`:"â"}),e.jsx(S,{icon:e.jsx(Q,{className:"h-4 w-4"}),label:"Carburant",value:s.fuel||"â"}),e.jsx(S,{icon:e.jsx(W,{className:"h-4 w-4"}),label:"Boîte",value:s.gearbox||"â"})]})]})]})}),y.length>1&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold mb-3",children:"Photos"}),e.jsx("div",{className:"grid grid-cols-3 md:grid-cols-6 gap-2",children:y.map((t,l)=>e.jsx("a",{href:t,target:"_blank",rel:"noreferrer",className:"aspect-square overflow-hidden rounded-lg bg-slate-900",children:e.jsx("img",{src:t,alt:"",className:"h-full w-full object-cover",referrerPolicy:"no-referrer"})},l))})]})}),i&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold",children:"Positionnement marché"}),e.jsxs("p",{className:"text-sm text-slate-300 mt-0.5",children:[i.sampleSize?`${i.sampleSize} annonces comparées`:"Marché",i.vehicleLabel?` · ${i.vehicleLabel}`:""]})]}),p>0&&e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-[11px] text-slate-500",children:"Médiane"}),e.jsxs("p",{className:"text-sm font-semibold text-slate-100 tabular-nums",children:[p.toLocaleString("fr-FR")," â¬"]})]})]}),v&&m&&f&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative h-3 rounded-full bg-white/5 overflow-hidden",children:[e.jsx("div",{className:"absolute inset-y-0 rounded-full bg-emerald-400/25",style:{left:"15%",right:"15%"}}),v.medPct!=null&&e.jsx("div",{className:"absolute top-0 bottom-0 w-px bg-slate-300/70",style:{left:`${v.medPct}%`}}),e.jsx("div",{className:"absolute -top-1 h-5 w-1 rounded bg-primary shadow",style:{left:`calc(${v.pct}% - 2px)`}})]}),e.jsxs("div",{className:"flex justify-between text-[11px] text-slate-500 tabular-nums",children:[e.jsxs("span",{children:[m.toLocaleStr
1ing("fr-FR")," â¬"]}),e.jsx("span",{className:"text-slate-400",children:"Zone typique P25âP75"}),e.jsxs("span",{children:[f.toLocaleString("fr-FR")," â¬"]})]})]})]})}),r&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold",children:"Similarité avec votre recherche"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-2xl font-bold text-slate-100 tabular-nums",children:[r.score,"%"]}),r.confidence&&e.jsxs(k,{variant:"outline",className:`border ${r.confidence==="high"?"border-emerald-500/40 text-emerald-300":r.confidence==="medium"?"border-amber-500/40 text-amber-300":"border-slate-500/40 text-slate-300"}`,children:["Fiabilité ",r.confidence==="high"?"élevée":r.confidence==="medium"?"moyenne":"faible"]})]})]}),e.jsx("div",{className:"space-y-1.5",children:[["Année",r.breakdown.year],["Kilométrage",r.breakdown.mileage],["Carburant",r.breakdown.fuel],["Boîte",r.breakdown.gearbox],["Mots-clés / finition",r.breakdown.keywords],["Proximité cluster",r.breakdown.cluster]].map(([t,l])=>e.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[e.jsx("span",{className:"w-40 shrink-0 text-slate-400",children:t}),l==null?e.jsx("span",{className:"text-slate-500 italic",children:"Donnée manquante · neutre"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full ${l>=80?"bg-emerald-400/70":l>=55?"bg-amber-400/70":"bg-rose-400/70"}`,style:{width:`${Math.max(0,Math.min(100,l))}%`}})}),e.jsx("span",{className:"w-10 text-right text-slate-300 tabular-nums",children:l})]})]},t))})]})}),w&&e.jsx(x,{className:"border-primary/30 bg-primary/5",children:e.jsxs(h,{className:"p-5 flex items-start gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-primary/80 font-semibold",children:"Suggestion prix de vente"}),e.jsxs("p",{className:"text-2xl font-bold text-slate-100 mt-1 tabular-nums",children:[w.toLocaleString("fr-FR")," â¬"]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:["Basé sur la médiane marché · arrondi psychologique (.90 â¬)",d?` · ${w>d?"+":""}${(w-d).toLocaleString("fr-FR")} ⬠vs prix affiché`:""]})]})]})}),(a.loading||a.detail?.description||s?.description||a.error)&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Z,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold",children:"Description complète"}),a.loading&&e.jsx(X,{className:"h-3.5 w-3.5 animate-spin text-slate-400"})]}),a.detail?.description||s?.description?e.jsx("div",{className:"text-sm text-slate-300 whitespace-pre-wrap leading-relaxed max-h-96 overflow-y-auto",children:a.detail?.description||s?.description}):a.loading?e.jsx("p",{className:"text-sm text-slate-500",children:"Récupération du contenu de l'annonceâ¦"}):e.jsx("p",{className:"text-sm text-slate-500 italic",children:"Description non récupérable pour cette source."})]})}),a.detail?.specs&&Object.keys(a.detail.specs).length>0&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ee,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold",children:"Caractéristiques détaillées"})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2 text-sm",children:Object.entries(a.detail.specs).filter(([,t])=>t!=null&&String(t).trim().length>0).slice(0,24).map(([t,l])=>e.jsxs("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] px-3 py-2",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-slate-500 font-semibold",children:t.replace(/_/g," ")}),e.jsx("p",{className:"text-slate-200 text-sm mt-0.5 truncate",title:String(l),children:String(l)}
1)]},t))})]})}),a.reliability&&e.jsx(x,{className:"border-white/10 bg-white/[0.02]",children:e.jsxs(h,{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-[11px] uppercase tracking-widest text-slate-500 font-semibold",children:"Fiabilité moteur"})]}),a.reliability.reliability_score!=null&&e.jsxs("span",{className:"text-2xl font-bold text-slate-100 tabular-nums",children:[a.reliability.reliability_score,e.jsx("span",{className:"text-sm text-slate-500",children:"/100"})]})]}),e.jsxs("p",{className:"text-sm text-slate-300",children:[a.reliability.engine_family,a.reliability.engine_code?` · ${a.reliability.engine_code}`:"",a.reliability.reliability_label?` â ${a.reliability.reliability_label}`:""]}),Array.isArray(a.reliability.known_problems)&&a.reliability.known_problems.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest text-slate-500 font-semibold mb-1",children:"Problèmes documentés"}),e.jsx("ul",{className:"text-sm text-slate-300 space-y-1 list-disc list-inside",children:a.reliability.known_problems.slice(0,4).map((t,l)=>e.jsx("li",{children:t},l))})]}),a.reliability.expert_comment&&e.jsx("p",{className:"text-xs text-slate-400 italic border-l-2 border-primary/30 pl-3",children:a.reliability.expert_comment})]})}),(a.loading||a.analysis)&&e.jsx(V,{analysis:a.analysis,isScanning:a.loading}),e.jsxs("div",{className:"rounded-xl border border-white/10 bg-white/[0.02] p-4 text-xs text-slate-400 flex items-start gap-2",children:[e.jsx(te,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("div",{children:["Fiche générée à la volée à partir des données de la recherche marché. Pour un suivi continu (alertes prix, historique, notifications), enregistrez le véhicule dans une alerte"," ",e.jsx(E,{to:"/veille/annonces",className:"underline decoration-dotted hover:text-slate-200",children:"Scanner"}),"."]})]})]})})}function S({icon:o,label:u,value:g}){return e.jsxs("div",{className:"rounded-lg border border-white/10 bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-slate-500 font-semibold",children:[o,e.jsx("span",{children:u})]}),e.jsx("div",{className:"mt-0.5 text-slate-100 text-sm tabular-nums",children:g})]})}export{ye as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.