PageSourceSearch

https://hopelia.com/assets/app.projets._id-C8txmqSo.js

js hopelia.com collected 2026-09-24 14:47:13 UTC 137,515 bytes, 6 lines download raw bytes

1import{c as G,X as dt,c7 as Ls,h as We,aT as _e,i as J,cV as ut,s as I,j as e,S as A,t as f,cW as mt,cX as pt,L as H,cY as Ms,r as y,m as v,cx as xt,cZ as ft,u as ht,c_ as gt,cT as Ue,cU as Ts,cS as Rs,c$ as bt,d0 as jt,G as vt,bC as yt}from"./index-DveFA38Q.js";import{d as Fs,e as Gs,f as Nt,g as _t,S as Z,h as kt}from"./useProjects-LUFtIIxf.js";import{b as Os,F as Qe,C as At,N as wt,D as Ct}from"./NotesPanel-D7-6PPKs.js";import{i as ne,a as St}from"./phases-projet-T8auBr9T.js";import{a as zt}from"./celebration-CEHQwQj1.js";import{S as E}from"./skeleton-1BtWIr2P.js";import{R as Et,a as $t,b as Pt}from"./index-VbmabMsg.js";import{D as qt,a as Lt,b as Mt,c as Tt}from"./dropdown-menu-Da4Bswp3.js";import{u as U}from"./useMutation-66Cllo-Z.js";import{E as as,b as Rt,a as Ft,V as Be}from"./EncadrementInfo-DwWj-4oe.js";import{T as _,a as oe}from"./TermeTip-C_BzjdvF.js";import{G as S,C as ee,P as K}from"./Puce-Ccj8DF2t.js";import{S as F}from"./SignalErreurIA-_UudEdxQ.js";import{R as L}from"./refresh-cw-1z9T44rc.js";import{a as Gt,c as Ot}from"./useFreemium-CE2uVj3A.js";import{C as is}from"./circle-check-DwmceHgL.js";import{T as V}from"./triangle-alert-CaBQ2GKx.js";import{T as Ye}from"./target-B1Ar92vS.js";import{L as se}from"./list-checks-CRAbaayb.js";import{K as os,F as Ze}from"./key-round-DvSxbS66.js";import{S as Ds}from"./shield-check-pk4vCEBJ.js";import{P as Dt}from"./pen-line-QHbgxTml.js";import{C as Is}from"./calendar-clock-vj1NYvku.js";import{C as ae}from"./check-iRIR4t7E.js";import{L as It}from"./lock-BZ0BQIkO.js";import{C as Vs}from"./copy-BMNs6JxP.js";import{E as Js}from"./external-link-DVvQ2qOO.js";import{S as Us}from"./save-i3KC44Wa.js";import{L as Qs}from"./lightbulb-DED9m2Yi.js";import{b as Vt,u as Jt}from"./useProfile-CS94G7F9.js";import{C as Ut}from"./CapaciteCard-D7Oh8cTb.js";import{W as Ae}from"./wallet-BJnLSRJT.js";import{S as Qt}from"./shield-alert-Dwjwpcdy.js";import{H as Ke}from"./hand-coins-AOEYZK42.js";import{u as Bt,p as Kt}from"./useObjectives-CjDv8Gso.js";import{p as es,a as Ht,c as Xt,b as Wt,f as ls,t as Bs,T as ye,d as He,g as Yt,O as Xe,h as Zt,i as er,j as sr}from"./projet-finance-DDZn9QUH.js";import{P as tr}from"./pencil-JPrQ3P9I.js";import{D as rr}from"./door-open--sn7dSDT.js";import{C as nr}from"./circle-question-mark-CSoqTNVK.js";import{W as we}from"./wand-sparkles-DtqoMwgg.js";import{A as Ks}from"./arrow-right-ClRYmJ9w.js";import{S as ar}from"./send-aGNW9eEl.js";import{S as ir}from"./SafeImage-fWvy3gps.js";import{A as cs}from"./arrow-left-DGLhCUMJ.js";import{T as or}from"./trash-2-kGadBVVn.js";import{L as Hs}from"./layout-dashboard-BGylKuDQ.js";import{C as lr}from"./chevron-down-DxhcEyXW.js";import{I as cr}from"./image-off-BSSiPOKh.js";import"./ecriture-guard-C2qLtfHI.js";import"./freemium-BbxWPx9a.js";import"./useScope-CLYbVEkB.js";import"./usePlan-DCyEl2y3.js";import"./useViewAs-BMT4VIl2.js";import"./subscription-T4ha2ROn.js";import"./social-GpM-F0Gm.js";import"./sheet-CrQ25CmC.js";import"./index-C1w7OvSc.js";import"./index-XLJRLJoS.js";import"./index-OzpVuhw5.js";import"./index-1vvNoPYX.js";import"./index-Bpzow1Yz.js";import"./x-D2_fecYF.js";import"./index-BNYIV8IE.js";import"./index-DjtSIepI.js";import"./index-CTo2-xz9.js";import"./index-C0vpHHMG.js";import"./chevron-right-Dt28cRRN.js";import"./circle-DEDMg4Py.js";import"./listing-quality-D0J7OZpe.js";import"./ville-Cbq_A6KQ.js";import"./lexique-D7UYB_MJ.js";import"./popover-18DRbp0p.js";import"./scale-BrtN9hoM.js";import"./FicheTerme-_rzBMQDx.js";import"./dialog-BO8k9DQ_.js";import"./textarea-hqvQrJCY.js";import"./label-DQK3yVeC.js";import"./circle-alert-CFoltYR2.js";const dr=[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]],ur=G("arrow-left-right",dr);const mr=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]],pr=G("clipboard-copy",mr);const xr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]],fr=G("clock-3",xr);const hr=[["path",{d:"m15 10 5 5-5 5",key:"qqa56n"}
1],["path",{d:"M4 4v7a4 4 0 0 0 4 4h12",key:"z08zvw"}]],gr=G("corner-down-right",hr);const br=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],jr=G("ellipsis-vertical",br);const vr=[["path",{d:"M10.5 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v6",key:"g5mvt7"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"m14 20 2 2 4-4",key:"15kota"}]],yr=G("file-check-corner",vr);const Nr=[["path",{d:"m11 17 2 2a1 1 0 1 0 3-3",key:"efffak"}],["path",{d:"m14 14 2.5 2.5a1 1 0 1 0 3-3l-3.88-3.88a3 3 0 0 0-4.24 0l-.88.88a1 1 0 1 1-3-3l2.81-2.81a5.79 5.79 0 0 1 7.06-.87l.47.28a2 2 0 0 0 1.42.25L21 4",key:"9pr0kb"}],["path",{d:"m21 3 1 11h-2",key:"1tisrp"}],["path",{d:"M3 3 2 14l6.5 6.5a1 1 0 1 0 3-3",key:"1uvwmv"}],["path",{d:"M3 4h8",key:"1ep09j"}]],Ce=G("handshake",Nr);const _r=[["path",{d:"M10 18v-7",key:"wt116b"}],["path",{d:"M11.12 2.198a2 2 0 0 1 1.76.006l7.866 3.847c.476.233.31.949-.22.949H3.474c-.53 0-.695-.716-.22-.949z",key:"1m329m"}],["path",{d:"M14 18v-7",key:"vav6t3"}],["path",{d:"M18 18v-7",key:"aexdmj"}],["path",{d:"M3 22h18",key:"8prr45"}],["path",{d:"M6 18v-7",key:"1ivflk"}]],kr=G("landmark",_r);const Ar=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M7 11h10",key:"1twpyw"}],["path",{d:"M7 15h6",key:"d9of3u"}],["path",{d:"M7 7h8",key:"af5zfr"}]],Xs=G("message-square-text",Ar);const wr=[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]],Cr=G("octagon-alert",wr);const Sr=[["path",{d:"M13 2a9 9 0 0 1 9 9",key:"1itnx2"}],["path",{d:"M13 6a5 5 0 0 1 5 5",key:"11nki7"}],["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]],ss=G("phone-call",Sr),Ws={contact:{slugs:["cinq-questions-avant-visite"],etapeAcademie:"projet"},visite:{slugs:["checklist-visite","cinq-questions-avant-visite"],etapeAcademie:"visite"},courtier:{slugs:["monter-dossier-banque","comprendre-offre-pret"],etapeAcademie:"financement"},offre:{slugs:["offre-sous-le-prix","annonce-qui-traine"],etapeAcademie:"offre"},financement:{slugs:["monter-dossier-banque","comprendre-offre-pret"],etapeAcademie:"financement"},compromis:{slugs:["compromis-sans-stress","chez-le-notaire"],etapeAcademie:"acte"},acte:{slugs:["chez-le-notaire","compromis-sans-stress"],etapeAcademie:"acte"}};function zr(s,t=2){const r=Ws[s];if(!r||t<=0)return[];const n=new Set,i=[];for(const a of r.slugs){if(i.length>=t)return i;const c=dt(a);c&&!n.has(c.slug)&&(i.push(c),n.add(c.slug))}
1if(r.etapeAcademie)for(const a of Ls(r.etapeAcademie)){if(i.length>=t)break;n.has(a.slug)||(i.push(a),n.add(a.slug))}return i}function Er(s){const t=Ws[s];return t?.etapeAcademie&&Ls(t.etapeAcademie).length>0?t.etapeAcademie:null}const $r=Et,Pr=$t,qr=Pt;function Lr(s){const{user:t}=We();return _e({queryKey:["action-plan",s],enabled:!!t&&!!s,queryFn:async()=>{const{data:r,error:n}=await I.from("action_plans").select("id,plan,updated_at").eq("project_id",s).maybeSingle();if(n)throw n;return r?{id:r.id,plan:r.plan,updatedAt:r.updated_at}:null}})}function Mr(){const s=J();return U({mutationFn:async t=>{const r=await ut(t);if(!r.ok)throw new Error(r.error||"Génération impossible");return r.plan},onSuccess:(t,r)=>s.invalidateQueries({queryKey:["action-plan",r]})})}function Tr(){const s=J();return U({mutationFn:async({projectId:t,plan:r,sectionKey:n,index:i,done:a})=>{const c={...r,sections:r.sections.map(d=>d.key===n?{...d,items:d.items.map((o,u)=>u===i?{...o,done:a}:o)}:d)},{error:l}=await I.from("action_plans").update({plan:c}).eq("project_id",t);if(l)throw l;return c},onSuccess:(t,r)=>s.invalidateQueries({queryKey:["action-plan",r.projectId]})})}const ds="questions_avant_rdv",us=["J'analyse l'annonce…","Je croise avec le marché du secteur…","Je prépare vos questions et vos arguments…","Encore un instant, je rédige…"],ms="Ça prend en général 30 secondes à 1 minute.";function Rr({projectId:s}){const{data:t,isLoading:r}=Lr(s),{data:n}=Fs(s),i=Mr(),a=Tr(),c=n?.annonce_snapshot??{},l=typeof c.ville=="string"?c.ville:"",d=typeof c.cp=="string"?c.cp:void 0,o=async()=>{try{await i.mutateAsync(s),f.success("Plan d'attaque généré")}catch(j){f.error("Erreur : "+j.message)}};if(r)return e.jsx(E,{className:"h-40 w-full"});if(!t)return e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"border border-dashed border-border rounded-xl p-8 text-center",children:i.isPending?e.jsx(S,{messages:us,estimation:ms}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Questions à poser avant le RDV puis en visite, points à vérifier, risques et arguments de négociation, générés à partir de l'annonce et du marché du secteur."}),e.jsxs("button",{type:"button",onClick:o,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer le plan d'attaque"]})]})}),e.jsx(as,{ville:l,cp:d})]});const{plan:u}=t,m=u.sections.reduce((j,w)=>j+w.items.length,0),x=u.sections.reduce((j,w)=>j+w.items.filter(h=>h.done).length,0),p=u.sections.find(j=>j.key===ds),b=u.sections.filter(j=>j.key!==ds),N=j=>e.jsx("ul",{className:"space-y-1.5",children:j.items.map((w,h)=>e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-2.5 text-sm cursor-pointer group",children:[e.jsx(ee,{checked:w.done,onCheckedChange:g=>a.mutate({projectId:s,plan:u,sectionKey:j.key,index:h,done:g===!0}),className:"mt-0.5"}),e.jsx("span",{className:w.done?"line-through text-muted-foreground":"group-hover:text-foreground",children:e.jsx(_,{texte:w.text})})]})},j.key+h))});return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5 mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-4 flex-wrap",children:[e.jsx("div",{className:"text-sm text-muted-foreground leading-relaxed flex-1 min-w-[240px]",children:e.jsx(_,{texte:u.resume})}),e.jsxs("button",{type:"button",disabled:i.isPending,onClick:()=>{confirm("Régénérer le plan ? Les coches actuelles seront perdues.")&&o()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${i.isPending?"animate-spin":""}`}),i.isPending?"Génération…":"Régénérer"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[x,"/",m," items traités · généré le"," ",new Date(u.generated_at).toLocaleStr
1ing("fr-FR")]}),e.jsx(F,{bloc:"plan-attaque",sourceTable:"action_plans",sourceId:t.id})]}),e.jsx(as,{ville:l,cp:d,className:"mb-5"}),i.isPending&&e.jsx("div",{className:"mb-5 rounded-xl border border-primary/30 bg-primary/5",children:e.jsx(S,{messages:us,estimation:ms})}),p&&e.jsxs("section",{className:"mb-6 rounded-xl border border-amber/60 bg-amber/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(Os,{className:"size-4 text-amber shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:e.jsx(_,{texte:p.titre})}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-amber border border-amber/60 bg-amber/10 rounded-full px-2 py-0.5",children:"Prioritaire"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3",children:"L'essentiel à valider au téléphone, avant même de vous déplacer."}),N(p)]}),b.map(j=>e.jsxs("section",{className:"mb-5",children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:e.jsx(_,{texte:j.titre})}),N(j)]},j.key))]})}function ts(s){const{user:t}=We();return _e({queryKey:["bien-analyse",s,"quality-v1"],enabled:!!t&&!!s,queryFn:async()=>{const[{data:r,error:n},i]=await Promise.all([I.from("bien_analyses").select("id,analyse,updated_at").eq("project_id",s).maybeSingle(),I.from("projects").select("annonce_snapshot").eq("id",s).maybeSingle()]);if(n)throw n;if(i.error)throw i.error;if(!r)return null;const a=Ft(r.analyse,i.data?.annonce_snapshot);return a?{id:r.id,analyse:a,updatedAt:r.updated_at}:null}})}function Ys(){const s=J();return U({mutationFn:async t=>{const r=await mt(t);if(!r.ok)throw new Error(r.error||"Analyse impossible");return Rt(r.analyse)},onSuccess:(t,r)=>s.invalidateQueries({queryKey:["bien-analyse",r]})})}const Fr=["Je relis l'annonce et vos chiffres…","Je croise le prix avec votre capacité d'emprunt…","Je vérifie l'adéquation avec votre objectif…","Encore un instant, je rédige l'analyse…"],Gr="Ça prend en général 30 secondes à 1 minute.",Or={pos:"border-pos/60 bg-pos/10 text-pos",amber:"border-amber/60 bg-amber/10 text-amber",neg:"border-neg/60 bg-neg/10 text-neg"};function Dr({projectId:s}){const{data:t,isLoading:r}=ts(s),n=Ys(),i=Gt(),a=Ot(i),c=async()=>{try{await n.mutateAsync(s),f.success("Analyse générée")}catch(m){f.error("Erreur : "+m.message)}};if(r)return e.jsx(E,{className:"h-40 w-full"});if(!t)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 md:p-8 text-center mb-6",children:n.isPending?e.jsx(S,{messages:Fr,estimation:Gr}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(A,{className:"size-4 text-primary"})," Analyse complète du bien"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Un dossier personnalisé pour ce bien : verdict, adéquation avec votre objectif et votre capacité d'emprunt, points forts, points de vigilance, risques et prochaines étapes."}),e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Lancer l'analyse"]}),i&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-3",children:["Mode gratuit : ",a.restantes,"/",a.total," analyse","s"," restante",a.restantes>1?"s":""," sur 30 jours."]})]})});const{analyse:l,updatedAt:d}=t,o=Be[l.verdict],u=pt(l);return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5 mb-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(A,{className:"size-4 text-primary"})," Analyse complète du bien"]}),e.jsx("span",{className:`text-[11px] font-bold uppercase tracking-wider border rounded-full px-2.5 py-0.5 ${Or[o.ton]}`,children:o.label})]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{confirm("Relancer l'analyse ? La version actuelle sera remplacée.")&&c()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Analyse…":"Relancer"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:o.accroche}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 mb-4",children:[e.jsx(le,{titre:"Points clés",items:u.points,icon:e.jsx(is,{className:"size-3.5 text-pos"})}),e.jsx(le,{titre:"À vérifier en priorité",items:u.verifications,icon:e.jsx(V,{className:"size-3.5 text-amber"})})]}),e.jsxs("details",{className:"border-t border-border pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold",children:"Lire l'anal
1yse détaillée"}),e.jsxs("div",{className:"mt-4",children:[l.syntheseGlobale&&e.jsx("p",{className:"text-sm leading-relaxed mb-4",children:e.jsx(_,{texte:l.syntheseGlobale})}),l.adequationObjectif&&e.jsxs("div",{className:"flex items-start gap-2 bg-input border border-border rounded-lg p-3 mb-4",children:[e.jsx(Ye,{"aria-hidden":!0,className:"size-4 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground block",children:"Adéquation avec votre objectif"}),e.jsx(_,{texte:l.adequationObjectif})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(le,{titre:"Points forts",items:u.autresPoints,icon:e.jsx(is,{className:"size-3.5 text-pos"})}),e.jsx(le,{titre:"Points de vigilance",items:u.autresVerifications,icon:e.jsx(V,{className:"size-3.5 text-amber"})})]}),u.etapes.length>0&&e.jsx("div",{className:"mt-4",children:e.jsx(le,{titre:"Prochaines étapes",items:u.etapes,icon:e.jsx(se,{className:"size-3.5 text-primary"})})})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4 flex-wrap",children:[d?e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Générée le ",new Date(l.generated_at||d).toLocaleString("fr-FR")]}):e.jsx("span",{}),e.jsx(F,{bloc:"bien-analyse",sourceTable:"bien_analyses",sourceId:t.id})]})]})}function le({titre:s,items:t,icon:r}){return t.length===0?null:e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[r," ",s]}),e.jsx("ul",{className:"space-y-1.5",children:t.map((n,i)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{}),e.jsx("span",{children:e.jsx(_,{texte:n})})]},s+i))})]})}const Ir=["Je relis l'annonce et vos chiffres…","Je croise le prix avec votre capacité d'emprunt…","Je vérifie l'adéquation avec votre objectif…","Encore un instant, je rédige l'analyse…"],Vr="Ça prend en général 30 secondes à 1 minute.";function Jr({projectId:s}){const t=Ys(),r=async()=>{try{await t.mutateAsync(s),f.success("Analyse générée")}catch(n){f.error("Erreur : "+n.message)}};return e.jsx("div",{className:"border border-dashed border-primary/50 bg-primary/5 rounded-xl p-6 text-center",children:t.isPending?e.jsx(S,{messages:Ir,estimation:Vr}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," D'abord, analysez le bien"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Lancez l'analyse du bien pour débloquer les recommandations de cette étape : c'est elle qui alimente la checklist de contact, le plan de visite, l'offre et toute la suite de votre piste."}),e.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Lancer l'analyse"]}),e.jsx("div",{className:"mt-3",children:e.jsx(H,{to:"/app/projets/$id",params:{id:s},search:{etape:"apercu"},className:"text-xs text-muted-foreground hover:text-primary underline underline-offset-2",children:"Voir le panneau Aperçu de la piste"})})]})})}function q(s,t){const{user:r}=We();return _e({queryKey:["projet-etape-ia",s,t],enabled:!!r&&!!s,queryFn:async()=>{const{data:n,error:i}=await I.from("projet_etape_ia").select("id,data,model,updated_at").eq("project_id",s).eq("kind",t).maybeSingle();if(i)throw i;return n?{id:n.id,data:n.data??{},model:n.model,updatedAt:n.updated_at}:null}})}function X(){const s=J();return U({mutationFn:async({projectId:t,kind:r,saisie:n})=>{const i=await Ms(t,r,n);if(!i.ok)throw new Error(i.error||"Génération impossible");return i.data},onSuccess:(t,r)=>s.invalidateQueries({queryKey:["projet-etape-ia",r.projectId,r.kind]})})}function Ur(){const s=J();return U({mutationFn:async({projectId:t,infos:r})=>{const n=await Ms(t,"contact_infos",r);if(!n.ok)throw new Error(n.error||"Enregistrement impossible");return n.data},onSuccess:(t,r)=>s.invalidateQueries({queryKey:["projet-etape-ia",r.projectId,"contact_infos"]})})}const fe="acte_checkpoints",Se=[{key:"avant_le_jour_j",titre:"Avant le jour J"},{key:"le_jour_j",titre:"Le jour J"},{key:"juste_apres",titre:"Juste après"}],ps=["Je relis votre dossier…","Je prépare votre dernier contrôle…","Encore un instant, les clés sont presque à vous…"],xs="Ça prend en général 30 secondes à 1 minute.";function ze(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.length>0):[]}function Qr(s){if(!s)return null;const t=ze(s.avant_le_jour_j),r=ze(s.le_jour_j),n=ze(s.juste_apres);if(!t.length||!r.length||!n.length)return null;const i=s.coches&&typeof s.coches=="object"&&!Array.isArray(s.coches)?s.coches:{};return{avant_le_jour_j:t,le_jour_j:r,juste_apres:n,generated_at:typeof s.generated_at=="string"?s.generated_at:void 0,coches:i}}function Br({project:s}){const t=J(),{data:r,isLoading:n}=q(s.id,fe),i=X(),a=Qr(r?.data),c=async()=>{try{await i.mutateAsync({projectId:s.id,kind:fe}),f.success("Point de contrôle généré")}catch(u){f.error("Erreur : "+u.message)}},l=U({mutationFn:async({cle:u,coche:m})=>{const x={...a?.coches??{},[u]:m},{error:p}=await I.from("projet_etape_ia").update({data:{...r?.data??{},coches:x}}).eq("project_id",s.id).eq("kind",fe);if(p)throw p},onSuccess:()=>
1t.invalidateQueries({queryKey:["projet-etape-ia",s.id,fe]}),onError:u=>f.error("Erreur : "+u.message)});if(n)return e.jsx(E,{className:"h-20 w-full"});if(!a)return e.jsx("div",{className:"border border-border rounded-xl p-4",children:i.isPending?e.jsx(S,{messages:ps,estimation:xs}):e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold",children:[e.jsx(os,{"aria-hidden":!0,className:"size-4 text-primary"}),"Le dernier contrôle avant les clés"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Un micro point personnalisé pour arriver serein chez le notaire."})]}),e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1.5 text-xs font-medium border border-border hover:border-primary hover:text-primary rounded-lg px-3 py-1.5 shrink-0",children:[e.jsx(A,{className:"size-3.5"}),"Générer"]})]})});const d=Se.reduce((u,m)=>u+a[m.key].length,0),o=Se.reduce((u,m)=>u+a[m.key].filter((x,p)=>a.coches[`${m.key}:${p}`]).length,0);return e.jsxs("div",{className:"border border-border rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-3 flex-wrap",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold",children:[e.jsx(os,{"aria-hidden":!0,className:"size-4 text-primary"}),"Le dernier contrôle avant les clés",e.jsxs("span",{className:"text-[11px] font-normal text-muted-foreground",children:[o,"/",d]})]}),e.jsxs("button",{type:"button",disabled:i.isPending,onClick:()=>{confirm("Régénérer le point de contrôle ? Les coches actuelles seront perdues.")&&c()},className:"text-[11px] text-muted-foreground hover:text-primary inline-flex items-center gap-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${i.isPending?"animate-spin":""}`}),i.isPending?"Génération…":"Régénérer"]})]}),i.isPending&&e.jsx("div",{className:"mb-3 rounded-lg border border-primary/30 bg-primary/5",children:e.jsx(S,{messages:ps,estimation:xs})}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-3",children:Se.map(u=>e.jsxs("section",{children:[e.jsx("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground mb-1.5",children:u.titre}),e.jsx("ul",{className:"space-y-1.5",children:a[u.key].map((m,x)=>{const p=`${u.key}:${x}`,b=!!a.coches[p];return e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-2 text-xs cursor-pointer group",children:[e.jsx(ee,{checked:b,onCheckedChange:N=>l.mutate({cle:p,coche:N===!0}),className:"mt-0.5"}),e.jsx("span",{className:b?"line-through text-muted-foreground":"text-foreground/90 group-hover:text-foreground",children:m})]})},p)})})]},u.key))}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-3 flex-wrap",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:a.generated_at&&`généré le ${new Date(a.generated_at).toLocaleDateString("fr-FR")}`}),r&&e.jsx(F,{bloc:"acte_checkpoints",sourceTable:"projet_etape_ia",sourceId:r.id})]})]})}const W=s=>typeof s=="string"&&s.trim().length>0;function Ee(s){return Array.isArray(s)?s.filter(W):[]}function Kr(s){return Array.isArray(s)?s.flatMap(t=>{const r=t??{};return W(r.moment)&&W(r.explication)?[{moment:r.moment,explication:r.explication}]:[]}):[]}function Hr(s){return Array.isArray(s)?s.flatMap(t=>{const r=t??{};return W(r.nom)&&W(r.duree)&&W(r.detail)?[{nom:r.nom,duree:r.duree,detail:r.detail}]:[]}):[]}function Xr(s){if(!s)return null;const t=Kr(s.deroule),r=Ee(s.avant_de_signer);if(t.length===0&&r.length===0)return null;const n=s.condition_suspensive??{},i=Array.isArray(s.coches)?s.coches.filter(a=>Number.isInteger(a)&&a>=0):[];return{deroule:t,avant_de_signer:r,condition_suspensive:{conseil:W(n.conseil)?n.conseil:"",parametres:Ee(n.parametres)},points_attention:Ee(s.points_attention),delais_cles:Hr(s.delais_cles),generated_at:W(s.generated_at)?s.generated_at:void 0,coches:i.filter(a=>a<r.length)}}function Wr(s,t,r){const n=s.filter(i=>i!==t);return(r?[...n,t]:n).sort((i,a)=>i-a)}const Ne="compromis_guide",fs=["Je relis votre dossier et l'annonce…","Je déroule les étapes jusqu'à l'acte…","Je cale votre condition suspensive sur vos chiffres…","Encore un instant, je rédige votre guide…"],hs="Ça prend en général 30 secondes à 1 minute.";function Yr(s){const t=J();return U({mutationFn:async({data:r,index:n,done:i})=>{const a=Array.isArray(r.coches)?r.coches.filter(d=>
1Number.isInteger(d)):[],c={...r,coches:Wr(a,n,i)},{error:l}=await I.from("projet_etape_ia").update({data:c}).eq("project_id",s).eq("kind",Ne);if(l)throw l;return c},onSuccess:r=>t.setQueryData(["projet-etape-ia",s,Ne],n=>n&&{...n,data:r}),onError:r=>f.error("Coche non enregistrée : "+r.message)})}function Zr({project:s}){const{data:t,isLoading:r}=q(s.id,Ne),n=X(),i=Yr(s.id),a=async()=>{try{await n.mutateAsync({projectId:s.id,kind:Ne}),f.success("Guide du compromis généré")}catch(o){f.error("Erreur : "+o.message)}};if(r)return e.jsx(E,{className:"h-40 w-full"});const c=Xr(t?.data);if(!c)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 md:p-8 text-center",children:n.isPending?e.jsx(S,{messages:fs,estimation:hs}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(Qe,{"aria-hidden":!0,className:"size-4 text-primary"})," Préparez votre signature sereinement"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Comment votre signature va se dérouler, quoi relire avant de signer et la condition suspensive calée sur votre dossier : un guide personnalisé à partir de votre projet."}),e.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer mon guide"]})]})});const l=new Set(c.coches),d=c.avant_de_signer.length;return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Qe,{"aria-hidden":!0,className:"size-4 text-primary"})," Préparez votre signature sereinement"]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{confirm("Régénérer le guide ? La version actuelle et vos coches seront remplacées.")&&a()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Génération…":"Régénérer"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Le compromis vous engage et déclenche les délais de votre prêt : voici votre guide, calé sur votre dossier."}),n.isPending&&e.jsx("div",{className:"mb-5 rounded-xl border border-primary/30 bg-primary/5",children:e.jsx(S,{messages:fs,estimation:hs})}),c.deroule.length>0&&e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Comment ça va se dérouler"}),e.jsx("ol",{className:"relative ml-2.5 border-l border-border pl-6 space-y-4",children:c.deroule.map((o,u)=>e.jsxs("li",{className:"relative",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute -left-[34px] top-0 flex size-5 items-center justify-center rounded-full border border-primary/50 bg-primary/15 text-[10px] font-bold text-primary",children:u+1}),e.jsx("div",{className:"text-sm font-semibold leading-5",children:e.jsx(_,{texte:o.moment})}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:e.jsx(_,{texte:o.explication})})]},o.moment+u))})]}),(c.condition_suspensive.conseil||c.condition_suspensive.parametres.length>0)&&e.jsxs("section",{className:"mb-6 rounded-xl border-2 border-primary/50 bg-primary/10 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(Ds,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"La condition suspensive de prêt"}),e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider text-primary border border-primary/50 bg-primary/10 rounded-full px-2 py-0.5",children:"Votre protection"})]}),c.condition_suspensive.conseil&&e.jsx("p",{className:"text-sm leading-relaxed mb-3",children:e.jsx(_,{texte:c.condition_suspensive.conseil})}),c.condition_suspensive.parametres.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground mb-1.5",children:"À faire écrire noir sur blanc"}),e.jsx("ul",{className:"space-y-1.5",children:c.condition_suspensive.parametres.map((o,u)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(Dt,{"aria-hidden":!0,
1className:"size-3.5 text-primary shrink-0 mt-0.5"}),e.jsx("span",{children:e.jsx(_,{texte:o})})]},o+u))})]})]}),d>0&&e.jsxs("section",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[e.jsx(se,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Avant de signer"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[l.size,"/",d," relus"]})]}),e.jsx("ul",{className:"space-y-1.5",children:c.avant_de_signer.map((o,u)=>e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-2.5 text-sm cursor-pointer group",children:[e.jsx(ee,{checked:l.has(u),disabled:i.isPending,onCheckedChange:m=>i.mutate({data:t?.data??{},index:u,done:m===!0}),className:"mt-0.5"}),e.jsx("span",{className:l.has(u)?"line-through text-muted-foreground":"group-hover:text-foreground",children:e.jsx(_,{texte:o})})]})},o+u))})]}),c.points_attention.length>0&&e.jsxs("section",{className:"mb-6 rounded-xl border border-amber/60 bg-amber/5 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(V,{"aria-hidden":!0,className:"size-4 text-amber shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Points d'attention sur votre dossier"})]}),e.jsx("ul",{className:"space-y-1.5",children:c.points_attention.map((o,u)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(V,{"aria-hidden":!0,className:"size-3.5 text-amber shrink-0 mt-0.5"}),e.jsx("span",{children:e.jsx(_,{texte:o})})]},o+u))})]}),c.delais_cles.length>0&&e.jsxs("section",{className:"mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Les délais à caler dans votre calendrier"}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:c.delais_cles.map((o,u)=>e.jsxs("div",{className:"bg-input border border-border rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider font-semibold text-muted-foreground",children:[e.jsx(Is,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),e.jsx("span",{children:o.nom})]}),e.jsx("div",{className:"text-base font-bold text-primary my-0.5",children:o.duree}),e.jsx("p",{className:"text-xs text-muted-foreground",children:e.jsx(_,{texte:o.detail})})]},o.nom+u))})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 flex-wrap text-[11px] text-muted-foreground",children:[e.jsx("span",{children:(c.generated_at||t?.updatedAt)&&`Généré le ${new Date(c.generated_at||t.updatedAt).toLocaleString("fr-FR")}`}),e.jsxs("span",{className:"flex items-center gap-3",children:["Votre notaire reste la référence pour votre cas précis.",t&&e.jsx(F,{bloc:"compromis_guide",sourceTable:"projet_etape_ia",sourceId:t.id})]})]})]})}function en(s){const t=J(),r=["projet-etape-ia",s,"contact_checklist"];return U({mutationFn:async({data:n,coches:i})=>{const a={...n,coches:i},{error:c}=await I.from("projet_etape_ia").update({data:a,updated_at:new Date().toISOString()}).eq("project_id",s).eq("kind","contact_checklist");if(c)throw c;return a},onMutate:async({data:n,coches:i})=>{await t.cancelQueries({queryKey:r});const a=t.getQueryData(r);return a&&t.setQueryData(r,{...a,data:{...n,coches:i}}),{precedent:a}},onError:(n,i,a)=>{a?.precedent!==void 0&&t.setQueryData(r,a.precedent),f.error("La coche n'a pas pu être enregistrée, réessaie.")},onSettled:()=>t.invalidateQueries({queryKey:r})})}function B(s){if(typeof s!="string")return null;const t=s.trim();return t||null}function $e(s){const t=Number(s);return Number.isFinite(t)&&t>0?t:null}function Zs(s){const t=s&&typeof s=="object"&&!Array.isArray(s)?s:{};return{titre:B(t.titre),ville:B(t.ville),cp:B(t.cp),prix:$e(t.prix),surface:$e(t.surface),pieces:$e(t.pieces),ref:B(t.ref),url:B(t.url),agence:B(t.agence),tel:B(t.tel)??B(t.telephone)??B(t.phone)}}const sn={analyse_requise:"Lancez d'abord l'analyse approfondie du bien : elle alimente le contact vendeur.",profil_financier_requis:"Renseignez vos revenus et votre apport dans votre profil : sans eux, impossible de proposer un montant crédible ni d'écrire quoi que ce soit sur votre financement.",prix_affiche_requis:"Le prix affiché de ce bien est introuvable : complète-le sur la fiche pour que le montant d'offre puisse être calculé."};function et(s){const t=s instanceof Error?s.message:String(s);return sn[t]??"Erreur : "+t}function tn({project:s}){const t=ts(s.id),r=q(s.id,"contact_arguments"),n=q(s.id,"contact_email"),i=X(),a=y.useMemo(()=>an(r.data?.data),[r.data]),c=y.useMemo(()=>on(n.data?.data),[n.data]),l=y.useMemo(()=>Zs(s.annonce_snapshot),[s.annonce_snapshot]),d=!!t.data,o=r.data?.updatedAt??null,u=n.data?.updatedAt??null,m=!!c&&!!o&&!!u&&new Date(o)>new Date(u),x=async()=>{try{await i.mutateAsync({projectId:s.id,kind:"contact_arguments"}),f.success("Vos arguments sont prêts")}catch(j){f.error(js(j))}},p=async()=>
1{if(a)try{await i.mutateAsync({projectId:s.id,kind:"contact_email",saisie:{arguments:a.arguments}}),f.success("Votre email au vendeur est prêt")}catch(j){f.error(js(j))}},b=i.isPending,N=i.variables?.kind;return e.jsxs("section",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Xs,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Contacter le vendeur, en 3 temps"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-4",children:"On enchaîne dans l'ordre : l'analyse du bien nourrit vos arguments, et vos arguments nourrissent l'email. Chaque temps s'appuie sur le précédent pour un message vraiment juste."}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Pe,{numero:1,titre:"L'analyse du bien",faite:d,children:t.isLoading?e.jsx(E,{className:"h-10 w-full"}):d&&t.data?e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:`inline-flex items-center gap-1.5 text-[11px] font-semibold rounded-full px-2 py-0.5 border ${ln[Be[t.data.analyse.verdict].ton]}`,children:Be[t.data.analyse.verdict].label}),t.data.analyse.syntheseGlobale&&e.jsx("p",{className:"text-muted-foreground mt-1.5 leading-relaxed",children:e.jsx(_,{texte:t.data.analyse.syntheseGlobale})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"L'analyse approfondie du bien alimente tout ce qui suit. Lancez-la depuis l'onglet Aperçu & analyse du projet."})}),e.jsx(Pe,{numero:2,titre:"Vos arguments face au vendeur",faite:!!a,verrouille:!d,children:d?b&&N==="contact_arguments"?e.jsx(S,{messages:cn,estimation:vs}):a?e.jsxs("div",{className:"space-y-3",children:[a.synthese&&e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:e.jsx(_,{texte:a.synthese})}),e.jsx("ul",{className:"space-y-1.5",children:a.arguments.map((j,w)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(K,{}),e.jsx("span",{children:e.jsx(_,{texte:j})})]},w))}),e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[r.data&&e.jsx(F,{bloc:"contact_arguments",sourceTable:"projet_etape_ia",sourceId:r.data.id}),e.jsx(st,{disabled:b,onClick:x,confirmMsg:"Régénérer vos arguments ? Votre email devra être régénéré ensuite pour rester cohérent."})]})]}):e.jsx(bs,{disabled:b,onClick:x,label:"Générer mes arguments"}):e.jsx(gs,{children:"Faites d'abord l'analyse du bien (temps 1)."})}),e.jsx(Pe,{numero:3,titre:"Votre email au vendeur",faite:!!c,verrouille:!a,children:a?b&&N==="contact_email"?e.jsx(S,{messages:dn,estimation:vs}):c?e.jsx(rn,{email:c,infos:l,perime:m,onRegenerer:p,regenDisabled:b,sourceId:n.data?.id??null}):e.jsx(bs,{disabled:b,onClick:p,label:"Générer mon email"}):e.jsx(gs,{children:"Générez d'abord vos arguments (temps 2)."})})]})]})}function Pe({numero:s,titre:t,faite:r,verrouille:n,children:i}){return e.jsxs("div",{className:`rounded-lg border p-3.5 ${n?"border-dashed border-border bg-input/40":"border-border bg-input/60"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:`inline-flex items-center justify-center size-6 rounded-full text-xs font-bold shrink-0 ${r?"bg-pos/15 text-pos border border-pos/40":n?"bg-transparent text-muted-foreground/60 border border-border":"bg-primary text-primary-foreground"}`,children:r?e.jsx(ae,{"aria-hidden":!0,className:"size-3.5"}):s}),e.jsx("h4",{className:"text-sm font-semibold",children:t}),n&&e.jsx(It,{"aria-hidden":!0,className:"size-3 text-muted-foreground/60"})]}),e.jsx("div",{className:"pl-8",children:i})]})}function gs({children:s}){return e.jsx("p",{className:"text-xs text-muted-foreground/80",children:s})}function bs({label:s,onClick:t,disabled:r}){return e.jsxs("button",{type:"button",disabled:r,onClick:t,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2 text-sm hover:brightness-110 disabled:opacity-50",children:[e.jsx(A,{className:"size-4"}),s]})}function st({onClick:s,disabled:t,confirmMsg:r}){return e.jsxs("button",{type:"button",disabled:t,onClick:()=>{confirm(r)&&s()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1",children:[e.jsx(L,{className:`size-3 ${t?"animate-spin":""}`}),"Régénérer"]})}
1function rn({email:s,infos:t,perime:r,onRegenerer:n,regenDisabled:i,sourceId:a}){const[c,l]=y.useState("email"),d=c==="email",o=async()=>{const u=d?`Objet : ${s.emailObjet}
2
3${s.emailLong}`:s.messageCourt;try{await navigator.clipboard.writeText(u),f.success(d?"Email copié (objet inclus)":"Message copié")}catch{f.error("Copie impossible sur cet appareil")}};return e.jsxs("div",{className:"space-y-3",children:[r&&e.jsxs("div",{className:"flex items-start gap-2 text-[11px] text-amber border border-amber/50 bg-amber/10 rounded-md px-2.5 py-1.5",children:[e.jsx(L,{"aria-hidden":!0,className:"size-3.5 shrink-0 mt-0.5"}),"Vos arguments ont changé depuis. Régénérez l'email pour qu'il reste cohérent."]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:[{v:"email",label:"Email détaillé"},{v:"message",label:"Message court"}].map(u=>e.jsx("button",{type:"button",onClick:()=>l(u.v),className:`text-xs rounded-md px-2.5 py-1 border transition-colors ${c===u.v?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:u.label},u.v))}),e.jsxs("div",{className:"bg-card border border-border rounded-lg p-3 text-sm leading-relaxed",children:[d&&e.jsxs("div",{className:"text-[11px] text-muted-foreground mb-2",children:[e.jsx("span",{className:"uppercase tracking-wider font-semibold",children:"Objet"})," :"," ",s.emailObjet]}),e.jsx("div",{className:"whitespace-pre-line",children:d?s.emailLong:s.messageCourt})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{o()},className:"inline-flex items-center gap-1.5 bg-primary text-primary-foreground rounded-lg px-3 py-1.5 text-sm font-semibold hover:brightness-110",children:[e.jsx(Vs,{className:"size-3.5"})," Copier"]}),t.url&&e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-primary border border-border hover:border-primary rounded-lg px-3 py-1.5",children:[e.jsx(Js,{className:"size-3.5"})," Ouvrir l'annonce pour l'envoyer"]}),t.tel&&e.jsxs("a",{href:`tel:${t.tel.replace(/[^\d+]/g,"")}`,className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-primary border border-border hover:border-primary rounded-lg px-3 py-1.5",children:[e.jsx(Os,{className:"size-3.5"})," Appeler",t.agence?` ${t.agence}`:""]}),e.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[a&&e.jsx(F,{bloc:"contact_email",sourceTable:"projet_etape_ia",sourceId:a}),e.jsx(st,{disabled:i,onClick:n,confirmMsg:"Régénérer l'email à partir de vos arguments actuels ?"})]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(Ze,{"aria-hidden":!0,className:"size-3"}),"Ajoutez votre nom et vos coordonnées avant l'envoi."]})]})}const je=s=>typeof s=="string"?s:"",nn=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.trim().length>0):[];function an(s){if(!s)return null;const t=nn(s.arguments);return t.length===0?null:{synthese:je(s.synthese),arguments:t}}function on(s){if(!s)return null;const t=je(s.message_court),r=je(s.email_objet),n=je(s.email_long);return!n&&!t?null:{messageCourt:t,emailObjet:r,emailLong:n}}function js(s){return et(s)}const ln={pos:"border-pos/60 bg-pos/10 text-pos",amber:"border-amber/60 bg-amber/10 text-amber",neg:"border-neg/60 bg-neg/10 text-neg"},vs="Ça prend en général 20 à 40 secondes.",cn=["Je relis l'analyse du bien…","Je repère vos meilleurs atouts…","Je formule vos arguments…"],dn=["Je pars de vos arguments…","Je rédige l'email au vendeur…","Encore un instant, je peaufine…"];function un({project:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx(tn,{project:s}),e.jsxs("details",{className:"rounded-xl border border-border bg-card",children:[e.jsx("summary",{className:"cursor-pointer p-4 text-sm font-semibold",children:"Préparer les questions de l'appel"}),e.jsx(fn,{projectId:s.id})]}),e.jsxs("details",{className:"rounded-xl border border-border bg-card",children:[e.jsx("summary",{className:"cursor-pointer p-4 text-sm font-semibold",children:"Noter les réponses du vendeur"}),e.jsx(yn,{projectId:s.id})]}),e.jsxs("details",{className:"rounded-xl border border-border bg-card",children:[e.jsx("summary",{className:"cursor-pointer p-4 text-sm font-semibold",children:"Réévaluer le bien après l'appel"}),e.jsx(An,{projectId:s.id})]})]})}const mn=["Je relis votre dossier et l'analyse du bien…","Je repère ce qui manque encore…","Je rédige des questions à poser telles quelles…","Encore un instant, je les classe par priorité…"],pn="Ça prend en général 20 à 40 secondes.";function xn(s){if(!s)return null;const t=Array.isArray(s.sections)?s.sections:[],r=[];for(const i of t){if(!i||typeof i!="object")continue;const a=i,c=typeof a.titre=="string"?a.titre:"",l=[];if(Array.isArray(a.questions))for(const d of a.questions){if(!d||typeof d!="object")continue;const o=d;
3typeof o.question=="string"&&o.question&&l.push({question:o.question,pourquoi:typeof o.pourquoi=="string"&&o.pourquoi?o.pourquoi:void 0})}else if(Array.isArray(a.points))for(const d of a.points)typeof d=="string"&&d&&l.push({question:d});c&&l.length&&r.push({titre:c,questions:l})}if(!r.length)return null;const n={};if(s.coches&&typeof s.coches=="object"&&!Array.isArray(s.coches))for(const[i,a]of Object.entries(s.coches))typeof a=="boolean"&&(n[i]=a);return{titre:typeof s.titre=="string"&&s.titre?s.titre:"Votre checklist d'appel",sections:r,coches:n,generatedAt:typeof s.generated_at=="string"?s.generated_at:void 0}}const qe=(s,t)=>`s${s}q${t}`;function fn({projectId:s}){const{data:t,isLoading:r}=q(s,"contact_checklist"),n=X(),i=en(s),a=y.useMemo(()=>xn(t?.data),[t]),c=async()=>{try{await n.mutateAsync({projectId:s,kind:"contact_checklist"}),f.success("Votre checklist d'appel est prête")}catch(u){const m=u.message;m==="analyse_requise"?f.error("Lancez d'abord l'analyse approfondie du bien : c'est elle qui alimente votre checklist."):f.error("Erreur : "+m)}};if(r)return e.jsx(E,{className:"h-32 w-full"});if(!a)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 text-center",children:n.isPending?e.jsx(S,{messages:mn,estimation:pn}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(se,{"aria-hidden":!0,className:"size-4 text-primary"})," Votre checklist d'appel"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Les questions à poser à l'agence ou au vendeur, préparées pour ce bien précis à partir de votre dossier : ce que l'annonce ne dit pas, ce que l'analyse veut vérifier, ce qui manque encore. Vous cochez au fil de l'appel."}),e.jsxs("button",{type:"button",onClick:()=>{c()},className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer ma checklist d'appel"]})]})});const l=a.sections.reduce((u,m)=>u+m.questions.length,0),d=a.sections.reduce((u,m,x)=>u+m.questions.filter((p,b)=>a.coches[qe(x,b)]).length,0),o=(u,m)=>{if(!t)return;const x=qe(u,m);i.mutate({data:t.data,coches:{...a.coches,[x]:!a.coches[x]}})};return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold min-w-0",children:[e.jsx(se,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),a.titre]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:[d,"/",l," posées"]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{confirm("Régénérer la checklist ? La version actuelle et vos coches seront remplacées.")&&c()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Génération…":"Régénérer"]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Cochez chaque question posée pendant votre appel. Le pourquoi est là pour vous aider à insister si la réponse reste vague."}),e.jsx("div",{className:"space-y-4",children:a.sections.map((u,m)=>e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:u.titre}),e.jsx("ul",{className:"space-y-2",children:u.questions.map((x,p)=>{const b=qe(m,p),N=!!a.coches[b];return e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[e.jsx(ee,{checked:N,onCheckedChange:()=>o(m,p),className:"mt-0.5","aria-label":x.question}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block text-sm ${N?"line-through text-muted-foreground":""}`,children:x.question}),x.pourquoi&&e.jsx("span",{className:"block text-[11px] text-muted-foreground mt-0.5",children:x.pourquoi})]})]})},b)})})]},m))}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4 flex-wrap",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Générée le"," ",new Date(a.generatedAt||t?.updatedAt||Date.now()).toLocaleStr
3ing("fr-FR")]}),t&&e.jsx(F,{bloc:"contact_checklist",sourceTable:"projet_etape_ia",sourceId:t.id})]})]})}const D="w-full bg-input border border-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-primary",M="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground/80",Le="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground mb-2",hn=[{v:"libre",label:"Libre"},{v:"loue",label:"Vendu loué"},{v:"occupe",label:"Occupé par le vendeur"}],gn=[{v:"agence",label:"Une agence"},{v:"vendeur",label:"Le vendeur en direct"}],bn={charges_copro_mois:"",taxe_fonciere_an:"",loyer_envisage:"",loyer_actuel:"",occupation:"",dpe_reel:"",chauffage:"",travaux_votes:"",interlocuteur:"",raison_vente:"",tel_contact:"",notes_appel:""};function jn(s){const t=r=>r==null?"":String(r);return{charges_copro_mois:t(s.charges_copro_mois),taxe_fonciere_an:t(s.taxe_fonciere_an),loyer_envisage:t(s.loyer_envisage),loyer_actuel:t(s.loyer_actuel),occupation:s.occupation??"",dpe_reel:s.dpe_reel??"",chauffage:s.chauffage??"",travaux_votes:s.travaux_votes??"",interlocuteur:s.interlocuteur??"",raison_vente:s.raison_vente??"",tel_contact:s.tel_contact??"",notes_appel:s.notes_appel??""}}function vn(s){const t={},r=i=>{const a=Number.parseFloat(i.replace(",",".").replace(/\s/g,""));return Number.isFinite(a)&&a>=0?a:void 0},n=i=>i.trim()?i.trim():void 0;return r(s.charges_copro_mois)!==void 0&&(t.charges_copro_mois=r(s.charges_copro_mois)),r(s.taxe_fonciere_an)!==void 0&&(t.taxe_fonciere_an=r(s.taxe_fonciere_an)),r(s.loyer_envisage)!==void 0&&(t.loyer_envisage=r(s.loyer_envisage)),r(s.loyer_actuel)!==void 0&&(t.loyer_actuel=r(s.loyer_actuel)),s.occupation&&(t.occupation=s.occupation),n(s.dpe_reel)&&(t.dpe_reel=n(s.dpe_reel)),n(s.chauffage)&&(t.chauffage=n(s.chauffage)),n(s.travaux_votes)&&(t.travaux_votes=n(s.travaux_votes)),s.interlocuteur&&(t.interlocuteur=s.interlocuteur),n(s.raison_vente)&&(t.raison_vente=n(s.raison_vente)),n(s.tel_contact)&&(t.tel_contact=n(s.tel_contact)),n(s.notes_appel)&&(t.notes_appel=n(s.notes_appel)),t}function yn({projectId:s}){const{data:t,isLoading:r}=q(s,"contact_infos"),n=Ur(),[i,a]=y.useState(bn),c=y.useRef(!1);y.useEffect(()=>{r||c.current||(c.current=!0,t?.data&&a(jn(t.data)))},[r,t]);const l=(o,u)=>a(m=>({...m,[o]:u})),d=async()=>{try{await n.mutateAsync({projectId:s,infos:vn(i)}),f.success("C'est noté. Votre plan de visite et votre offre s'en serviront.")}catch(o){f.error("Erreur : "+o.message)}};return e.jsxs("section",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ss,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Pendant votre appel"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-4",children:"Notez ce que vous apprenez, pendant ou juste après le téléphone, sans prise de tête : tout est optionnel. Chaque info remplie nourrit votre plan de visite, votre offre et toute la suite du projet."}),r?e.jsx(E,{className:"h-48 w-full"}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:Le,children:"Les chiffres"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Charges copro (€/mois)"}),e.jsx("input",{className:`${D} mt-1`,inputMode:"decimal",value:i.charges_copro_mois,onChange:o=>l("charges_copro_mois",o.target.value),placeholder:"ex : 90"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Taxe foncière (€/an)"}),e.jsx("input",{className:`${D} mt-1`,inputMode:"decimal",value:i.taxe_fonciere_an,onChange:o=>l("taxe_fonciere_an",o.target.value),placeholder:"ex : 800"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Loyer envisagé (€/mois)"}),e.jsx("input",{className:`${D} mt-1`,inputMode:"decimal",value:i.loyer_envisage,onChange:o=>l("loyer_envisage",o.target.value),placeholder:"ex : 550"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Loyer actuel (€/mois)"}),e.jsx("input",{className:`${D} mt-1`,inputMode:"decimal",value:i.loyer_actuel,onChange:o=>l("loyer_actuel",o.target.value),placeholder:"si vendu loué"})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:Le,children:"L'état du bien"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:M,children:"Occupation"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:hn.map(o=>e.jsx("button",{type:"button",onClick:()=>l("occupation",i.occupation===o.v?"":o.v),className:`text-xs rounded-md px-2.5 py-1 border transition-colors ${i.occupation===o.v?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:o.label},o.v))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"DPE réel confirmé"}),e.jsx("input",{className:`${D} mt-1`,maxLength:20,value:i.dpe_reel,onChange:o=>l("dpe_reel",o.target.value),placeholder:"ex : D"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Chauffage"}),e.jsx("input",{className:`${D} mt-1`,maxLength:200,value:i.chauffage,onChange:o=>l("chauffage",o.target.value),placeholder:"ex : individuel gaz"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Travaux votés en copro"}),e.jsx("input",{className:`${D} mt-1`,maxLength:500,value:i.travaux_votes,onChange:o=>l("travaux_votes",o.target.value),placeholder:"ex : ravalement voté pour 2027, 4 500 € par lot"})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:Le,children:"Le contexte"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:M,children:"Vous avez parlé à"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:gn.map(o=>e.jsx("button",{type:"button",onClick:()=>l("interlocuteur",i.interlocuteur===o.v?"":o.v),className:`text-xs rounded-md px-2.5 py-1 border transition-colors ${i.interlocuteur===o.v?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:o.label},o.v))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Raison de la vente"}),e.jsx("input",{className:`${D} mt-1`,maxLength:500,value:i.raison_vente,onChange:o=>l("raison_vente",o.target.value),placeholder:"ex : mutation, succession, divorce"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Téléphone du contact"}),e.jsx("input",{className:`${D} mt-1`,inputMode:"tel",maxLength:50,value:i.tel_contact,onChange:o=>l("tel_contact",o.target.value),placeholder:"ex : 06 12 34 56 78"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:M,children:"Notes libres"}),e.jsx("textarea",{className:`${D} mt-1 resize-y`,rows:3,maxLength:2e3,value:i.notes_appel,onChange:o=>l("notes_appel",o.target.value),placeholder:"Tout ce qui vous a marqué pendant l'appel : ton de l'interlocuteur, ouverture à la négociation, prochain créneau de visite…"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ces réponses entrent dans le dossier du projet : le plan de visite et l'offre s'appuieront dessus."}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{d()},className:"inline-flex items-center gap-1.5 bg-primary text-primary-foreground rounded-lg px-3 py-1.5 text-sm font-semibold hover:brightness-110 disabled:opacity-60",children:[e.jsx(Us,{className:"size-3.5"}),n.isPending?"Enregistrement…":"Enregistrer"]})]}),t?.updatedAt&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Dernière sauvegarde le ",new Date(t.updatedAt).toLocaleStr
3ing("fr-FR")]})]})]})}const Nn=["Je reprends l'analyse approfondie du bien…","Je la confronte à ce que vous avez appris pendant l'appel…","Je repère ce qui se confirme et ce qui change…","Encore un instant, je rédige votre sur-analyse…"],_n="Ça prend en général 30 secondes à 1 minute.",ce=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.length>0):[];function kn(s){const t=typeof s.synthese=="string"?s.synthese:"",r=ce(s.ce_qui_a_change);return!t&&r.length===0?null:{synthese:t,ceQuiAChange:r,pointsVigilance:ce(s.points_vigilance),opportunites:ce(s.opportunites),impact:ce(s.impact),prochainesActions:ce(s.prochaines_actions),generatedAt:typeof s.generated_at=="string"?s.generated_at:null}}function de({titre:s,items:t,icon:r}){return t.length===0?null:e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[r," ",s]}),e.jsx("ul",{className:"space-y-1.5",children:t.map((n,i)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{}),e.jsx("span",{children:e.jsx(_,{texte:n})})]},s+i))})]})}function An({projectId:s}){const{data:t,isLoading:r}=q(s,"analyse_post_contact"),n=q(s,"contact_infos"),i=X(),a=y.useMemo(()=>t?kn(t.data):null,[t]),c=!!n.data&&Object.values(n.data.data).some(o=>o!=null&&o!==""),l=async()=>{try{await i.mutateAsync({projectId:s,kind:"analyse_post_contact"}),f.success("Votre sur-analyse post-appel est prête")}catch(o){const u=o.message;u.includes("analyse_requise")?f.error("Lancez d'abord l'analyse approfondie du bien : c'est elle que la sur-analyse réévalue."):f.error("Erreur : "+u)}};if(r)return e.jsx(E,{className:"h-32 w-full"});if(!a)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 text-center",children:i.isPending?e.jsx(S,{messages:Nn,estimation:_n}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," Sur-analyse post-appel"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Réévaluez le bien avec ce que vous avez appris pendant l'appel : ce qui se confirme ou tombe par rapport à l'analyse de départ, les nouveaux points de vigilance, les opportunités, l'impact sur votre projet et les prochaines actions."}),!c&&e.jsxs("div",{className:"flex items-start gap-2 text-left bg-input border border-border rounded-lg p-3 mb-4 max-w-md mx-auto",children:[e.jsx(ss,{"aria-hidden":!0,className:"size-4 text-primary shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Remplissez d'abord le questionnaire d'appel ci-dessus : votre sur-analyse sera bien plus fine. Vous pouvez quand même la lancer maintenant."})]}),e.jsxs("button",{type:"button",onClick:()=>{l()},className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer ma sur-analyse"]})]})});const d=a.generatedAt??t?.updatedAt??null;return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," Sur-analyse post-appel"]}),e.jsxs("button",{type:"button",disabled:i.isPending,onClick:()=>{confirm("Régénérer la sur-analyse ? La version actuelle sera remplacée.")&&l()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${i.isPending?"animate-spin":""}`}),i.isPending?"Génération…":"Régénérer"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Le verdict réévalué maintenant que vous en savez plus qu'au moment de l'analyse de départ."}),a.synthese&&e.jsx("p",{className:"text-sm leading-relaxed mb-4",children:e.jsx(_,{texte:a.synthese})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(de,{titre:"Ce qui a changé depuis l'analyse",items:a.ceQuiAChange,icon:e.jsx(ur,{"aria-hidden":!0,
3className:"size-3.5 text-primary"})}),e.jsx(de,{titre:"Nouveaux points de vigilance",items:a.pointsVigilance,icon:e.jsx(V,{"aria-hidden":!0,className:"size-3.5 text-amber"})}),e.jsx(de,{titre:"Opportunités et leviers",items:a.opportunites,icon:e.jsx(Qs,{"aria-hidden":!0,className:"size-3.5 text-pos"})}),e.jsx(de,{titre:"Impact sur votre projet",items:a.impact,icon:e.jsx(Ye,{"aria-hidden":!0,className:"size-3.5 text-primary"})}),e.jsx(de,{titre:"Prochaines actions",items:a.prochainesActions,icon:e.jsx(se,{"aria-hidden":!0,className:"size-3.5 text-primary"})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4 flex-wrap",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:d&&`Générée le ${new Date(d).toLocaleString("fr-FR")}`}),t&&e.jsx(F,{bloc:"analyse_post_contact",sourceTable:"projet_etape_ia",sourceId:t.id})]})]})}function wn({project:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Cn,{}),e.jsx($n,{projectId:s.id})]})}function Cn(){const{capacite:s}=Vt();return s?e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ae,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Votre capacité d'emprunt"})]}),e.jsx(Ut,{result:s}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"Estimation indicative (règle HCSF 35 %). C'est exactement ce qu'un courtier va chiffrer, en plus précis, pour votre attestation de faisabilité."})]}):e.jsxs("section",{className:"border border-dashed border-border rounded-xl p-6 text-center",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(Ae,{"aria-hidden":!0,className:"size-4 text-primary"})," Votre capacité d'emprunt"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Renseignez vos revenus, votre apport et vos crédits en cours pour estimer ce que la banque peut vous prêter. Ce chiffre situe le bien dans votre budget et sert de base à votre brief courtier."}),e.jsxs(H,{to:"/app/profil",className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(Ae,{className:"size-4"}),"Compléter mon profil financier"]})]})}const Sn=["Je relis votre profil et l'analyse du bien…","Je rédige votre message pour le courtier…","Je liste les pièces à réunir…","Encore un instant, je prépare vos leviers de négo…"],zn="Ça prend en général 20 à 40 secondes.";function Me(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function En(s){if(!s)return null;const t=typeof s.brief_courtier=="string"?s.brief_courtier.trim():"",r=Me(s.pieces_dossier),n=Me(s.conseils_negociation),i=Me(s.vigilance);return!t||r.length===0?null:{brief_courtier:t,pieces_dossier:r,conseils_negociation:n,vigilance:i}}function $n({projectId:s}){const{data:t,isLoading:r}=q(s,"courtier_accord"),n=X(),i=y.useMemo(()=>En(t?.data),[t]),a=async()=>{try{await n.mutateAsync({projectId:s,kind:"courtier_accord",saisie:{}}),f.success("Votre dossier courtier est prêt")}catch(l){const d=l.message;d==="analyse_requise"?f.error("Lancez d'abord l'analyse du bien : c'est elle qui alimente votre brief."):f.error("Erreur : "+d)}},c=async()=>{if(i)try{await navigator.clipboard.writeText(i.brief_courtier),f.success("Brief copié, prêt à coller dans votre mail")}catch{f.error("Copie impossible sur cet appareil")}};return r?e.jsx(E,{className:"h-40 w-full"}):i?e.jsxs("section",{className:"bg-card border border-border rounded-xl p-4 md:p-5 space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(Ce,{"aria-hidden":!0,className:"size-4 text-primary shrink-0"}),"Votre dossier courtier"]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{confirm("Régénérer le dossier ? La version actuelle sera remplacée.")&&a()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Génération…":"Régénérer"]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[e.jsx("h4",{className:"text-[13px] font-semibold",children:"Message à envoyer"}),e.jsxs("button",{type:"button",onClick:()=>{c()},className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(pr,{className:"size-3.5"})," Copier"]})]}),e.jsx("p",{className:"text-sm bg-input border border-border rounded-lg p-3 whitespace-pre-wrap",children:i.brief_courtier})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-[13px] font-semibold inline-flex items-center gap-1.5 mb-2",children:[e.jsx(se,{"aria-hidden":!0,
3className:"size-3.5 text-primary"})," Les pièces à réunir"]}),e.jsx("ul",{className:"space-y-1.5",children:i.pieces_dossier.map((l,d)=>e.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[e.jsx(K,{}),e.jsx("span",{children:l})]},d))})]}),i.conseils_negociation.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-[13px] font-semibold inline-flex items-center gap-1.5 mb-2",children:[e.jsx(Ce,{"aria-hidden":!0,className:"size-3.5 text-primary"})," Dans la négociation"]}),e.jsx("ul",{className:"space-y-1.5",children:i.conseils_negociation.map((l,d)=>e.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[e.jsx(K,{}),e.jsx("span",{children:l})]},d))})]}),i.vigilance.length>0&&e.jsxs("div",{className:"bg-amber/5 border border-amber/20 rounded-lg p-3",children:[e.jsxs("h4",{className:"text-[13px] font-semibold inline-flex items-center gap-1.5 mb-2 text-amber",children:[e.jsx(Qt,{"aria-hidden":!0,className:"size-3.5"})," À garder en tête"]}),e.jsx("ul",{className:"space-y-1.5",children:i.vigilance.map((l,d)=>e.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[e.jsx(K,{className:"bg-amber/70"}),e.jsx("span",{children:l})]},d))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t?.updatedAt&&`Généré le ${new Date(t.updatedAt).toLocaleString("fr-FR")}`}),t&&e.jsx(F,{bloc:"courtier_accord",sourceTable:"projet_etape_ia",sourceId:t.id})]})]}):e.jsx("section",{className:"border border-dashed border-border rounded-xl p-5 md:p-6",children:n.isPending?e.jsx(S,{messages:Sn,estimation:zn}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(Ce,{"aria-hidden":!0,className:"size-4 text-primary"})," Votre dossier courtier"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md",children:"Un message prêt à envoyer à un courtier (ou à votre banque) pour obtenir une attestation de faisabilité, la liste des pièces à réunir, et comment vous en servir dans la négociation."}),e.jsxs("button",{type:"button",onClick:()=>{a()},className:"mt-4 inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer mon dossier courtier"]})]})})}function Te(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function Pn(s){if(!Array.isArray(s))return[];const t=[];for(const r of s){if(!r||typeof r!="object"||Array.isArray(r))continue;const n=r,i=typeof n.echeance=="string"?n.echeance.trim():"",a=typeof n.quand=="string"?n.quand.trim():"",c=typeof n.action=="string"?n.action.trim():"";i&&a&&c&&t.push({echeance:i,quand:a,action:c})}return t}function qn(s){if(!s||typeof s!="object"||Array.isArray(s))return{};const t={};for(const[r,n]of Object.entries(s))typeof n=="boolean"&&(t[r]=n);return t}function Ln(s){if(!s)return null;const t=Pn(s.retro_planning),r=Te(s.pieces_dossier);return t.length===0&&r.length===0?null:{retroPlanning:t,piecesDossier:r,conseilsNegociation:Te(s.conseils_negociation),vigilance:Te(s.vigilance),coches:qn(s.coches),generatedAt:typeof s.generated_at=="string"?s.generated_at:null}}const he="financement_plan",ys=["Je relis votre dossier et l'offre acceptée…","Je cale les jalons sur la condition suspensive…","Je liste les pièces adaptées à votre situation…","Encore un instant, je rédige le plan…"],Ns="Ça prend en général 30 secondes à 1 minute.",_s="w-full bg-input border border-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-primary",Re="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground/80",Mn=[{value:"oui",label:"Oui"},{value:"non",label:"Non"},{value:"sais_pas",label:"Je ne sais pas"}],Tn="45";function Rn({project:s}){const{data:t,isLoading:r}=q(s.id,he),n=X(),i=J(),[a,c]=y.useState(""),[l,d]=y.useState(Tn),[o,u]=y.useState(null),[m,x]=y.useState(!1),p=Ln(t?.data),b=U({mutationFn:async({piece:g,done:z})=>{if(!t)return;const ie={...p?.coches??{},[g]:z},ke={...t.data,coches:ie},{error:te}=await I.from("projet_etape_ia").update({data:ke}).eq("project_id",s.id).eq("kind",he);if(te)throw te},onSuccess:()=>i.invalidateQueries({queryKey:["projet-etape-ia",s.id,he]}),onError:g=>f.error("Erreur : "+g.message)}),N=async()=>{try{await n.mutateAsync({projectId:s.id,kind:he,saisie:{date_compromis:a||void 0,delai_condition_jours:Number(l)||void 0,courtier:o??void 0}}),x(!1),f.success("Plan de financement généré")}catch(g){f.error("Erreur : "+g.message)}},j=e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Re,children:"Compromis signé le (optionnel)"}),e.jsx("input",{type:"date",value:a,onChange:g=>c(g.target.value),className:`${_s} mt-1`})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Re,children:"Condition suspensive de prêt (jours)"}
3),e.jsx("input",{type:"number",min:30,max:90,value:l,onChange:g=>d(g.target.value),className:`${_s} mt-1`})]})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("span",{className:Re,children:"Passez-vous par un courtier ?"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:Mn.map(g=>e.jsx("button",{type:"button",onClick:()=>u(o===g.value?null:g.value),"aria-pressed":o===g.value,className:`rounded-full border px-3 py-1.5 text-xs transition-colors ${o===g.value?"border-primary/60 bg-primary/10 text-primary font-semibold":"border-border text-muted-foreground hover:border-primary/40 hover:text-foreground"}`,children:g.label},g.value))})]}),e.jsxs("button",{type:"button",onClick:N,disabled:n.isPending,className:"mt-4 inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110 disabled:opacity-50",children:[e.jsx(A,{className:"size-4"}),"Générez mon plan de financement"]})]});if(r)return e.jsx(E,{className:"h-40 w-full"});if(!p)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-4 md:p-6",children:n.isPending?e.jsx(S,{messages:ys,estimation:Ns}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-1",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," Votre plan de financement"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Rétroplanning calé sur les délais du compromis, pièces du dossier bancaire adaptées à votre situation, conseils de négociation et points de vigilance. La mensualité, elle, se calcule dans l'outil Simulation juste en dessous."}),j]})});const w=p.piecesDossier.length,h=p.piecesDossier.filter(g=>p.coches[g]).length;return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," Votre plan de financement"]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>x(g=>!g),className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Génération…":"Régénérer"]})]}),m&&!n.isPending&&e.jsxs("div",{className:"bg-input border border-border rounded-lg p-3.5 mb-4",children:[j,e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"Régénérer remplace le plan actuel et remet la checklist des pièces à zéro."})]}),n.isPending&&e.jsx("div",{className:"mb-4 rounded-xl border border-primary/30 bg-primary/5",children:e.jsx(S,{messages:ys,estimation:Ns})}),p.retroPlanning.length>0&&e.jsxs("section",{className:"mb-5",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-3 inline-flex items-center gap-2",children:[e.jsx(Is,{"aria-hidden":!0,className:"size-4 text-primary"})," Rétroplanning"]}),e.jsx("ol",{className:"relative border-l border-border ml-1.5 pl-4 space-y-4",children:p.retroPlanning.map((g,z)=>e.jsxs("li",{className:"relative",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute -left-[21px] top-1.5 size-2.5 rounded-full bg-primary/80 border-2 border-card"}),e.jsx("div",{className:"text-[11px] font-mono font-semibold text-primary",children:g.quand}),e.jsx("div",{className:"text-sm font-semibold",children:e.jsx(_,{texte:g.echeance})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:e.jsx(_,{texte:g.action})})]},g.echeance+z))})]}),w>0&&e.jsxs("section",{className:"mb-5",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-2 flex-wrap",children:[e.jsx(yr,{"aria-hidden":!0,className:"size-4 text-primary"})," Pièces du dossier bancaire",e.jsxs("span",{className:"text-[11px] font-normal text-muted-foreground",children:[h,"/",w," prêtes"]})]}),e.jsx("ul",{className:"space-y-1.5",children:p.piecesDossier.map(g=>e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-2.5 text-sm cursor-pointer group",children:[e.jsx(ee,{checked:!!p.coches[g],onCheckedChange:z=>b.mutate({piece:g,done:z===!0}),className:"mt-0.5"}),e.jsx("span",{className:p.coches[g]?"line-through text-muted-foreground":"group-hover:text-foreground",children:e.jsx(_,{texte:g})})]})},g))})]}),p.conseilsNegociation.length>0&&e.jsxs("section",{className:"mb-5",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-2",children:[e.jsx(Ke,{"aria-hidden":!0,
3className:"size-4 text-pos"})," Conseils de négociation"]}),e.jsx("ul",{className:"space-y-1.5",children:p.conseilsNegociation.map((g,z)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(Ke,{"aria-hidden":!0,className:"size-3.5 text-pos shrink-0 mt-0.5"}),e.jsx("span",{children:e.jsx(_,{texte:g})})]},g+z))})]}),p.vigilance.length>0&&e.jsxs("section",{className:"rounded-xl border border-amber/60 bg-amber/5 p-4 mb-4",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-2",children:[e.jsx(V,{"aria-hidden":!0,className:"size-4 text-amber"})," Points de vigilance"]}),e.jsx("ul",{className:"space-y-1.5",children:p.vigilance.map((g,z)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(V,{"aria-hidden":!0,className:"size-3.5 text-amber shrink-0 mt-0.5"}),e.jsx("span",{children:e.jsx(_,{texte:g})})]},g+z))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[p.generatedAt||t?.updatedAt?`Généré le ${new Date(p.generatedAt||t.updatedAt).toLocaleString("fr-FR")} · `:"","La mensualité et le coût du crédit se calculent dans l'outil Simulation, juste en dessous."]}),t&&e.jsx(F,{bloc:"financement_plan",sourceTable:"projet_etape_ia",sourceId:t.id})]})]})}const Fn={ancienneteInconnue:9999};function Gn(s,t=Date.now()){if(!s)return null;const r=Number(s.age);if(Number.isFinite(r)&&r>0&&r<Fn.ancienneteInconnue)return Math.floor(r);if(s.firstSeen){const n=new Date(s.firstSeen).getTime();if(Number.isFinite(n)&&n<=t)return Math.floor((t-n)/864e5)}return null}function On(s){const t=s.ville?` à ${s.ville}${s.cp?` (${s.cp})`:""}`:"";return s.titre?`votre bien « ${s.titre} »${t}`:`votre bien${t}`}function Dn(s){const t=[];return s.emprunt!=null&&s.emprunt>0&&t.push(`montant d'environ ${v(s.emprunt)}`),s.dureeAns!=null&&s.dureeAns>0&&t.push(`durée de ${s.dureeAns} ans`),s.tauxMaxPct!=null&&s.tauxMaxPct>0&&t.push(`taux nominal maximum de ${s.tauxMaxPct.toLocaleString("fr-FR")} %`),`Cette offre est faite sous condition suspensive d'obtention d'un prêt immobilier${t.length>0?` (${t.join(", ")})`:""}, conformément aux dispositions légales en vigueur.`}function In(s,t){const r=t.validiteJours??3,n=r===3?"72 heures":`${r} jours`,i=t.conditionPret!==!1,a=s.ville?` à ${s.ville}${s.cp?` (${s.cp})`:""}`:"",c=`Offre d'achat : ${s.titre??"votre bien"}${a}${s.ref?`, réf. ${s.ref}`:""}`,l=s.prix!=null?`, présenté au prix de ${v(s.prix)}`:"",d=["Bonjour,","",`Après étude de ${On(s)}${l}, je vous adresse par la présente une offre d'achat ferme.`,"",`Je vous propose d'acquérir ce bien au prix de ${v(t.montant)}, net vendeur.`,"",`Cette offre est valable ${n} à compter de son envoi. Passé ce délai, elle deviendra caduque.`,"",i?Dn(t):"Cette offre n'est pas conditionnée à l'obtention d'un prêt : l'acquisition sera financée comptant.","","Mon dossier est préparé et je suis en mesure de signer un compromis de vente rapidement, chez le notaire de votre choix.","","Dans l'attente de votre réponse, je reste à votre disposition pour en échanger.","","Bien cordialement"];return{objet:c,corps:d.join(`
4`)}}const ks=["Je relis tout votre dossier…","Je pèse le prix affiché face à vos chiffres…","Je calibre l'offre et le plancher…","Encore un instant, je rédige l'argumentaire…"],As="Ça prend en général 30 secondes à 1 minute.",ws={fraiche:"Récente",ancienne:"En ligne depuis longtemps",inconnue:"Je ne sais pas"},ve="w-full bg-input border border-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-primary",Y="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground/80";function ue(s){if(!s.trim())return null;const t=Number(s.replace(",","."));return Number.isFinite(t)?t:null}function Vn(s){const t=a=>Number.isFinite(Number(a))&&Number(a)>0?Number(a):null,r=t(s.offre_conseillee_eur),n=t(s.offre_plancher_eur);if(r==null||n==null)return null;const i=a=>Array.isArray(a)?a.filter(c=>typeof c=="string"&&c.length>0):[];return{offreConseillee:r,offrePlancher:n,lectureDuMarche:typeof s.lecture_du_marche=="string"?s.lecture_du_marche:"",argumentaire:i(s.argumentaire),conditionsSuspensives:i(s.conditions_suspensives),delaiValidite:typeof s.delai_validite=="string"?s.delai_validite:"",etSiRefus:i(s.et_si_refus),lettreOffre:typeof s.lettre_offre=="string"?s.lettre_offre:"",generatedAt:typeof s.generated_at=="string"?s.generated_at:null}}function Jn({project:s}){const{data:t,isLoading:r}=q(s.id,"offre_proposition"),n=X(),{data:i}=Bt(),a=s.annonce_snapshot??{},c=Gn(a),l=Number(a.prix)>0?Math.round(Number(a.prix)):null,d=Number.isFinite(Number(a.ecart))&&Number(a.ecart)!==0?Math.round(Number(a.ecart)):null,o=c==null?"inconnue":c>=60?"ancienne":c<=21?"fraiche":"inconnue",u=y.useMemo(()=>{for(const k of i??[]){if(k.statut!=="actif")continue;const Q=Kt(k.plan)?.criteres.budget_max??0;if(Q>0)return Q}return null},[i]),[m,x]=y.useState(""),[p,b]=y.useState(""),[N,j]=y.useState(o),[w,h]=y.useState(""),[g,z]=y.useState(""),[ie,ke]=y.useState(""),[te,it]=y.useState("");y.useEffect(()=>{u!=null&&b(k=>
4k===""?String(u):k)},[u]);const C=y.useMemo(()=>t?Vn(t.data):null,[t]);function ot(){const k={concurrence:N},Q=ue(m);Q!=null&&Q>0&&(k.travaux_estimes_eur=Q);const re=ue(p);re!=null&&re>0&&(k.budget_max_eur=re);const ns=w.trim();if(ns&&(k.remarques=ns.slice(0,300)),g.trim()!==""){const O=ue(g);O!=null&&O>0&&(k.prix_affiche_eur=O)}if(ie.trim()!==""){const O=ue(ie);O!=null&&O>=0&&(k.anciennete_jours=O)}if(te.trim()!==""){const O=ue(te);O!=null&&(k.ecart_marche_pct=O)}return k}const lt=async()=>{try{await n.mutateAsync({projectId:s.id,kind:"offre_proposition",saisie:ot()}),f.success("Proposition d'offre générée")}catch(k){f.error(et(k))}},xe=y.useMemo(()=>{if(!C)return null;if(C.lettreOffre.trim())return C.lettreOffre.trim();const k=Zs(s.annonce_snapshot),Q=es(s.finances),re=In(k,{montant:C.offreConseillee,dureeAns:Q.duree_ans,tauxMaxPct:Q.taux_pret_pct});return`Objet : ${re.objet}
5
6${re.corps}`},[C,s.annonce_snapshot,s.finances]),ct=async()=>{if(xe)try{await navigator.clipboard.writeText(xe),f.success("Lettre d'offre copiée, prête à envoyer")}catch{f.error("Copie impossible sur cet appareil")}};if(r)return e.jsx(E,{className:"h-40 w-full"});const rs=e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:Y,children:"Le bien, d'après l'annonce (corrige au crayon si erreur)"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 mt-1.5",children:[e.jsx(Ge,{label:"Prix affiché",valeurConnue:l,suffixe:" €",override:g,setOverride:z,placeholder:"ex. 250000"}),e.jsx(Ge,{label:"En ligne depuis",valeurConnue:c,suffixe:" j",override:ie,setOverride:ke,placeholder:"jours"}),e.jsx(Ge,{label:"Écart au marché",valeurConnue:d,suffixe:" %",override:te,setOverride:it,placeholder:"ex. 5 ou -3"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:Y,htmlFor:`offre-ia-travaux-${s.id}`,children:"Travaux estimés (€)"}),e.jsx("input",{id:`offre-ia-travaux-${s.id}`,className:ve,inputMode:"decimal",value:m,onChange:k=>x(k.target.value),placeholder:"optionnel, ex. 12000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:Y,htmlFor:`offre-ia-budget-${s.id}`,children:"Votre budget max (€)"}),e.jsx("input",{id:`offre-ia-budget-${s.id}`,className:ve,inputMode:"decimal",value:p,onChange:k=>b(k.target.value),placeholder:"optionnel"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:Y,children:"L'annonce est récente ou ancienne ?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:Object.keys(ws).map(k=>e.jsx("button",{type:"button",onClick:()=>j(k),className:`text-xs rounded-md px-2.5 py-1 border transition-colors ${N===k?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:ws[k]},k))})]}),e.jsxs("div",{children:[e.jsx("label",{className:Y,htmlFor:`offre-ia-remarques-${s.id}`,children:"Un truc à signaler ?"}),e.jsx("input",{id:`offre-ia-remarques-${s.id}`,className:ve,value:w,maxLength:300,onChange:k=>h(k.target.value),placeholder:"optionnel, ex. vendeur pressé, vis-à-vis, balcon"})]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{lt()},className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110 disabled:opacity-50",children:[C?e.jsx(L,{className:"size-4"}):e.jsx(A,{className:"size-4"}),C?"Régénérer avec ces infos":"Générer mon offre"]})]});return C?e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-sm font-semibold",children:[e.jsx(A,{className:"size-4 text-primary"})," Votre offre, préparée pour vous"]}),C.delaiValidite&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] text-muted-foreground border border-border rounded-full px-2.5 py-0.5",children:[e.jsx(fr,{className:"size-3"})," Offre valable ",C.delaiValidite]})]}),n.isPending?e.jsx(S,{messages:ks,estimation:As}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Offre conseillée"}),e.jsx("div",{className:"text-3xl font-bold font-mono tabular-nums mt-0.5",children:v(C.offreConseillee)}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Plancher :"," ",e.jsx("span",{className:"font-mono tabular-nums font-semibold text-foreground",children:v(C.offrePlancher)}),", en dessous le vendeur risque de ne même pas répondre."]})]}),C.lectureDuMarche&&e.jsx("p",{className:"text-sm leading-relaxed",children:C.lectureDuMarche}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(Fe,{titre:"Vos arguments face au vendeur",items:C.argumentaire,icon:e.jsx(Xs,{className:"size-3.5 text-primary"})}),e.jsx(Fe,{titre:"Conditions suspensives à poser",items:C.conditionsSuspensives,icon:e.jsx(Ds,{className:"size-3.5 text-pos"})})]}),e.jsx(Fe,{titre:"Et si le vendeur refuse",items:C.etSiRefus,icon:e.jsx(gr,{className:"size-3.5 text-amber"})}),e.jsxs("div",{className:"flex items-start gap-2 border border-primary/40 bg-primary/5 rounded-lg p-3 text-sm",children:[e.jsx(kr,{className:"size-4 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold",children:"Votre financement se prépare maintenant."})," ","N'attendez pas le compromis : contactez votre banque ou un courtier dès l'offre envoyée, un accord de principe rassure le vendeur et vous fait gagner des semaines."]})]}),xe&&e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[e.jsxs("h3",{className:"text-sm font-semibold inline-flex items-center gap-1.5",children:[e.jsx(Qe,{className:"size-4 text-primary"})," Votre lettre d'offre, prête à envoyer"]}),e.jsxs("button",{type:"button",onClick:()=>{ct()},className:"text-xs text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(Vs,{className:"size-3.5"})," Copier"]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-2",children:"Rédigée à partir de tout votre dossier. Copiez-la et envoyez-la par email au vendeur ou à l'agence. Ajoutez votre nom et vos coordonnées avant l'envoi."}),e.jsx("div",{className:"bg-input border border-border rounded-lg p-3 text-sm leading-relaxed whitespace-pre-line",children:xe})]}),e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground
6/70 mb-2",children:"Ajuste et régénère"}),rs]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Générée le"," ",new Date(C.generatedAt??t?.updatedAt??Date.now()).toLocaleString("fr-FR")]}),t&&e.jsx(F,{bloc:"offre_proposition",sourceTable:"projet_etape_ia",sourceId:t.id})]})]})]}):e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-1",children:[e.jsx(A,{className:"size-4 text-primary"})," Votre offre, préparée pour vous"]}),n.isPending?e.jsx(S,{messages:ks,estimation:As}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3",children:"Les infos de l'annonce sont déjà là (corrigez au crayon si besoin). Ajoutez ce que vous êtes seul à savoir, et on croise tout votre dossier (annonce, analyse, appel au vendeur, profil, objectif) pour vous proposer une offre argumentée et générer votre lettre prête à envoyer."}),rs]})]})}function Fe({titre:s,items:t,icon:r}){return t.length===0?null:e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"shrink-0",children:r}),s]}),e.jsx("ul",{className:"space-y-1.5",children:t.map((n,i)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{}),e.jsx("span",{children:n})]},s+i))})]})}function Ge({label:s,valeurConnue:t,suffixe:r,override:n,setOverride:i,placeholder:a}){const[c,l]=y.useState(!1),d=n.trim()!=="";if(c||t==null)return e.jsxs("div",{children:[e.jsx("span",{className:Y,children:s}),e.jsx("input",{className:`${ve} mt-1`,inputMode:"decimal",value:n,onChange:m=>i(m.target.value),onBlur:()=>l(!1),placeholder:t!=null?String(t):a,autoFocus:c})]});const u=d?n:String(t);return e.jsxs("div",{children:[e.jsx("span",{className:Y,children:s}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 h-9",children:[e.jsxs("span",{className:"text-sm font-medium tabular-nums",children:[u,r]}),e.jsx("button",{type:"button",onClick:()=>l(!0),"aria-label":`Corriger ${s}`,className:"text-muted-foreground hover:text-primary",children:e.jsx(tr,{className:"size-3.5"})}),d&&e.jsx("span",{className:"text-[10px] text-primary",children:"corrigé"})]})]})}const Un=["Je relis votre dossier et l'annonce…","J'exploite les réponses de votre appel…","Je choisis les zones à inspecter…","Encore un instant, je rédige votre plan…"],Qn="Ça prend en général 30 secondes à 1 minute.",ge=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"&&t.length>0):[];function Bn(s){if(!Array.isArray(s))return[];const t=[];for(const r of s){if(!r||typeof r!="object")continue;const n=r,i=typeof n.zone=="string"?n.zone:"",a=[];if(Array.isArray(n.points))for(const c of n.points){if(!c||typeof c!="object")continue;const l=c;typeof l.point=="string"&&l.point&&a.push({point:l.point,pourquoi:typeof l.pourquoi=="string"?l.pourquoi:""})}i&&a.length&&t.push({zone:i,points:a})}return t}function Kn(s){const t=Bn(s.pendant_la_visite);return t.length===0?null:{titre:typeof s.titre=="string"&&s.titre?s.titre:"Plan de visite",avantLaVisite:ge(s.avant_la_visite),pendantLaVisite:t,questionsSurPlace:ge(s.questions_sur_place),signauxDAlerte:ge(s.signaux_d_alerte),apresLaVisite:ge(s.apres_la_visite),generatedAt:typeof s.generated_at=="string"?s.generated_at:null,coches:s.coches&&typeof s.coches=="object"&&!Array.isArray(s.coches)?s.coches:{}}}function Hn(s){const t=J(),r=["projet-etape-ia",s,"visite_plan"];return U({mutationFn:async({cle:n,valeur:i})=>{const a=t.getQueryData(r);if(!a)throw new Error("plan introuvable");const c={...a.data.coches??{},[n]:i},{error:l}=await I.from("projet_etape_ia").update({data:{...a.data,coches:c}}).eq("project_id",s).eq("kind","visite_plan");if(l)throw l},onMutate:async({cle:n,valeur:i})=>{await t.cancelQueries({queryKey:r});const a=t.getQueryData(r);return a&&t.setQueryData(r,{...a,data:{...a.data,coches:{...a.data.coches??{},[n]:i}}}),{prev:a}},onError:(n,i,a)=>{a?.prev!==void 0&&t.setQueryData(r,a.prev),f.error("Coche non enregistrée : "+n.message)},onSettled:()=>
6t.invalidateQueries({queryKey:r})})}function Xn({project:s}){const t=q(s.id,"visite_plan"),r=q(s.id,"contact_infos"),n=X(),i=Hn(s.id),a=t.data?Kn(t.data.data):null,c=!!r.data&&Object.values(r.data.data).some(m=>m!=null&&m!==""),l=async()=>{try{await n.mutateAsync({projectId:s.id,kind:"visite_plan"}),f.success("Plan de visite généré")}catch(m){const x=m.message;x.includes("analyse_requise")?f.error("Lancez d'abord l'analyse approfondie du bien : elle débloque et alimente le plan de visite."):f.error("Erreur : "+x)}};if(t.isLoading)return e.jsx(E,{className:"h-40 w-full"});if(!a)return e.jsx("div",{className:"border border-dashed border-border rounded-xl p-6 md:p-8 text-center",children:n.isPending?e.jsx(S,{messages:Un,estimation:Qn}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm font-semibold mb-2",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," Générez votre plan de visite"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-md mx-auto",children:"Un plan personnalisé pour ce bien : quoi préparer, quoi vérifier zone par zone (avec le pourquoi de chaque point), les questions à poser sur place et les signaux d'alerte à repérer."}),!c&&e.jsxs("div",{className:"flex items-start gap-2 text-left bg-input border border-border rounded-lg p-3 mb-4 max-w-md mx-auto",children:[e.jsx(ss,{"aria-hidden":!0,className:"size-4 text-primary shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Remplissez le questionnaire d'appel à l'étape Contact d'abord : votre plan sera bien plus précis."," ",e.jsx(H,{to:"/app/projets/$id",params:{id:s.id},search:{etape:"contact"},className:"text-primary underline underline-offset-2 hover:brightness-110",children:"Aller à l'étape Contact"})]})]}),e.jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-4 py-2.5 text-sm hover:brightness-110",children:[e.jsx(A,{className:"size-4"}),"Générer le plan de visite"]})]})});const d=a.pendantLaVisite.reduce((m,x)=>m+x.points.length,0),o=a.pendantLaVisite.reduce((m,x,p)=>m+x.points.filter((b,N)=>a.coches[`z${p}-p${N}`]).length,0),u=a.generatedAt??t.data?.updatedAt??null;return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 md:p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",children:[e.jsx(A,{"aria-hidden":!0,className:"size-4 text-primary"})," ",a.titre]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:()=>{confirm("Régénérer le plan ? La version actuelle et vos coches seront remplacées.")&&l()},className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 shrink-0",children:[e.jsx(L,{className:`size-3 ${n.isPending?"animate-spin":""}`}),n.isPending?"Génération…":"Régénérer"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Cochez les points au fil de la visite : tout est enregistré sur ce projet."}),a.avantLaVisite.length>0&&e.jsxs("section",{className:"mb-4",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[e.jsx(At,{"aria-hidden":!0,className:"size-3.5 text-primary"})," Avant la visite"]}),e.jsx("ul",{className:"space-y-1.5",children:a.avantLaVisite.map((m,x)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{}),e.jsx("span",{children:e.jsx(_,{texte:m})})]},"av"+x))})]}),e.jsxs("section",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 flex-wrap",children:[e.jsxs("h3",{className:"text-sm font-semibold inline-flex items-center gap-1.5",children:[e.jsx(rr,{"aria-hidden":!0,className:"size-3.5 text-primary"})," Pendant la visite"]}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[o,"/",d," points vérifiés"]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:a.pendantLaVisite.map((m,x)=>e.jsxs("div",{className:"bg-input border border-border rounded-lg p-3",children:[e.jsx("h4",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:m.zone}),e.jsx("ul",{className:"space-y-2.5",children:m.points.map((p,b)=>{const N=`z${x}-p${b}`,j=!!a.coches[N];return e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx(ee,{id:`visite-${N}`,checked:j,onCheckedChange:w=>i.mutate({cle:N,valeur:w===!0}),className:"mt-0.5"}),e.jsxs("label",{htmlFor:`visite-${N}`,className:"cursor-pointer",children:[e.jsx("span",{className:`text-sm block ${j?"text-muted-foreground line-through":""}`,children:e.jsx(_,{texte:p.point})}),p.pourquoi&&e.jsxs("span",{className:"text-xs text-muted-foreground block mt-0.5",children:["Pourquoi : ",e.jsx(_,{texte:p.pourquoi})]})]})]},N)})})]},"z"+x))})]}),a.questionsSurPlace.length>0&&e.jsxs("section",{className:"mb-4",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[e.jsx(nr,{"aria-hidden":!0,
6className:"size-3.5 text-primary"})," Questions sur place"]}),e.jsx("ul",{className:"space-y-2",children:a.questionsSurPlace.map((m,x)=>{const p=`q${x}`,b=!!a.coches[p];return e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx(ee,{id:`visite-${p}`,checked:b,onCheckedChange:N=>i.mutate({cle:p,valeur:N===!0}),className:"mt-0.5"}),e.jsx("label",{htmlFor:`visite-${p}`,className:`cursor-pointer text-sm ${b?"text-muted-foreground line-through":""}`,children:e.jsx(_,{texte:m})})]},p)})})]}),a.signauxDAlerte.length>0&&e.jsxs("section",{className:"border border-amber/60 bg-amber/10 rounded-lg p-3 mb-4",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5 text-amber",children:[e.jsx(V,{"aria-hidden":!0,className:"size-3.5"})," Signaux d'alerte"]}),e.jsx("ul",{className:"space-y-1.5",children:a.signauxDAlerte.map((m,x)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx(V,{"aria-hidden":!0,className:"size-3.5 text-amber shrink-0 mt-0.5"}),e.jsx("span",{children:e.jsx(_,{texte:m})})]},"sa"+x))})]}),a.apresLaVisite.length>0&&e.jsxs("section",{children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 inline-flex items-center gap-1.5",children:[e.jsx(se,{"aria-hidden":!0,className:"size-3.5 text-primary"})," Après la visite"]}),e.jsx("ul",{className:"space-y-1.5",children:a.apresLaVisite.map((m,x)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{}),e.jsx("span",{children:e.jsx(_,{texte:m})})]},"ap"+x))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4 flex-wrap",children:[e.jsx("div",{className:"text-[11px] text-muted-foreground",children:u&&`Généré le ${new Date(u).toLocaleString("fr-FR")}`}),t.data&&e.jsx(F,{bloc:"visite_plan",sourceTable:"projet_etape_ia",sourceId:t.data.id})]})]})}const Wn=["contact","visite","courtier","offre","financement","compromis","acte"];function Yn({project:s,etape:t}){const{data:r,isLoading:n}=ts(s.id);if(!Wn.includes(t)||n)return null;if(!r)return e.jsx(Jr,{projectId:s.id});switch(t){case"contact":return e.jsx(un,{project:s});case"visite":return e.jsx(Xn,{project:s});case"courtier":return e.jsx(wn,{project:s});case"offre":return e.jsx(Jn,{project:s});case"financement":return e.jsx(Rn,{project:s});case"compromis":return e.jsx(Zr,{project:s});case"acte":return e.jsx(Br,{project:s})}}const tt=new Set(["prix_vise","loyer_vise"]);function rt(s,t){const r=s&&typeof s=="object"&&!Array.isArray(s)?s:{},n=Number(r[t]);return Number.isFinite(n)&&n>0?n:null}function nt(s){return rt(s,"loyer")}function me(s){const t=Number(s);return Number.isFinite(t)&&t>0?t:null}function Cs(s,t,r,n={}){const i=n.force===!0,a={...s,offre:s.offre},c=[],l=[["prix_vise",rt(r,"prix")],["loyer_vise",nt(r)],["taux_notaire_pct",t?me(t.frais_notaire_pct):null],["apport",t?me(t.apport_eur):null],["taux_pret_pct",t?me(t.taux):null],["duree_ans",t?me(t.duree_ans):null],["assurance_pct",t?me(t.taux_assurance):null]];for(const[d,o]of l){if(o==null)continue;const u=s[d];u!=null&&!i||u!==o&&(a[d]=o,c.push(d))}return{finances:a,champs:c}}function Zn(s){return s.some(t=>!tt.has(t))}function Oe(s){return s.some(t=>tt.has(t))}const ea=50,Ss=1,zs=7,sa=27,ta=-300,ra=15,na=30,Es={rouge:0,ambre:1};function aa(s,t={}){const r=[],n=t.conjoint===!0,i=Ht(s),a=Xt(s);if((s.offre.montant??0)>0&&(s.prix_vise??0)>0&&s.offre.montant>s.prix_vise){const d=s.offre.montant-s.prix_vise;r.push({id:"offre_superieure_prix",niveau:"rouge",titre:"Offre au-dessus du prix affiché",explication:`Votre offre de ${v(s.offre.montant)} dépasse le prix affiché (${v(s.prix_vise)}), soit ${v(d)} de trop.`,recommandation:"Sauf enchère ou concurrence assumée, une offre ne dépasse pas le prix demandé : vérifiez le montant saisi."})}s.taux_pret_pct!=null&&(s.taux_pret_pct<Ss||s.taux_pret_pct>zs)&&r.push({id:"taux_pret_aberrant",niveau:"rouge",titre:"Taux du prêt improbable",explication:`Un taux de ${s.taux_pret_pct.toLocaleString("fr-FR")} % est très inhabituel pour un prêt immobilier en France (fourchette courante : ${Ss} à ${zs} %).`,recommandation:"Vérifiez votre saisie : le taux s'exprime en % annuel (par exemple 3,5), pas en mensualité ni en décimal."});const c=Wt(s);c!=null&&c<ta&&r.push({id:"cashflow_tres_negatif",niveau:"rouge",titre:"Cash-flow très négatif",explication:`Le projet vous coûte ${v(Math.abs(c))} par mois une fois le loyer encaissé, les charges payées et le crédit remboursé.`,recommandation:n?"Même à deux, êtes-vous sûrs de pouvoir absorber cet effort chaque mois, vacance locative et imprévus compris ?":"Êtes-vous sûr de pouvoir absorber cet effort chaque mois, vacance locative et imprévus compris ?"});const l=t.loyerMarche??null;if((s.loyer_vise??0)>0&&l!=null&&l>0){const d=(s.loyer_vise-l)/l*100;if(d>=ra){const o=d>=na;r.push({id:"loyer_vise_irrealiste",niveau:o?"rouge":"ambre",titre:"Loyer visé au-dessus du marché",explication:`Vous visez ${v(s.loyer_vise)}/mois alors que le marché local est estimé à ${v(l)}/mois (+${Math.round(d)} %).`,recommandation:"Un loyer trop ambitieux allonge la vacance et fausse tous les calculs : refaites vos projections avec le loyer de marché avant de vous engager."})}}if(i!=null&&(s.apport??0)<=0){const d=ls(i,Bs(s)),o=d>0?` (ici environ ${v(d)})`:"";r.push({id:"apport_absent",niveau:"ambre",titre:"Pas d'apport renseigné",explication:"Sans apport, la banque doit financer plus de 100 % du projet (prix + frais). Les financements à 110 % sont devenus rares et se paient par un taux plus élevé.",recommandation:n?`À deux, visez au moins les frais de notaire en apport${o} : vos deux épargnes peuvent se compléter, c'est le minimum attendu par la plupart des banques.`:`Visez au moins les frais de notaire en apport${o} : c'est le minimum attendu par la plupart des banques.`})}if(a!=null&&a>0&&(s.apport??0)>a*ea/100){const d=Math.round(s.apport/a*100);
6r.push({id:"apport_surexposition",niveau:"ambre",titre:"Apport très élevé",explication:`Votre apport de ${v(s.apport)} couvre ${d} % du coût total (${v(a)}). Immobiliser autant de cash vous surexpose à ce seul projet.`,recommandation:"Gardez une épargne de sécurité (travaux imprévus, vacance locative) et profitez du levier du crédit : c'est lui qui fait le rendement en immobilier locatif."})}if(s.taux_notaire_pct===0){const d=i!=null?` Sur ce projet, cela représente environ ${v(ls(i,s.bien_neuf?ye:He))} oubliés.`:"";r.push({id:"notaire_zero",niveau:"ambre",titre:"Frais de notaire à zéro",explication:`Le plan ne prévoit aucun frais de notaire. En France ils existent toujours : environ ${He.toLocaleString("fr-FR")} % dans l'ancien, ${ye.toLocaleString("fr-FR")} % dans le neuf.${d}`,recommandation:"Laissez le champ vide pour reprendre le taux par défaut, ou saisissez le taux réel : sinon le coût total est sous-estimé de plusieurs milliers d'euros."})}return s.duree_ans!=null&&s.duree_ans>sa&&r.push({id:"duree_trop_longue",niveau:"ambre",titre:"Durée de prêt très longue",explication:`${s.duree_ans} ans de crédit : au-delà de 25 ans (plafond HCSF pour la quasi-totalité des banques), les dossiers acceptés sont rarissimes et le coût des intérêts explose.`,recommandation:"Visez 25 ans maximum (27 ans seulement avec différé travaux dans le neuf) et vérifiez ce chiffre : c'est probablement une erreur de saisie."}),r.sort((d,o)=>Es[d.niveau]-Es[o.niveau])}const T="w-full bg-input border border-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-primary",$="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground/80";function R(s){return s==null?"":String(s)}function P(s){if(!s.trim())return null;const t=Number(s.replace(",","."));return Number.isFinite(t)?t:null}function De(s){return{prix_vise:R(s.prix_vise),prix_negocie:R(s.prix_negocie),frais_agence:R(s.frais_agence),bien_neuf:s.bien_neuf,taux_notaire_pct:R(s.taux_notaire_pct),travaux:R(s.travaux),apport:R(s.apport),taux_pret_pct:R(s.taux_pret_pct),duree_ans:R(s.duree_ans),assurance_pct:R(s.assurance_pct),loyer_vise:R(s.loyer_vise),charges_mensuelles:R(s.charges_mensuelles),taxe_fonciere:R(s.taxe_fonciere),avec_conjoint:s.avec_conjoint}}function be(s,t){return{prix_vise:P(s.prix_vise),prix_negocie:P(s.prix_negocie),frais_agence:P(s.frais_agence),bien_neuf:s.bien_neuf,taux_notaire_pct:P(s.taux_notaire_pct),travaux:P(s.travaux),apport:P(s.apport),taux_pret_pct:P(s.taux_pret_pct),duree_ans:P(s.duree_ans),assurance_pct:P(s.assurance_pct),loyer_vise:P(s.loyer_vise),charges_mensuelles:P(s.charges_mensuelles),taxe_fonciere:P(s.taxe_fonciere),avec_conjoint:s.avec_conjoint,offre:t}}function ia({project:s,onGoToOffre:t}){const r=es(s.finances),n=Gs(),i=Jt(),[a,c]=y.useState(()=>De(r)),l=(h,g)=>c(z=>({...z,[h]:g})),[d,o]=y.useState([]),u=y.useRef(!1),m=i.data?{taux:Number(i.data.taux)||0,duree_ans:Number(i.data.duree_ans)||0,apport_eur:Number(i.data.apport_eur)||0,taux_assurance:Number(i.data.taux_assurance)||0,frais_notaire_pct:Number(i.data.frais_notaire_pct)||0}:null;y.useEffect(()=>{if(u.current||i.isLoading)return;u.current=!0;const h=Cs(be(a,r.offre),m,s.annonce_snapshot);h.champs.length>0&&(c(De(h.finances)),o(h.champs))},[i.isLoading]);function x(){const h=Cs(be(a,r.offre),m,s.annonce_snapshot,{force:!0});c(De(h.finances)),o(h.champs),f.success("Valeurs réinitialisées depuis votre profil. Pensez à enregistrer.")}const p=be(a,r.offre),b=Yt(p),N=nt(s.annonce_snapshot)??0,j=aa(p,{loyerMarche:N>0?N:null,conjoint:a.avec_conjoint});async function w(h,g){try{await n.mutateAsync({id:s.id,finances:h}),f.success(g)}catch(z){f.error("Erreur : "+z.message)}}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-3",children:[e.jsx(pe,{label:"Coût total",value:b.coutTotal!=null?v(b.coutTotal):"à compléter"}),e.jsx(pe,{label:"Emprunt",value:b.emprunt!=null?v(b.emprunt):"à compléter"}),e.jsx(pe,{label:e.jsx(oe,{terme:"mensualite",children:"Mensualité"}),value:b.mensualite!=null?v(b.mensualite)+"/mois":"à compléter"}),e.jsx(pe,{label:e.jsx(oe,{terme:"cashflow",children:"Cash-flow"}),value:b.cashflow!=null?v(b.cashflow)+"/mois":"à compléter"}),e.jsx(pe,{label:e.jsx(oe,{terme:"rendement",children:"Rdt brut / net"}),value:b.rendementBrut!=null?`${b.rendementBrut.toFixed(1)} % / ${b.rendementNet!=null?b.rendementNet.toFixed(1)+" %":"?"}`:"à compléter"})]}),b.prix!=null&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Détail : prix retenu ",v(b.prix),(p.frais_agence??0)>0?` + agence ${v(p.frais_agence)}`:""," ","+ notaire ",v(b.fraisNotaire??0)," (",b.tauxNotairePct.toLocaleStr
6ing("fr-FR")," %)",(p.travaux??0)>0?` + travaux ${v(p.travaux)}`:""," ","= ",v(b.coutTotal??0),(p.apport??0)>0?` · apport${a.avec_conjoint?" (à deux)":""} ${v(p.apport)}`:""]}),j.length>0&&e.jsx("div",{className:"space-y-3",children:j.map(h=>e.jsx(oa,{flag:h},h.id))}),e.jsxs("form",{onSubmit:h=>{h.preventDefault(),w(be(a,r.offre),"Finances enregistrées")},className:"space-y-4",children:[e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Acquisition"}),(Oe(d)||d.includes("taux_notaire_pct"))&&e.jsxs("p",{className:"text-[11px] text-primary/90 inline-flex items-center gap-1.5 mb-2",children:[e.jsx(we,{className:"size-3 shrink-0"}),"Pré-rempli depuis ",Oe(d)?"l'annonce":"",Oe(d)&&d.includes("taux_notaire_pct")?" et ":"",d.includes("taux_notaire_pct")?"votre profil":""," : vérifiez et ajustez avant d'enregistrer."]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Prix visé (€)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.prix_vise,onChange:h=>l("prix_vise",h.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Prix négocié (€)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.prix_negocie,onChange:h=>l("prix_negocie",h.target.value),placeholder:"si accord"})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Frais d'agence (€)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.frais_agence,onChange:h=>l("frais_agence",h.target.value),placeholder:"si non inclus"})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Frais de notaire (%)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.taux_notaire_pct,onChange:h=>l("taux_notaire_pct",h.target.value),placeholder:`défaut ${a.bien_neuf?ye:He} %`.replace(".",",")})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.bien_neuf,onChange:h=>l("bien_neuf",h.target.checked),className:"accent-[var(--primary)] size-4"}),"Bien neuf (",ye.toLocaleString("fr-FR")," %)"]})}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Enveloppe travaux (€)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.travaux,onChange:h=>l("travaux",h.target.value)})]})]}),P(a.taux_notaire_pct)==null&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:["Taux appliqué : ",Bs(p).toLocaleString("fr-FR")," % (",a.bien_neuf?"neuf":"ancien","), modifiable ci-dessus."]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap mb-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Financement"}),m&&e.jsx("button",{type:"button",onClick:x,className:"text-[11px] text-muted-foreground hover:text-primary underline underline-offset-2",children:"Réinitialiser depuis mon profil"})]}),Zn(d)&&e.jsxs("p",{className:"text-[11px] text-primary/90 inline-flex items-center gap-1.5 mb-2",children:[e.jsx(we,{className:"size-3 shrink-0"}),"Pré-rempli depuis votre profil : rien n'est écrasé, seules les cases vides ont été complétées."]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("span",{className:$,children:"Vous achetez"}),e.jsx("div",{className:"flex gap-1.5 mt-1.5",children:[[!1,"Seul"],[!0,"Avec conjoint"]].map(([h,g])=>e.jsx("button",{type:"button",onClick:()=>l("avec_conjoint",h),className:`text-xs rounded-md px-2.5 py-1 border transition-colors ${a.avec_conjoint===h?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:g},g))}),a.avec_conjoint&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1.5",children:"Les conseils tiennent compte d'un achat à deux. L'apport saisi reste l'apport total du projet, pas celui de chacun."})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Apport (€)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.apport,onChange:h=>l("apport",h.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Taux du prêt (%)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.taux_pret_pct,onChange:h=>l("taux_pret_pct",h.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Durée (années)"}),e.jsx("input",{className:T,inputMode:"numeric",value:a.duree_ans,onChange:h=>l("duree_ans",h.target.value)})]}),e.jsxs("div",{children:[e.jsxs("label",{className:$,children:[e.jsx(oe,{terme:"assurance_emprunteur",children:"Assurance emprunteur"})," (%/an)"]}),e.jsx("input",{className:T,inputMode:"decimal",value:a.assurance_pct,onChange:h=>l("assurance_pct",h.target.value),placeholder:"ex. 0,34"})]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Exploitation projetée"}),d.includes("loyer_vise")&&e.jsxs("p",{className:"text-[11px] text-primary/90 inline-flex items-center gap-1.5 mb-2",children:[e.jsx(we,{className:"size-3 shrink-0"}),"Loyer pré-rempli depuis le loyer de marché estimé de l'annonce : ajustez-le à votre bien."]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:$,children:["Loyer visé 
6(€/mois ",e.jsx(oe,{terme:"hc",children:"hors charges"}),")"]}),e.jsx("input",{className:T,inputMode:"decimal",value:a.loyer_vise,onChange:h=>l("loyer_vise",h.target.value)}),N>0&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1",children:["Marché estimé : ",v(N),"/mois"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Charges estimées (€/mois)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.charges_mensuelles,onChange:h=>l("charges_mensuelles",h.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:$,children:"Taxe foncière estimée (€/an)"}),e.jsx("input",{className:T,inputMode:"decimal",value:a.taxe_fonciere,onChange:h=>l("taxe_fonciere",h.target.value)})]})]})]}),e.jsxs("button",{type:"submit",disabled:n.isPending,className:"inline-flex items-center gap-2 bg-primary text-primary-foreground rounded-lg px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:brightness-110",children:[e.jsx(Us,{className:"size-4"})," ",n.isPending?"Enregistrement…":"Enregistrer les finances"]})]}),e.jsx("section",{className:"border-t border-border pt-5",children:e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-semibold inline-flex items-center gap-1.5",children:[e.jsx(Ke,{className:"size-4 text-primary"})," Votre offre se gère dans l'onglet Offre"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:r.offre.montant!=null?`Offre en cours : ${v(r.offre.montant)}${r.offre.statut?` (${Xe[r.offre.statut]})`:""}. Une offre acceptée devient le prix retenu des calculs ci-dessus.`:"Fourchette recommandée, dépôt, statut et historique : tout est là-bas."})]}),t&&e.jsxs("button",{type:"button",onClick:t,className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-primary border border-border hover:border-primary rounded-md px-2.5 py-1.5 shrink-0",children:["Aller à l'onglet Offre ",e.jsx(Ks,{className:"size-3.5"})]})]})})]})}function oa({flag:s}){const t=s.niveau==="rouge",r=t?Cr:V;return e.jsx("div",{className:`rounded-xl border p-4 ${t?"border-neg/40 bg-neg/10":"border-amber/40 bg-amber/10"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(r,{className:`size-5 shrink-0 mt-0.5 ${t?"text-neg":"text-amber"}`}),e.jsxs("div",{className:"space-y-1.5 min-w-0",children:[e.jsx("div",{className:`text-sm font-semibold ${t?"text-neg":"text-amber"}`,children:s.titre}),e.jsx("p",{className:"text-sm leading-relaxed text-foreground/75",children:s.explication}),e.jsxs("p",{className:"text-sm leading-relaxed text-foreground/90",children:[e.jsx("span",{className:"font-semibold",children:"Notre conseil : "}),s.recommandation]})]})]})})}function pe({label:s,value:t,tone:r}){return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("div",{className:`text-base font-bold font-mono tabular-nums mt-0.5 ${r==="pos"?"text-pos":r==="neg"?"text-neg":""}`,children:t})]})}const $s="w-full bg-input border border-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-primary",Ps="text-[11px] uppercase tracking-wider font-semibold text-muted-foreground/80";function qs(s){if(!s.trim())return null;const t=Number(s.replace(",","."));return Number.isFinite(t)?t:null}function la({project:s}){const t=es(s.finances),r=Gs(),[n,i]=y.useState(()=>t.offre.montant!=null?String(t.offre.montant):""),[a,c]=y.useState(()=>new Date().toISOString().slice(0,10));async function l(){const o=qs(n);if(o==null||o<=0){f.error("Renseignez le montant de votre offre");return}const u={...t,offre:er(t.offre,o,a)};try{await r.mutateAsync({id:s.id,finances:u}),f.success(`Offre de ${v(o)} enregistrée dans votre suivi (en attente).`)}catch(m){f.error("Erreur : "+m.message)}}async function d(o){const u={...t,offre:sr(t.offre,o)};try{await r.mutateAsync({id:s.id,finances:u}),f.success("Statut de l'offre mis à jour")}catch(m){f.error("Erreur : "+m.message)}}return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Suivi de votre offre"}),e.jsx("p",{className:"text-[11px] text-muted-foreground mb-3",children:"Enregistrez ici le montant que vous avez réellement proposé pour le suivre. Rien n'est transmis au vendeur ni à l'agence : votre lettre d'offre à envoyer est générée dans « Générer mon offre », au-dessus. Une offre marquée « acceptée » devient le prix retenu des calculs de la Simulation."}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:Ps,children:"Montant (€)"}),e.jsx("input",{className:$s,inputMode:"decimal",value:n,onChange:o=>i(o.target.value),placeholder:"ex. 132000"})]}),e.jsxs("div",{children:[e.jsx("label",{className:Ps,children:"Date"}),e.jsx("input",{type:"date",className:$s,value:a,onChange:o=>c(o.target.value)})]}),e.jsxs("button",{type:"button",disabled:r.isPending||(qs(n)??0)<=0,onClick:()=>{l()},className:"inline-flex items-center gap-2 bg-primary text-primary-foreground rounded-lg px-4 py-2 text-sm font-semibold disabled:opacity-50 hover:brightness-110",children:[e.jsx(ar,{className:"size-4"})," Enregistrer cette offre"]})]}),t.offre.montant!=null?e.jsxs("div",{className:"bg-card border border-border rounded-xl p-3.5 mb-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-bold font-mono tabular-nums",children:v(t.offre.montant)}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Offre du ",t.offre.date?new Date(t.offre.date).toLocaleDateString("fr-FR"):"?"]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Zt.map(o=>e.jsx("button",{type:"button",disabled:r.isPending,onClick:()=>{d(o)},className:`text-[11px] rounded-md px-2 py-0.5 border transition-colors disabled:opacity-50 ${t.offre.statut===o?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:Xe[o]},o))})]}),t.offre.statut==="acceptee"&&e.jsx("div",{className:"text-[11px] text-pos mt-2",children:"Offre acceptée : ce montant devient le prix retenu des calculs de la Simulation."})]}):e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Aucune offre enregistrée pour le moment."}),t.offre.historique.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground
6/70 mb-1.5",children:"Offres précédentes"}),e.jsx("ul",{className:"space-y-1",children:t.offre.historique.map((o,u)=>e.jsxs("li",{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"font-mono tabular-nums",children:v(o.montant)}),e.jsx("span",{className:"text-[11px]",children:o.date?new Date(o.date).toLocaleDateString("fr-FR"):""}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider border border-border rounded-full px-2 py-0.5",children:Xe[o.statut]??o.statut})]},u))})]})]})}function Di(){const{id:s}=xt({from:"/_authenticated/app/projets/$id"}),{etape:t}=ft.useSearch(),{data:r,isLoading:n}=Fs(s),i=Nt(),a=_t(),c=ht(),l=gt(t,r?.statut);function d(x){c({to:"/app/projets/$id",params:{id:s},search:{etape:x},replace:!0})}if(n)return e.jsxs("div",{className:"p-6 md:p-10 max-w-5xl mx-auto space-y-4",children:[e.jsx(E,{className:"h-6 w-32"}),e.jsx(E,{className:"h-28 w-full"}),e.jsx(E,{className:"h-64 w-full"})]});if(!r)return e.jsxs("div",{className:"p-10 max-w-3xl mx-auto",children:[e.jsxs(H,{to:"/app/projets",className:"text-sm text-muted-foreground hover:text-primary inline-flex items-center gap-1 mb-4",children:[e.jsx(cs,{className:"size-4"})," Pistes"]}),e.jsx("div",{className:"bg-card border border-border rounded-2xl p-8 text-center text-muted-foreground",children:"Piste introuvable."})]});const o=r.statut,u=jt(o);function m(){!r||!u||i.isPending||i.mutate({id:r.id,statut:u},{onSuccess:()=>{const x=zt(u);f.success(`🎉 ${x.titre}`,{description:x.message,duration:x.niveau==="grand"?9e3:5e3}),d(u)},onError:x=>f.error("Erreur : "+x.message)})}return e.jsxs("div",{className:"p-4 md:p-8 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4",children:[e.jsxs(H,{to:"/app/projets",className:"text-sm text-muted-foreground hover:text-primary inline-flex items-center gap-1",children:[e.jsx(cs,{className:"size-4"})," Pistes"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{projectId:r.id}),e.jsxs(qt,{children:[e.jsx(Lt,{asChild:!0,children:e.jsxs("button",{type:"button","aria-label":"Actions de la piste",className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1",children:[e.jsx(jr,{className:"size-3"})," Actions"]})}),e.jsx(Mt,{align:"end",className:"w-64",children:e.jsxs(Tt,{onSelect:async()=>{if(confirm("Supprimer cette piste ? Les événements seront effacés."))try{await a.mutateAsync(r.id),f.success("Piste supprimée"),c({to:"/app/projets"})}catch(x){f.error("Erreur : "+x.message)}},className:"gap-2 cursor-pointer text-neg focus:text-neg",children:[e.jsx(or,{className:"size-4"})," Supprimer la piste"]})})]})]})]}),e.jsx(ca,{project:r,panel:l,onGoPanel:d,pending:i.isPending,onAvancer:m}),e.jsxs("div",{className:"lg:hidden mt-4 flex gap-1.5 overflow-x-auto pb-1",children:[e.jsxs(Ie,{accent:!0,actif:l==="apercu",onClick:()=>d("apercu"),children:[e.jsx(Hs,{"aria-hidden":!0,className:"size-3"})," Aperçu & analyse"]}),Ue.map((x,p)=>e.jsxs(Ie,{actif:l===x,onClick:()=>d(x),children:[p<ne(o)?e.jsx(ae,{"aria-hidden":!0,className:"size-3 text-pos"}):e.jsxs("span",{className:"tabular-nums",children:[p+1,"."]}),Z[x]]},x)),e.jsxs(Ie,{actif:l==="documents",onClick:()=>d("documents"),children:[e.jsx(Ze,{"aria-hidden":!0,className:"size-3"})," Documents"]})]}),e.jsxs("div",{className:"mt-4 lg:grid lg:grid-cols-[228px_minmax(0,1fr)] lg:gap-6 lg:items-start",children:[e.jsx(da,{statut:o,panel:l,onSelect:d}),e.jsxs("div",{className:"min-w-0",children:[l==="apercu"&&e.jsxs("div",{children:[e.jsx(xa,{project:r}),e.jsx(Dr,{projectId:r.id}),e.jsxs("details",{className:"rounded-xl border border-border bg-card",children:[e.jsx("summary",{className:"cursor-pointer p-4 text-sm font-semibold",children:"Plan d'action et checklist détaillée"}),e.jsx("div",{className:"px-3 pb-3",children:e.jsx(Rr,{projectId:r.id})})]})]}),l==="documents"&&e.jsx(Ct,{projectId:r.id}),l!=="apercu"&&l!=="documents"&&e.jsx(ua,{project:r,etape:l,onPlacer:()=>i.mutate({id:r.id,statut:l},{onSuccess:()=>f.success(`Piste placée à l'étape ${Z[l]}`),onError:x=>f.error("Erreur : "+x.message)}),onGoPanel:d})]})]})]})}function Ie({actif:s,accent:t,onClick:r,children:n}){return e.jsx("button",{type:"button",onClick:r,"aria-current":s?"page":void 0,className:`shrink-0 inline-flex items-center gap-1.5 text-xs rounded-md px-2.5 py-1.5 border transition-colors ${s?"bg-primary/10 border-primary/50 text-primary font-semibold":t?"bg-primary/5 border-primary/40 text-foreground font-semibold hover:bg-primary/10":"border-border text-muted-foreground hover:border-primary hover:text-primary"}`,children:n})}function ca({project:s,panel:t,onGoPanel:r,pending:n,onAvancer:i}){const a=s.statut,c=bt(a,t),l=ne(a),d=s.annonce_snapshot??{};return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 flex flex-col md:flex-row gap-4 md:items-center",children:[e.jsx(at,{img:
6d.img,refAnnonce:s.annonce_ref,compact:!0}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-xl font-display font-semibold tracking-tight leading-snug",children:s.nom}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[d.ville," ",d.cp||"",d.prix?e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"text-foreground font-mono tabular-nums font-semibold",children:v(d.prix)})]}):null,d.surface?` · ${d.surface} m²`:"",d.rdt?` · rdt ${d.rdt.toFixed(1)} %`:""]}),e.jsx(ha,{project:s,snapPrix:d.prix})]}),e.jsxs("div",{className:"md:w-72 shrink-0",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Étape ",Ts(a)," sur ",Ue.length," ·"," ",e.jsx("span",{className:"text-foreground font-semibold",children:Z[a]})]}),e.jsx("div",{className:"flex gap-[3px] my-2","aria-hidden":!0,children:Ue.map((o,u)=>e.jsx("span",{className:`h-1 flex-1 rounded-full ${u<l?"bg-pos/70":u===l?"bg-primary":"bg-border"}`},o))}),c?e.jsxs("button",{type:"button",disabled:n,onClick:()=>c.kind==="retour"?r(c.destination):i(),className:"w-full inline-flex items-center justify-center gap-2 bg-primary text-primary-foreground font-semibold rounded-lg px-3 py-2 text-xs hover:brightness-110 disabled:opacity-50",children:[c.label,e.jsx(Ks,{"aria-hidden":!0,className:"size-3.5"})]}):e.jsxs("div",{className:"text-[11px] text-pos inline-flex items-center gap-1.5",children:[e.jsx(ae,{className:"size-3"})," Dernière étape : préparez la signature de l'acte"]})]})]})}function da({statut:s,panel:t,onSelect:r}){const n=ne(s);return e.jsxs("aside",{className:"hidden lg:block sticky top-6 bg-surface border border-border rounded-xl p-2.5",children:[e.jsx(Ve,{children:"La piste"}),e.jsxs(Je,{accent:!0,actif:t==="apercu",onClick:()=>r("apercu"),children:[e.jsx("span",{className:"inline-flex items-center justify-center size-[17px] rounded-full border border-primary/50 bg-primary/10 text-primary text-[10px] font-mono font-bold shrink-0",children:e.jsx(Hs,{"aria-hidden":!0,className:"size-3"})}),"Aperçu & analyse"]}),St.map(i=>e.jsxs("div",{children:[e.jsx(Ve,{children:i.label}),i.statuts.map(a=>{const c=ne(a),l=c<n,d=a===s;return e.jsxs(Je,{actif:t===a,onClick:()=>r(a),children:[e.jsx("span",{className:`inline-flex items-center justify-center size-[17px] rounded-full border text-[10px] font-mono shrink-0 ${l?"border-pos/50 text-pos":"border-border text-muted-foreground/70"}`,children:l?e.jsx(ae,{"aria-hidden":!0,className:"size-2.5"}):c+1}),e.jsx("span",{className:d?"font-semibold text-foreground":void 0,children:Z[a]})]},a)})]},i.key)),e.jsx(Ve,{children:"Annexes"}),e.jsxs(Je,{actif:t==="documents",onClick:()=>r("documents"),children:[e.jsx(Ze,{"aria-hidden":!0,className:"size-3.5 shrink-0"})," Documents"]})]})}function Ve({children:s}){return e.jsx("div",{className:"px-2.5 pt-3 pb-1 text-[9px] uppercase tracking-[0.12em] font-bold text-muted-foreground/50 first:pt-1.5",children:s})}function Je({actif:s,accent:t,onClick:r,children:n}){return e.jsx("button",{type:"button",onClick:r,"aria-current":s?"page":void 0,className:`w-full flex items-center gap-2.5 text-[13px] rounded-lg px-2.5 py-1.5 text-left transition-colors ${s?"bg-primary/10 text-primary font-medium":t?"bg-primary/5 ring-1 ring-primary/20 text-foreground font-medium hover:bg-primary/10":"text-muted-foreground hover:text-foreground hover:bg-muted/40"}`,children:n})}function ua({project:s,etape:t,onPlacer:r,onGoPanel:n}){const i=s.statut,a=Rs[t],c=t===i,l=ne(t)<ne(i);return e.jsxs("div",{className:"space-y-3",children:[!c&&e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap bg-input border border-border rounded-lg px-3.5 py-2.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:l?e.jsxs(e.Fragment,{children:[e.jsx(ae,{"aria-hidden":!0,className:"size-3 inline text-pos mr-1"}),"Étape déjà passée. Votre piste est à :"," ",e.jsx("b",{className:"text-foreground",children:Z[i]}),"."]}):e.jsxs(e.Fragment,{children:["Étape à venir. Votre piste est à :"," ",e.jsx("b",{className:"text-foreground",children:Z[i]}),"."]})}),e.jsx("button",{type:"button",onClick:r,className:"text-muted-foreground hover:text-primary border border-border hover:border-primary rounded-md px-2 py-1",children:"Placer la piste à cette étape"})]}),a&&e.jsx(ma,{etape:t}),e.jsx(Yn,{project:s,etape:t}),t==="offre"&&e.jsx(la,{project:s}),t==="financement"&&e.jsx(ia,{project:s,onGoToOffre:()=>n("offre")}
6),t==="acte"&&e.jsx(pa,{})]})}function ma({etape:s}){const[t,r]=y.useState(!1),n=Rs[s];return n?e.jsxs($r,{open:t,onOpenChange:r,className:"bg-card border border-border rounded-xl",children:[e.jsxs(Pr,{className:"w-full flex items-start gap-2.5 p-3.5 text-left",children:[e.jsx(Ye,{"aria-hidden":!0,className:"size-4 text-primary shrink-0 mt-0.5"}),e.jsxs("span",{className:"text-sm flex-1 min-w-0",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground block",children:["Objectif de l'étape ",Ts(s)," : ",Z[s]]}),n.objectif,e.jsx("span",{className:"block text-xs text-muted-foreground mt-1",children:t?"Replier les conseils":`Pourquoi ça compte + ${n.conseils.length} conseils`})]}),e.jsx(lr,{"aria-hidden":!0,className:`size-4 text-muted-foreground shrink-0 mt-0.5 transition-transform ${t?"rotate-180":""}`})]}),e.jsxs(qr,{className:"px-3.5 pb-3.5 space-y-2.5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n.pourquoi}),e.jsx("ul",{className:"space-y-1.5",children:n.conseils.map(i=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(Qs,{"aria-hidden":!0,className:"size-3.5 text-amber shrink-0 mt-0.5"}),e.jsx("span",{children:i})]},i))}),e.jsx(fa,{statut:s})]})]}):null}function pa(){return e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4",children:[e.jsxs("div",{className:"text-sm font-display font-semibold inline-flex items-center gap-2",children:[e.jsx(ae,{"aria-hidden":!0,className:"size-4 text-pos"})," Le projet s'arrête ici"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:"Acte signé, clés en main. La gestion locative (bail, quittances, loyers) arrive en V2."})]})}function xa({project:s}){const t=s.annonce_snapshot??{};return!s.annonce_ref&&!t?.titre?null:e.jsxs("div",{className:"bg-card border border-border rounded-xl p-4 mb-3 flex gap-4",children:[e.jsx(at,{img:t.img,refAnnonce:s.annonce_ref}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:[t.ville," ",t.cp||""]}),e.jsx("div",{className:"text-sm font-semibold truncate",children:t.titre}),e.jsx("div",{className:"text-lg font-bold font-mono tabular-nums mt-1",children:t.prix?v(t.prix):"n/c"}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[t.surface?`${t.surface} m²`:"",t.pieces?` · ${t.pieces} p.`:"",t.rdt?` · Rdt ${t.rdt.toFixed(1)}%`:""]}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[s.annonce_ref&&e.jsx(H,{to:"/app/recherche/$ref",params:{ref:s.annonce_ref},className:"text-xs text-primary hover:underline",children:"Voir la fiche"}),t.url&&e.jsxs("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-primary inline-flex items-center gap-1",children:["Annonce d'origine ",e.jsx(Js,{className:"size-3"})]})]})]})]})}function fa({statut:s}){const t=zr(s),r=Er(s);return t.length===0&&!r?null:e.jsxs("div",{className:"flex items-center gap-x-3 gap-y-1.5 flex-wrap text-xs pt-0.5",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-wider font-semibold text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(vt,{"aria-hidden":!0,className:"size-3.5"})," Pour aller plus loin"]}),t.map(n=>e.jsxs(H,{to:"/app/academie/$slug",params:{slug:n.slug},className:"text-primary hover:underline underline-offset-2",children:[n.titre," (",n.minutes," min)"]},n.slug)),r&&e.jsx(H,{to:"/app/academie",search:{etape:r},className:"text-muted-foreground hover:text-primary underline underline-offset-2",children:"Tous les guides de l'étape"})]})}function at({img:s,refAnnonce:t,compact:r}){const n=r?"w-24 h-[68px] rounded-lg":"w-36 h-28 md:w-44 md:h-32 rounded-lg",i=s?e.jsx(ir,{src:s,alt:"Photo de l'annonce",className:n}):e.jsxs("div",{className:`${n} bg-input border border-border flex flex-col items-center justify-center gap-1.5 text-muted-foreground/50`,children:[e.jsx(cr,{className:"size-6"}),!r&&e.jsx("span",{className:"text-[10px] uppercase tracking-wider",children:"Pas de photo"})]});return t?e.jsx(H,{to:"/app/recherche/$ref",params:{ref:t},title:"Voir la fiche annonce",className:"shrink-0 block rounded-lg hover:ring-2 hover:ring-primary/60 transition-shadow",children:i}):e.jsx("div",{className:"shrink-0",children:i})}function ha({project:s,snapPrix:t}){const r=s.annonce_ref,n=kt(),{data:i,isSuccess:a}=_e({queryKey:["annonce-live",r],enabled:!!r,staleTime:5*6e4,queryFn:()=>yt(r)});if(!r||!a)return null;if(i==null)return e.jsx("div",{className:"mt-2 text-[11px] inline-flex items-center gap-1.5 border border-amber/50 text-amber rounded-md px-2 py-1",children:"Annonce plus disponible (les informations enregistrées restent consultables)"});const c=Number(i.prix)||0,l=Number(t)||0;return c<=0||l<=0||c===l?null:e.jsxs("div",{className:"mt-2 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:`text-[11px] inline-flex items-center gap-1.5 border rounded-md px-2 py-1 ${c<l?"border-pos/50 text-pos":"border-neg/50 text-neg"}`,children:["Prix a changé : ",v(l)," → ",v(c)]}),e.jsxs("button",{type:"button",disabled:n.isPending,onClick:async()=>{const d=s.annonce_snapshot??{},o={...d,prix:i.prix,titre:i.titre??d.titre,img:i.img??d.img,url:i.url??d.url,surface:i.surface??d.surface,pieces:i.pieces??d.pieces,lastSeen:i.lastSeen??d.lastSeen};try{await n.mutateAsync({id:s.id,snapshot:o}),f.success("Annonce actualisée")}catch(u){f.error("Erreur : "+u.message)}},className:"text-[11px] text-muted-foreground hover:text-primary inline-flex items-center gap-1 border border-border hover:border-primary rounded-md px-2 py-1 disabled:opacity-50",children:[e.jsx(L,{className:"size-3"})," Actualiser l'annonce"]})]})}export{Di as component};

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.