1import{j as e,r as i}from"./vendor-query-D03kqGcP.js";import{c as Pe,d as Te,u as X,A as Ie,K as oe,f as W,O as Ne,i as V,Q as ee,S as de,t as te,V as re,X as pe,W as ke,T as Le,Y as Me,q as De,k as Be,s as Ae,N as Ke,h as Ue,x as ze,l as He,F as qe}from"./index-D_dNnqBM.js";import{P as Ve}from"./PageFAQ-BnAMdvLG.js";import{m as $,A as ce}from"./vendor-motion-COUPMg2I.js";import{P as Ge,S as Ze}from"./share-2-DXMNksl7.js";import{C as We}from"./circle-x-CZxZQcpb.js";import{C as fe}from"./calculator-CAQOoZqY.js";import{F as Se}from"./file-text-B3Kj_iZu.js";import{M as ne}from"./mail-CAYNgcx-.js";import{L as J}from"./lock-loE9n_Sc.js";import{C as le}from"./check-CbM6x7KO.js";import{L as ge}from"./link-2-B5lXSQ58.js";import{A as Xe}from"./arrow-left-5Q2QqU3X.js";import"./vendor-react-BIgjgDsd.js";const Ye=Pe("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),Qe="/assets/simulator_hero_8-tO6KbefS.webp",Je=300,et=3.5,tt=.001062,st=.85,Ce=.7,_e=.82,Oe=.9,at=2;function rt(t,s){const u=1-t/s,d=Math.round(u*100),r=Math.round(d*Ce),o=Math.round(r*_e),h=Math.round(r*Oe),l=Math.round((1-Math.pow(1-u,at))*100);return{tripPct:d,kmPct:r,costPct:o,co2Pct:h,hoursPct:l}}const ot=Je,ue=tt,he=st,it=et,Ee=Ce,Re=_e,$e=Oe;function nt(t,s,u,d,r){const o=1-s/u,h=Math.round(t*o),l=r??ot,p=d??it,f=Math.round(h*l*Ee),b=Math.round(f*p*Re),L=parseFloat((f*ue*$e).toFixed(1)),O=Math.round(t*he);return{tripsEliminated:h,savings:b,kmReduction:f,co2Reduction:L,hoursSaved:O,currentOccupancy:s,targetOccupancy:u,inputs:{trips:t,currentOcc:s,targetOcc:u,kmPerTrip:l,costPerKm:p,usedDefaultKm:r===null,usedDefaultCost:d===null}}}const xe={"pt-br":"pt-BR",en:"en-US",es:"es-ES"};function z(t,s){const u=xe[s]||"pt-BR";return new Intl.NumberFormat(u,{maximumFractionDigits:0}).format(t)}function Y(t,s){const u=xe[s]||"pt-BR";return new Intl.NumberFormat(u,{minimumFractionDigits:1,maximumFractionDigits:2}).format(t)}const H="w-full bg-background/80 border border-border/60 rounded-lg px-4 py-3 text-foreground placeholder:text-muted-foreground/40 focus:outline-none focus:ring-2 focus:ring-primary/40 focus:border-primary/40 transition-colors text-sm font-mono",q="w-full bg-background/80 border border-red-500/60 rounded-lg px-4 py-3 text-foreground placeholder:text-muted-foreground/40 focus:outline-none focus:ring-2 focus:ring-red-500/40 focus:border-red-500/40 transition-colors text-sm font-mono",we={cyan:{bg:"bg-cyan-500/10",border:"border-cyan-500/20",text:"text-cyan-400",glow:"shadow-[0_0_40px_rgba(6,182,212,0.08)]"},emerald:{bg:"bg-emerald-500/10",border:"border-emerald-500/20",text:"text-emerald-400",glow:"shadow-[0_0_40px_rgba(16,185,129,0.08)]"},violet:{bg:"bg-violet-500/10",border:"border-violet-500/20",text:"text-violet-400",glow:"shadow-[0_0_40px_rgba(139,92,246,0.08)]"},amber:{bg:"bg-amber-500/10",border:"border-amber-500/20",text:"text-amber-400",glow:"shadow-[0_0_40px_rgba(245,158,11,0.08)]"}};function lt({value:t,decimals:s=0,duration:u=2e3}){const{lang:d}=X(),r=xe[d]||"pt-BR",[o,h]=i.useState("0"),l=i.useRef(!1);return i.useEffect(()=>{if(l.current)return;l.current=!0;const p=new Intl.NumberFormat(r,{minimumFractionDigits:s,maximumFractionDigits:s}),f=Date.now(),b=()=>{const L=Date.now()-f,a=Math.min(L/u,1),O=1-Math.pow(1-a,3),k=t*O;h(p.format(k)),a<1&&requestAnimationFrame(b)};requestAnimationFrame(b)},[t,s,u,r]),e.jsx("span",{children:o})}function ye({percentage:t,color:s,status:u,label:d}){const r=s==="cyan"?"bg-gradient-to-t from-cyan-500/80 to-cyan-400/60":"bg-gradient-to-t from-orange-500/60 to-orange-400/40",o=s==="cyan"?"border-cyan-500/40":"border-orange-500/40",h=s==="cyan"?"text-cyan-400":"text-orange-400",l=s==="cyan"?"shadow-[0_0_60px_rgba(6,182,212,0.15)]":"shadow-[0_0_60px_rgba(249,115,22,0.1)]";return e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs("div",{className:`relative w-full max-w-[200px] h-[220px] border-2 ${o} rounded-lg overflow-hidden ${l} bg-background/50 mx-auto`,"data-testid":`container-${s}`,children:[e.jsx("div",{className:"absolute inset-0 opacity-10",children:Array.from({length:8}).map((p,f)=>e.jsx("div",{className:"border-b border-border/30",style:{height:"12.5%"}},f))}),e.jsx($.div,{className:`absolute bottom-0 left-0 right-0 ${r}`,initial:{height:"0%"},animate:{height:`${t}%`},transition:{duration:1.5,ease:"easeOut",delay:s==="cyan"?.3:0},children:e.jsx("div",{className:"absolute inset-0 opacity-20",children:Array.from({length:Math.floor(t/10)}).map((p,f)=>e.jsx("div",{className:"border-b border-white/20 mx-1",style:{height:`${100/Math.floor(t/10)}%`},children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx(Ge,{className:"w-3 h-3 text-white/30"})})},f))})}),e.jsx($.div,{className:"absolute top-2 left-0 right-0 flex items-center justify-center",initial:{opacity:0}
1,animate:{opacity:1},transition:{delay:1.8,duration:.5},children:e.jsx("span",{className:`text-xs ${h} opacity-60 font-mono uppercase tracking-wider`,children:d})}),e.jsx($.div,{className:"absolute bottom-3 left-0 right-0 flex items-center justify-center",initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{delay:1.6,duration:.4},children:e.jsxs("span",{className:`text-3xl font-display font-bold ${h}`,children:[t,"%"]})})]}),e.jsx("div",{className:"text-center",children:e.jsxs("div",{className:"flex items-center gap-2 justify-center",children:[s==="red"?e.jsx(We,{className:"w-4 h-4 text-orange-400"}):e.jsx(Te,{className:"w-4 h-4 text-cyan-400"}),e.jsx("span",{className:`text-sm font-semibold ${h}`,children:u})]})})]})}function se({label:t,helper:s,error:u,children:d,htmlFor:r}){const o=r?`${r}-helper`:void 0,h=r?`${r}-error`:void 0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:r,className:"block text-sm font-medium text-foreground",children:t}),d,u?e.jsx("p",{id:h,className:"text-xs text-red-400",role:"alert",children:u}):e.jsx("p",{id:o,className:"text-xs text-muted-foreground",children:s})]})}function ae({label:t,value:s,suffix:u}){return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 sm:px-4 py-3",children:[e.jsx("span",{className:"text-xs sm:text-sm text-muted-foreground shrink-0",children:t}),e.jsxs("span",{className:"text-xs sm:text-sm font-mono font-medium text-foreground text-right",children:[s,u&&e.jsx("span",{className:"text-xs text-muted-foreground/60 ml-1.5",children:u})]})]})}function Q({label:t,formula:s,result:u,note:d}){return e.jsxs("div",{className:"bg-muted/30 rounded-xl border border-border/50 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:t}),e.jsx("span",{className:"text-sm font-mono font-bold text-primary",children:u})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground font-mono",children:[e.jsx(Ie,{className:"w-3 h-3 flex-shrink-0"}),e.jsx("span",{children:s})]}),d&&e.jsx("div",{className:"text-xs text-muted-foreground/60 mt-1.5 italic space-y-0.5",children:d.split(` 2`).map((r,o)=>e.jsx("p",{children:r},o))})]})}function ct({onResults:t}){const{t:s,lang:u}=X(),{toast:d}=oe(),[r,o]=i.useState(!1),[h,l]=i.useState(""),[p,f]=i.useState(""),[b,L]=i.useState(""),[a,O]=i.useState(""),[k,F]=i.useState(""),[A,E]=i.useState({}),R=i.useRef(!1),P=()=>{R.current||(R.current=!0,te("simulator_start",{page_path:window.location.pathname}))},[T,M]=i.useState({}),y=i.useCallback(()=>{const c={},D=parseFloat(h),S=parseFloat(p),I=parseFloat(b),K=a?parseFloat(a):null,B=k?parseFloat(k):null;return(!h||isNaN(D)||D<=0)&&(c.trips=s.showroom.validationPositive),!p||isNaN(S)?c.current=s.showroom.validationRequired:(S<1||S>100)&&(c.current=s.showroom.validationOccupancyRange),!b||isNaN(I)?c.target=s.showroom.validationRequired:I<1||I>100?c.target=s.showroom.validationOccupancyRange:!isNaN(S)&&I<=S&&(c.target=s.showroom.validationTargetGreater),K!==null&&(isNaN(K)||K<=0)&&(c.km=s.showroom.validationPositive),B!==null&&(isNaN(B)||B<=0)&&(c.cost=s.showroom.validationPositive),c},[h,p,b,a,k,s]),U=i.useCallback(()=>{const c=y();return E(c),M({trips:!0,current:!0,target:!0,km:!0,cost:!0}),Object.keys(c).length===0},[y]),m=c=>()=>{M(S=>({...S,[c]:!0}));const D=y();E(S=>({...S,[c]:D[c]||""}))},x=c=>T[c]?A[c]:void 0;i.useEffect(()=>{if(Object.keys(T).length===0)return;const c=y();E(D=>{const S={...D};for(const I of Object.keys(T))S[I]=c[I]||"";return S})},[h,p,b,a,k,T,y]);const _=async()=>{if(!U())return;const c=parseFloat(h),D=parseFloat(p),S=parseFloat(b),I=a?parseFloat(a):null,K=k?parseFloat(k):null;te("simulator_calculate",{trips_per_month:c,current_occupancy:D,target_occupancy:S,page_path:window.location.pathname}),o(!0);try{const w=await(await re("POST","/api/simulator/run",{lang:u,trips:c,currentOcc:D,targetOcc:S,kmPerTrip:I,costPerKm:K})).json(),v={tripsEliminated:w.results.tripsEliminated,savings:w.results.savings,kmReduction:w.results.kmReduction,co2Reduction:w.results.co2Reduction,hoursSaved:w.results.hoursSaved,currentOccupancy:w.inputs.currentOcc,targetOccupancy:w.inputs.targetOcc,inputs:w.inputs};t(v,w.runId,w.runToken??null)}catch{const B=nt(c,D,S,K,I);t(B,null,null),d({title:s.showroom.unlockError,variant:"destructive"})}finally{o(!1)}};return e.jsx($.div,{initial:"hidden",animate:"visible",exit:{opacity:0,y:-20,transition:{duration:.3}},variants:W,className:"max-w-2xl mx-auto",children:e.jsx("div",{className:"rounded-2xl p-5 sm:p-8 md:p-10 bg-gradient-to-br from-primary/20 via-primary/10 to-cyan-500/10 border border-primary/40 shadow-lg shadow-primary/10 relative overflow-hidden","data-testid":"panel-form",onFocus:P,children:e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 border border-primary/20 flex items-center justify-center",children:e.jsx(fe,{className:"w-5 h-5 text-primary"})}),e.jsx("h2",{className:"text-2xl font-display font-bold","data-testid":"text-form-title",children:s.showroom.formTitle})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-8 ml-[52px]",children:s.showroom.formSubtitle}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(se,{label:s.showroom.inputTripsPerMonth,helper:s.showroom.inputTripsHelper,error:x("trips"),htmlFor:"sim-trips",children:e.jsx("input",{id:"sim-trips",type:"number",min:"1",value:h,onChange:c=>l(c.target.value),onBlur:m("trips"),placeholder:s.showroom.inputTripsPlaceholder,className:x("trips")?q:H,"aria-invalid":!!x("trips"),"aria-describedby":x("trips")?"sim-trips-error":"sim-trips-helper","data-testid":"input-trips"})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(se,{label:s.showroom.inputCurrentOccupancy,helper:s.showroom.inputCurrentHelper,error:x("current"),htmlFor:"sim-current",children:e.jsx("input",{id:"sim-current",type:"number",min:"1",max:"100",value:p,onChange:c=>f(c.target.value),onBlur:m("current"),placeholder:s.showroom.inputCurrentPlaceholder,className:x("current")?q:H,"aria-invalid":!!x("current"),"aria-describedby":x("current")?"sim-current-error":"sim-current-helper","data-testid":"input-current-occupancy"})}),e.jsx(se,{label:s.showroom.inputTargetOccupancy,helper:s.showroom.inputTargetHelper,error:x("target"),htmlFor:"sim-target",children:e.jsx("input",{id:"sim-target",type:"number",min:"1",max:"100",value:b,onChange:c=>L(c.target.value),onBlur:m("target"),placeholder:s.showroom.inputTargetPlaceholder,className:x("target")?q:H,"aria-invalid":!!x("target"),"aria-describedby":x("target")?"sim-target-error":"sim-target-helper","data-testid":"input-target-occupancy"})})]}),e.jsxs("div",{className:"rounded-lg border border-cyan-500/20 bg-cyan-500/5 px-4 py-3 flex items-start gap-3","data-testid":"badge-occupancy-boost",children:[e.jsx(Ne,{className:"w-5 h-5 text-cyan-400 shrink-0 mt-0.5 rotate-180"}),e.jsx("p",{className:"text-sm text-cyan-300/90",children:s.showroom.occupancyBoost})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(se,{label:s.showroom.inputAvgKmPerTrip,helper:s.showroom.inputAvgKmHelper,error:x("km"),htmlFor:"sim-km",children:e.jsx("input",{id:"sim-km",type:"number",min:"1",value:a,onChange:c=>O(c.target.value),onBlur:m("km"),placeholder:s.showroom.inputAvgKmPlaceholder,className:x("km")?q:H,"aria-invalid":!!x("km"),"aria-describedby":x("km")?"sim-km-error":"sim-km-helper","data-testid":"input-avg-km"})}),e.jsx(se,{label:s.showroom.inputCostPerKm,helper:s.showroom.inputCostHelper,error:x("cost"),htmlFor:"sim-cost",children:e.jsx("input",{id:"sim-cost",type:"number",min:"0",step:"0.01",value:k,onChange:c=>F(c.target.value),onBlur:m("cost"),placeholder:s.showroom.inputCostPlaceholder,className:x("cost")?q:H,"aria-invalid":!!x("cost"),"aria-describedby":x("cost")?"sim-cost-error":"sim-cost-helper","data-testid":"input-cost-per-km"})})]}),e.jsx(V,{size:"lg",className:"w-full text-lg mt-4",onClick:_,disabled:r,"data-testid":"button-calculate",children:r?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-5 h-5 mr-2 animate-spin"}),s.showroom.unlockSubmitting]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-5 h-5 mr-2"}),s.showroom.buttonCalculate]})}
2),e.jsxs("p",{className:"text-xs text-muted-foreground/70 leading-relaxed flex items-start gap-2 mt-3","data-testid":"text-lgpd-notice",children:[e.jsx(de,{className:"w-3.5 h-3.5 shrink-0 mt-0.5 text-primary/70","aria-hidden":"true"}),e.jsx("span",{children:s.showroom.lgpdNotice})]})]})]})})},"form")}function mt({results:t,show:s,onClose:u,hoursPct:d}){const{t:r,lang:o}=X();return e.jsx(ce,{children:s&&e.jsx($.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",onClick:u,children:e.jsxs($.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.3},className:"bg-background border border-border rounded-2xl shadow-2xl max-w-2xl w-full max-h-[85vh] overflow-y-auto",onClick:h=>h.stopPropagation(),role:"dialog","aria-labelledby":"details-dialog-title","aria-modal":"true","data-testid":"modal-calculation-details",children:[e.jsxs("div",{className:"sticky top-0 bg-background/95 backdrop-blur-sm border-b border-border px-6 py-4 flex items-center justify-between rounded-t-2xl z-10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(Se,{className:"w-5 h-5 text-primary"})}),e.jsx("h3",{id:"details-dialog-title",className:"text-lg font-display font-bold",children:r.showroom.detailsTitle})]}),e.jsx("button",{onClick:u,className:"w-8 h-8 rounded-lg hover:bg-muted flex items-center justify-center transition-colors","aria-label":r.showroom.detailsClose,"data-testid":"button-close-details",children:e.jsx(pe,{className:"w-5 h-5","aria-hidden":"true"})})]}),e.jsxs("div",{className:"px-6 py-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wider mb-3",children:r.showroom.detailsInputs}),e.jsxs("div",{className:"bg-muted/30 rounded-xl border border-border/50 divide-y divide-border/50",children:[e.jsx(ae,{label:r.showroom.detailsInputTrips,value:z(t.inputs.trips,o)}),e.jsx(ae,{label:r.showroom.detailsInputCurrentOcc,value:`${t.inputs.currentOcc}%`}),e.jsx(ae,{label:r.showroom.detailsInputTargetOcc,value:`${t.inputs.targetOcc}%`}),e.jsx(ae,{label:r.showroom.detailsInputKm,value:`${z(t.inputs.kmPerTrip,o)} km`,suffix:t.inputs.usedDefaultKm?r.showroom.detailsDefaultLabel:void 0}),e.jsx(ae,{label:r.showroom.detailsInputCost,value:`R$ ${Y(t.inputs.costPerKm,o)}/km`,suffix:t.inputs.usedDefaultCost?r.showroom.detailsDefaultLabel:void 0})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wider mb-3",children:r.showroom.detailsFormulas}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Q,{label:r.showroom.detailsFormulaRatio,formula:`1 - (${t.inputs.currentOcc}% ÷ ${t.inputs.targetOcc}%)`,result:`${Y((1-t.inputs.currentOcc/t.inputs.targetOcc)*100,o)}%`}),e.jsx(Q,{label:r.showroom.detailsFormulaTrips,formula:`${z(t.inputs.trips,o)} à ${Y((1-t.inputs.currentOcc/t.inputs.targetOcc)*100,o)}%`,result:`${z(t.tripsEliminated,o)}`}),e.jsx(Q,{label:r.showroom.detailsFormulaKm,formula:`${z(t.tripsEliminated,o)} à ${z(t.inputs.kmPerTrip,o)} km à ${Ee}`,result:`${z(t.kmReduction,o)} km`,note:r.showroom.consolidationNote}),e.jsx(Q,{label:r.showroom.detailsFormulaSavings,formula:`${z(t.kmReduction,o)} km à R$ ${Y(t.inputs.costPerKm,o)} à ${Re}`,result:`R$ ${z(t.savings,o)}`,note:r.showroom.costUpsizingNote}),e.jsx(Q,{label:r.showroom.detailsFormulaCo2,formula:`${z(t.kmReduction,o)} km à ${ue} à ${$e}`,result:`${Y(t.co2Reduction,o)} ton`,note:`${r.showroom.co2UpsizingNote} 3${r.showroom.detailsCo2Factor}: ${ue} ton COâ/km (${r.showroom.detailsCo2Source})`}),e.jsx(Q,{label:r.showroom.detailsFormulaHours,formula:`${z(t.inputs.trips,o)} à ${he}h = ${z(t.hoursSaved,o)}h`,result:`-${d}% ${r.showroom.hoursEfficiency}`,note:`${r.showroom.detailsHoursFactor}: ${he}h 4${r.showroom.hoursComplexityNote} 5${r.showroom.hoursFormulaExplain}: 1 â (1 â ${Y((1-t.inputs.currentOcc/t.inputs.targetOcc)*100,o)}%)² = ${d}%`})]})]}),e.jsx("div",{className:"pt-2",children:e.jsx(V,{variant:"outline",className:"w-full",onClick:u,"data-testid":"button-close-details-bottom",children:r.showroom.detailsClose})})]})]})})})}function je(t){if(t instanceof Error){const s=t.message.match(/^(\d+): (.*)$/);if(s){const u=parseInt(s[1],10);try{const d=JSON.parse(s[2]);return{status:u,message:d.message||t.message}}catch{return{status:u,message:s[2]}}}}return{status:0,message:String(t)}}function dt({results:t,show:s,onClose:u,onSent:d,runId:r,runToken:o,userInfo:h}){const{t:l,lang:p}=X(),{toast:f}
5=oe(),[b,L]=i.useState(h?.name??""),[a,O]=i.useState(h?.email??""),[k,F]=i.useState(h?.company??"");i.useEffect(()=>{h&&(L(h.name),O(h.email),F(h.company))},[h]);const[A,E]=i.useState({}),[R,P]=i.useState({}),[T,M]=i.useState(!1),[y,U]=i.useState(1),[m,x]=i.useState(""),[_,c]=i.useState(""),[D,S]=i.useState(!1),I=i.useRef(null),K=()=>{const n={};return b.trim()||(n.name=l.showroom.emailRequired),a.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)||(n.email=l.showroom.emailInvalid):n.email=l.showroom.emailRequired,k.trim()||(n.company=l.showroom.emailRequired),n},B=n=>()=>{P(C=>({...C,[n]:!0}));const g=K();E(C=>({...C,[n]:g[n]||""}))},w=n=>R[n]?A[n]:void 0;i.useEffect(()=>{if(Object.keys(R).length===0)return;const n=K();E(g=>{const C={...g};for(const Z of Object.keys(R))C[Z]=n[Z]||"";return C})},[b,a,k,R]),i.useEffect(()=>{s||(E({}),P({}),U(1),x(""),c(""))},[s]),i.useEffect(()=>{y===2&&I.current&&I.current.focus()},[y]);const v=async()=>{const n=K();if(E(n),P({name:!0,email:!0,company:!0}),!(Object.keys(n).length>0)){M(!0);try{await re("POST","/api/simulator/request-otp",{email:a.trim(),lang:p}),x(""),c(""),U(2)}catch(g){const{message:C}=je(g);f({title:C||l.showroom.otpError,variant:"destructive"})}finally{M(!1)}}},G=async()=>{if(m.length!==6){c(l.showroom.otpInvalid);return}c(""),S(!0);try{const n=await re("POST","/api/simulator/send-results",{name:b.trim(),email:a.trim(),company:k.trim(),lang:p,otp:m,inputs:t.inputs,runId:r??void 0,runToken:o??void 0});let g=null,C=!0;try{const Z=await n.json();g=Z?.shareSlug??null,C=Z?.stored!==!1}catch{}d(g),u(),f({title:C?l.showroom.emailSuccess:l.showroom.emailSentNotStored}),L(""),O(""),F(""),E({}),P({}),x(""),c(""),U(1)}catch(n){const{status:g}=je(n);g===403?c(l.showroom.otpInvalid):f({title:l.showroom.emailError,variant:"destructive"})}finally{S(!1)}},j=async()=>{x(""),c(""),M(!0);try{await re("POST","/api/simulator/request-otp",{email:a.trim(),lang:p})}catch{}finally{M(!1)}},N=T||D;return e.jsx(ce,{children:s&&e.jsx($.div,{initial:{opacity:0}
5,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",onClick:()=>!N&&u(),children:e.jsxs($.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.3},className:"bg-background border border-border rounded-2xl shadow-2xl max-w-md w-full",onClick:n=>n.stopPropagation(),role:"dialog","aria-labelledby":"email-dialog-title","aria-modal":"true","data-testid":"modal-email-form",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary/10 flex items-center justify-center",children:y===1?e.jsx(ne,{className:"w-5 h-5 text-primary"}):e.jsx(de,{className:"w-5 h-5 text-primary"})}),e.jsx("h3",{id:"email-dialog-title",className:"text-lg font-display font-bold",children:l.showroom.emailTitle})]}),e.jsx("button",{onClick:()=>!N&&u(),className:"w-8 h-8 rounded-lg hover:bg-muted flex items-center justify-center transition-colors","aria-label":p==="en"?"Close":p==="es"?"Cerrar":"Fechar","data-testid":"button-close-email",children:e.jsx(pe,{className:"w-5 h-5","aria-hidden":"true"})})]}),e.jsx("div",{className:"px-6 py-5 space-y-4",children:y===1?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:l.showroom.emailDesc}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-form-name",className:"text-sm font-medium text-foreground mb-1.5 block",children:l.showroom.emailNameLabel}),e.jsx("input",{id:"email-form-name",type:"text",value:b,onChange:n=>L(n.target.value),onBlur:B("name"),placeholder:l.showroom.emailNamePlaceholder,className:w("name")?q:H,disabled:N,"aria-invalid":!!w("name"),"aria-describedby":w("name")?"email-name-error":void 0,"data-testid":"input-email-name"}),w("name")&&e.jsx("p",{id:"email-name-error",className:"text-xs text-red-500 mt-1",role:"alert",children:w("name")})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-form-email",className:"text-sm font-medium text-foreground mb-1.5 block",children:l.showroom.emailEmailLabel}),e.jsx("input",{id:"email-form-email",type:"email",value:a,onChange:n=>O(n.target.value),onBlur:B("email"),placeholder:l.showroom.emailEmailPlaceholder,className:w("email")?q:H,disabled:N,"aria-invalid":!!w("email"),"aria-describedby":w("email")?"email-email-error":void 0,"data-testid":"input-email-email"}),w("email")?e.jsx("p",{id:"email-email-error",className:"text-xs text-red-500 mt-1",role:"alert",children:w("email")}):ke(a).show?e.jsx("p",{className:"text-xs text-amber-500 mt-1","data-testid":"warning-corporate-email-send",children:l.form.corporateEmailWarning}):null]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-form-company",className:"text-sm font-medium text-foreground mb-1.5 block",children:l.showroom.emailCompanyLabel}),e.jsx("input",{id:"email-form-company",type:"text",value:k,onChange:n=>F(n.target.value),onBlur:B("company"),placeholder:l.showroom.emailCompanyPlaceholder,className:w("company")?q:H,disabled:N,"aria-invalid":!!w("company"),"aria-describedby":w("company")?"email-company-error":void 0,"data-testid":"input-email-company"}),w("company")&&e.jsx("p",{id:"email-company-error",className:"text-xs text-red-500 mt-1",role:"alert",children:w("company")})]}),e.jsx(V,{className:"w-full",size:"lg",onClick:v,disabled:N,"data-testid":"button-send-otp",children:T?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2 animate-spin"}),l.showroom.otpSending]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),l.showroom.otpSendCode]})})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:l.showroom.otpSent.replace("{email}",a.trim())}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"otp-input",className:"text-sm font-medium text-foreground mb-1.5 block",children:l.showroom.otpLabel}),e.jsx("input",{id:"otp-input",ref:I,type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:m,onChange:n=>{const g=n.target.value.replace(/\D/g,"").slice(0,6);x(g),_&&c("")},onKeyDown:n=>{n.key==="Enter"&&m.length===6&&G()},placeholder:l.showroom.otpPlaceholder,className:`${_?q:H} text-center text-2xl tracking-[0.5em] font-mono`,disabled:N,"aria-invalid":!!_,"aria-describedby":_?"otp-error":void 0,"data-testid":"input-otp"}),_&&e.jsx("p",{id:"otp-error",className:"text-xs text-red-500 mt-1",role:"alert",children:_})]}),e.jsx(V,{className:"w-full",size:"lg",onClick:G,disabled:N||m.length!==6,"data-testid":"button-submit-email",children:D?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2 animate-spin"}),l.showroom.otpConfirming]}):e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"w-4 h-4 mr-2"}),l.showroom.otpSubmit]})}),e.jsxs("div",{className:"text-center",children:[e.jsxs("button",{onClick:()=>U(1),disabled:N,className:"text-xs text-muted-foreground hover:text-foreground underline transition-colors mr-4","data-testid":"button-back-to-form",children:["â ",p==="en"?"Back":p==="es"?"Volver":"Voltar"]}),e.jsx("button",{onClick:j,disabled:N,className:"text-xs text-muted-foreground hover:text-foreground underline transition-colors","data-testid":"button-resend-otp",children:T?e.jsx(ee,{className:"w-3 h-3 inline animate-spin"}):l.showroom.otpResend})]})]})})]})})})}function ut({show:t,onClose:s,runId:u,runToken:d,onIdentified:r}){const{t:o,lang:h}=X(),{toast:l}=oe(),[p,f]=i.useState(""),[b,L]=i.useState(""),[a,O]=i.useState(""),[k,F]=i.useState({}),[A,E]=i.useState({}),[R,P]=i.useState(!1),T=()=>{const m={};return p.trim()||(m.name=o.showroom.emailRequired),b.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(b)||(m.email=o.showroom.emailInvalid):m.email=o.showroom.emailRequired,a.trim()||(m.company=o.showroom.emailRequired),m},M=m=>()=>{E(_=>({..._,[m]:!0}));const x=T();F(_=>({..._,[m]:x[m]||""}))},y=m=>A[m]?k[m]:void 0;i.useEffect(()=>{if(Object.keys(A).length===0)return;const m=T();F(x=>{const _={...x};for(const c of Object.keys(A))_[c]=m[c]||"";return _})},[p,b,a,A]),i.useEffect(()=>{t||(F({}),E({}))},[t]);const U=async()=>{const m=T();if(F(m),E({name:!0,email:!0,company:!0}),!(Object.keys(m).length>0)){if(!u||!d){r({name:p.trim(),email:b.trim(),company:a.trim()}),s(),l({title:o.showroom.unlockSuccess});return}P(!0);try{await re("POST","/api/simulator/identify",{runId:u,runToken:d,name:p.trim(),email:b.trim(),company:a.trim(),lang:h}),r({name:p.trim(),email:b.trim(),company:a.trim()}),s(),l({title:o.showroom.unlockSuccess})}catch{l({title:o.showroom.unlockError,variant:"destructive"})}finally{P(!1)}}};return e.jsx(ce,{children:t&&e.jsx($.div,{initial:{opacity:0}
5,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",onClick:()=>!R&&s(),children:e.jsxs($.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.25},className:"bg-background border border-border rounded-2xl shadow-2xl max-w-md w-full",onClick:m=>m.stopPropagation(),role:"dialog","aria-labelledby":"unlock-dialog-title","aria-modal":"true","data-testid":"modal-unlock-form",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-border flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(J,{className:"w-5 h-5 text-primary"})}),e.jsx("h3",{id:"unlock-dialog-title",className:"text-lg font-display font-bold",children:o.showroom.unlockTitle})]}),e.jsx("button",{onClick:()=>!R&&s(),className:"w-8 h-8 rounded-lg hover:bg-muted flex items-center justify-center transition-colors","aria-label":h==="en"?"Close":h==="es"?"Cerrar":"Fechar","data-testid":"button-close-unlock",children:e.jsx(pe,{className:"w-5 h-5","aria-hidden":"true"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:o.showroom.unlockDesc}),e.jsx("ul",{className:"space-y-1.5 text-sm",children:[o.showroom.unlockBullet1,o.showroom.unlockBullet2,o.showroom.unlockBullet3].map(m=>e.jsxs("li",{className:"flex items-start gap-2 text-foreground/85",children:[e.jsx(le,{className:"w-4 h-4 text-primary shrink-0 mt-0.5","aria-hidden":"true"}),e.jsx("span",{children:m})]},m))}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"unlock-name",className:"text-sm font-medium text-foreground mb-1.5 block",children:o.showroom.emailNameLabel}),e.jsx("input",{id:"unlock-name",type:"text",value:p,onChange:m=>f(m.target.value),onBlur:M("name"),placeholder:o.showroom.emailNamePlaceholder,className:y("name")?q:H,disabled:R,"aria-invalid":!!y("name"),"data-testid":"input-unlock-name"}),y("name")&&e.jsx("p",{className:"text-xs text-red-500 mt-1",role:"alert",children:y("name")})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"unlock-email",className:"text-sm font-medium text-foreground mb-1.5 block",children:o.showroom.emailEmailLabel}),e.jsx("input",{id:"unlock-email",type:"email",value:b,onChange:m=>L(m.target.value),onBlur:M("email"),placeholder:o.showroom.emailEmailPlaceholder,className:y("email")?q:H,disabled:R,"aria-invalid":!!y("email"),"data-testid":"input-unlock-email"}),y("email")?e.jsx("p",{className:"text-xs text-red-500 mt-1",role:"alert",children:y("email")}):ke(b).show?e.jsx("p",{className:"text-xs text-amber-500 mt-1","data-testid":"warning-corporate-email-unlock",children:o.form.corporateEmailWarning}):null]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"unlock-company",className:"text-sm font-medium text-foreground mb-1.5 block",children:o.showroom.emailCompanyLabel}),e.jsx("input",{id:"unlock-company",type:"text",value:a,onChange:m=>O(m.target.value),onBlur:M("company"),placeholder:o.showroom.emailCompanyPlaceholder,className:y("company")?q:H,disabled:R,"aria-invalid":!!y("company"),"data-testid":"input-unlock-company"}),y("company")&&e.jsx("p",{className:"text-xs text-red-500 mt-1",role:"alert",children:y("company")})]}),e.jsx(V,{className:"w-full",size:"lg",onClick:U,disabled:R,"data-testid":"button-submit-unlock",children:R?e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-4 h-4 mr-2 animate-spin"}),o.showroom.unlockSubmitting]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),o.showroom.unlockCta]})}),e.jsx("p",{className:"text-xs text-muted-foreground/70 text-center",children:o.showroom.lgpdNotice})]})]})})})}const ve=Ae(.12);function ht({results:t,onReset:s,resultsRef:u,initialShareSlug:d,sharedFrom:r,onEmailSent:o,requestEmailOpen:h,runId:l,runToken:p,unlocked:f,userInfo:b,onIdentified:L}){const{t:a}=X(),{toast:O}=oe(),[k,F]=i.useState(!1),[A,E]=i.useState(!1),[R,P]=i.useState(!1),[T,M]=i.useState(!1),[y,U]=i.useState(d??null),[m,x]=i.useState(!1),_=v=>`${window.location.origin}${window.location.pathname}?sim=${encodeURIComponent(v)}`,c=async()=>
5{if(!y)return;const v=_(y);try{await navigator.clipboard.writeText(v),x(!0),te("simulation_share_copy",{page_path:window.location.pathname}),O({title:a.showroom.shareCopied}),setTimeout(()=>x(!1),2500)}catch{O({title:a.showroom.shareCopyError,variant:"destructive"})}};i.useEffect(()=>{h&&h>0&&(E(!0),M(!1))},[h]),i.useEffect(()=>{te("simulator_results_view",{trips_eliminated:t.tripsEliminated,savings:t.savings,page_path:window.location.pathname})},[t]);const{tripPct:D,kmPct:S,costPct:I,co2Pct:K,hoursPct:B}=rt(t.inputs.currentOcc,t.inputs.targetOcc),w=[{value:t.tripsEliminated,decimals:0,label:a.showroom.metricTripsLabel,unit:a.showroom.metricTripsUnit,desc:a.showroom.metricTripsDesc,color:"cyan",icon:Le,badge:`-${D}%`},{value:t.savings,decimals:0,label:a.showroom.metricSavingsLabel,unit:a.showroom.metricSavingsUnit,desc:a.showroom.metricSavingsDesc,color:"emerald",icon:Me,badge:`-${I}%`},{value:t.kmReduction,decimals:0,label:a.showroom.metricKmLabel,unit:a.showroom.metricKmUnit,desc:a.showroom.metricKmDesc,color:"violet",icon:Ne,badge:`-${S}%`},{value:t.co2Reduction,decimals:1,label:a.showroom.metricCo2Label,unit:a.showroom.metricCo2Unit,desc:a.showroom.metricCo2Desc,color:"emerald",icon:De,badge:`-${K}%`},{value:t.hoursSaved,decimals:0,label:a.showroom.metricHoursLabel,unit:a.showroom.metricHoursUnit,desc:a.showroom.metricHoursDesc,color:"amber",icon:Be,badge:`-${B}%`}];return e.jsxs(e.Fragment,{children:[e.jsxs($.div,{ref:u,initial:"hidden",animate:"visible",variants:ve,children:[e.jsxs($.div,{variants:W,className:"text-center mb-12",children:[e.jsx("h2",{className:"text-3xl md:text-4xl font-display font-bold mb-4","data-testid":"text-result-title",children:a.showroom.resultTitle}),e.jsx("p",{className:"text-lg text-muted-foreground max-w-2xl mx-auto","data-testid":"text-result-subtitle",children:a.showroom.resultSubtitle})]}),e.jsxs($.div,{variants:W,className:"mb-12",children:[e.jsx("h3",{className:"text-xl font-display font-bold text-center mb-2",children:a.showroom.comparisonTitle}),e.jsx("p",{className:"text-center text-muted-foreground text-sm mb-8",children:a.showroom.occupancyLabel}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-6 max-w-xl mx-auto",children:[e.jsxs("div",{className:"glass-panel rounded-2xl p-6 border-orange-500/20 relative overflow-hidden","data-testid":"panel-before",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-orange-500/60 to-orange-400/40 rounded-t-2xl"}),e.jsx("h4",{className:"text-sm font-display font-bold text-orange-400 mb-4 text-center",children:a.showroom.beforeTitle}),e.jsx(ye,{percentage:t.currentOccupancy,color:"red",status:a.showroom.beforeStatus,label:a.showroom.wastedLabel})]}),e.jsxs("div",{className:"glass-panel rounded-2xl p-6 border-cyan-500/20 relative overflow-hidden","data-testid":"panel-after",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-cyan-500/60 to-cyan-400/40 rounded-t-2xl"}),e.jsx("h4",{className:"text-sm font-display font-bold text-cyan-400 mb-4 text-center",children:a.showroom.afterTitle}),e.jsx(ye,{percentage:t.targetOccupancy,color:"cyan",status:a.showroom.afterStatus,label:a.showroom.optimizedLabel})]})]})]}),e.jsx($.div,{variants:ve,initial:"hidden",animate:"visible",className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 mb-8",children:w.map((v,G)=>{const j=we[v.color]||we.cyan,N=v.icon,n=!f&&G>0,g=n?{role:"button",tabIndex:0,onClick:()=>P(!0),onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),P(!0))},"aria-label":a.showroom.unlockOpenButton}:{};return e.jsxs($.div,{variants:W,className:`glass-panel rounded-2xl p-6 border ${j.border} ${j.glow} relative overflow-hidden ${n?"cursor-pointer hover:border-primary/40 transition-colors":""}`,"data-testid":`metric-card-${G}`,"data-locked":n||void 0,...g,children:[e.jsx("div",{className:`absolute top-0 left-0 right-0 h-0.5 ${j.bg}`}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:`shrink-0 w-11 h-11 rounded-xl ${j.bg} ${j.border} border flex items-center justify-center`,children:e.jsx(N,{className:`w-5 h-5 ${j.text}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5 mb-1",children:[e.jsx("span",{className:`text-3xl font-display font-bold ${j.text} ${n?"blur-md select-none":""}`,"aria-hidden":n||void 0,children:e.jsx(lt,{value:v.value,decimals:v.decimals})}),e.jsx("span",{className:`text-sm font-medium ${j.text} opacity-70 ${n?"blur-md select-none":""}`,"aria-hidden":n||void 0,children:v.unit}),!n&&"badge"in v&&v.badge&&e.jsx("span",{className:`ml-1 text-xs font-bold ${j.text} ${j.bg} ${j.border} border rounded-full px-2 py-0.5`,"data-testid":`badge-pct-${G}`,children:v.badge})]}),e.jsx("h3",{className:"text-sm font-semibold text-foreground mb-1",children:v.label}),n?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-primary/90","data-testid":`badge-locked-${G}`,children:[e.jsx(J,{className:"w-3 h-3","aria-hidden":"true"}),a.showroom.lockedBadge]}):e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:v.desc})]})]})]},G)})}),!f&&e.jsx($.div,{variants:W,className:"mb-12 max-w-2xl mx-auto",children:e.jsxs("div",{className:"rounded-2xl p-6 sm:p-7 bg-gradient-to-br from-primary/20 via-primary/10 to-cyan-500/10 border border-primary/40 shadow-lg shadow-primary/10 text-center","data-testid":"panel-unlock-cta",children:[e.jsx("div",{className:"w-11 h-11 rounded-xl bg-primary/15 border border-primary/30 flex items-center justify-center mx-auto mb-3",children:e.jsx(J,{className:"w-5 h-5 text-primary"})}),e.jsx("h3",{className:"text-xl font-display font-bold mb-2",children:a.showroom.unlockTitle}),e.jsx("p",{className:"text-sm text-muted-foreground mb-5",children:a.showroom.unlockDesc}),e.jsxs(V,{size:"lg",className:"w-full sm:w-auto text-base px-8",onClick:()=>P(!0),"data-testid":"button-open-unlock",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),a.showroom.unlockOpenButton]})]})}),e.jsxs($.div,{variants:W,children:[e.jsx("p",{className:"text-xs text-muted-foreground
5/60 text-center italic mb-3","data-testid":"text-disclaimer",children:a.showroom.disclaimer}),e.jsx("div",{className:"text-center mb-12",children:e.jsxs("button",{onClick:()=>f?F(!0):P(!0),className:"inline-flex items-center gap-1.5 text-sm text-primary hover:text-primary/80 transition-colors font-medium","data-testid":"button-view-details","data-locked":!f||void 0,"aria-label":f?a.showroom.detailsLink:a.showroom.unlockOpenButton,children:[f?e.jsx(Se,{className:"w-4 h-4"}):e.jsx(J,{className:"w-4 h-4"}),f?a.showroom.detailsLink:a.showroom.lockedBadge]})})]}),e.jsxs($.div,{variants:W,className:"flex flex-col items-center justify-center gap-4",children:[!r&&f&&e.jsxs("div",{className:"rounded-xl p-5 max-w-md w-full text-center bg-gradient-to-br from-primary/20 via-primary/10 to-cyan-500/10 border border-primary/40 shadow-lg shadow-primary/10",children:[e.jsx(ne,{className:"w-6 h-6 text-primary mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-white/90 mb-3",children:a.showroom.emailDesc}),e.jsxs(V,{size:"lg",className:"w-full text-base bg-primary hover:bg-primary/90 shadow-md shadow-primary/25",onClick:()=>{E(!0),M(!1)},disabled:T,"data-testid":"button-email-results",children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),T?a.showroom.emailSuccess:a.showroom.emailButton]}),y&&e.jsxs(V,{type:"button",size:"lg",variant:"outline",className:"w-full mt-3 text-sm border-primary/40 text-primary hover:bg-primary/10",onClick:c,"data-testid":"button-copy-share-link",children:[m?e.jsx(le,{className:"w-4 h-4 mr-2"}):e.jsx(ge,{className:"w-4 h-4 mr-2"}),m?a.showroom.shareCopied:a.showroom.shareCopyButton]})]}),r&&y&&e.jsxs("div",{className:"rounded-xl p-4 max-w-md w-full text-center bg-gradient-to-br from-primary/15 to-cyan-500/10 border border-primary/30",children:[e.jsx(Ze,{className:"w-5 h-5 text-primary mx-auto mb-2"}),e.jsxs(V,{type:"button",size:"lg",variant:"outline",className:"w-full text-sm border-primary/40 text-primary hover:bg-primary/10",onClick:c,"data-testid":"button-copy-share-link",children:[m?e.jsx(le,{className:"w-4 h-4 mr-2"}):e.jsx(ge,{className:"w-4 h-4 mr-2"}),m?a.showroom.shareCopied:a.showroom.shareCopyButton]})]}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(V,{size:"lg",variant:"outline",className:"text-lg px-8",onClick:s,"data-testid":"button-reset",children:[e.jsx(Ye,{className:"w-4 h-4 mr-2"}),r?a.showroom.shareTryYourOwn:a.showroom.buttonReset]})})]})]},"results"),e.jsx(mt,{results:t,show:k,onClose:()=>F(!1),hoursPct:B}),e.jsx(dt,{results:t,show:A,onClose:()=>E(!1),runId:l,runToken:p,userInfo:b,onSent:v=>{M(!0),v&&U(v),o?.(v)}}),e.jsx(ut,{show:R,onClose:()=>P(!1),runId:l,runToken:p,onIdentified:v=>{L(v)}})]})}function pt({current:t,onStepClick:s,enabledSteps:u}){const{t:d}=X(),r=[d.showroom.stepper.step1,d.showroom.stepper.step2,d.showroom.stepper.step3],o=h=>u?u[h]!==!1:!0;return e.jsxs("nav",{"aria-label":d.showroom.stepper.ariaLabel,className:"mb-10",children:[e.jsx("ol",{className:"flex items-center justify-center gap-2 sm:gap-4 max-w-2xl mx-auto","data-testid":"simulator-stepper",children:r.map((h,l)=>{const p=l+1,f=p===t,b=p<t,L=b?"complete":f?"current":"pending",a=!!s&&o(p),O=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`shrink-0 w-8 h-8 rounded-full border-2 flex items-center justify-center text-xs font-bold transition-colors ${b?"bg-primary border-primary text-primary-foreground":f?"border-primary text-primary bg-primary/10":"border-border text-muted-foreground bg-background"}`,"aria-hidden":"true",children:b?e.jsx(le,{className:"w-4 h-4"}):p}),e.jsxs("span",{className:`text-xs sm:text-sm font-medium truncate ${f?"text-foreground":b?"text-foreground/80":"text-muted-foreground"}`,children:[e.jsxs("span",{className:"sm:hidden",children:[p,"/",r.length]}),e.jsx("span",{className:"hidden sm:inline",children:h})]})]});return e.jsxs("li",{className:"flex items-center gap-2 sm:gap-4 flex-1 min-w-0",children:[a?e.jsx("button",{type:"button",onClick:()=>s(p),className:"flex items-center gap-2 min-w-0 rounded-md px-1 py-0.5 hover-elevate active-elevate-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","aria-current":f?"step":void 0,"data-state":L,"data-testid":`stepper-item-${p}`,children:O}):e.jsx("div",{className:"flex items-center gap-2 min-w-0 px-1 py-0.5 opacity-70","aria-current":f?"step":void 0,"aria-disabled":"true","data-state":L,"data-testid":`stepper-item-${p}`,children:O}),l<r.length-1&&e.jsx("span",{className:`hidden sm:block flex-1 h-px ${b?"bg-primary/60":"bg-border"}`,"aria-hidden":"true"})]},p)})}),e.jsx("p",{className:"sr-only","aria-live":"polite",children:d.showroom.stepper.liveAnnounce.replace("{current}",String(t)).replace("{total}",String(r.length))})]})}function Et(){const{t,lang:s}=X(),{toast:u}=oe(),[d,r]=i.useState(null),[o,h]=i.useState(null),[l,p]=i.useState(null),[f,b]=i.useState(!1),[L,a]=i.useState(null),[O,k]=i.useState(null),[F,A]=i.useState(null),[E,R]=i.useState(!1),[P,T]=i.useState(!1),[M,y]=i.useState(0),[U,m]=i.useState(1),x=i.useRef(null),_=i.useRef(null),D=Math.max(P?3:d?2:1,U);i.useEffect(()=>{if(typeof window>"u"||!("IntersectionObserver"in window))return;const N=[{el:_.current,step:1},{el:x.current,step:d?2:1}].filter(C=>!!C.el);if(N.length===0)return;const n=new Map,g=new IntersectionObserver(C=>{for(const ie of C)n.set(ie.target,ie.intersectionRatio);let Z=1,me=0;for(const{el:ie,step:Fe}of N){const be=n.get(ie)??0;be>me&&(me=be,Z=Fe)}me>0&&m(P&&Z===2?3:Z)},{threshold:[0,.25,.5,.75,1]});
5return N.forEach(({el:C})=>g.observe(C)),()=>g.disconnect()},[d,P]);const S=j=>{if(j===1){d?w():_.current?.scrollIntoView({behavior:"smooth",block:"start"});return}if(j===2){d&&x.current?.scrollIntoView({behavior:"smooth",block:"start"});return}j===3&&d&&(x.current?.scrollIntoView({behavior:"smooth",block:"start"}),y(N=>N+1))},[I,K]=i.useState(()=>typeof window<"u"?window.location.search:"");i.useEffect(()=>{const j=()=>K(window.location.search);return window.addEventListener("popstate",j),()=>window.removeEventListener("popstate",j)},[]),i.useEffect(()=>{const N=new URLSearchParams(I).get("sim");if(!N||!/^[A-Za-z0-9_-]{1,32}$/.test(N)||N===O&&d)return;let n=!1;return R(!0),fetch(`/api/simulations/by-slug/${encodeURIComponent(N)}`).then(async g=>{if(!g.ok)throw new Error(String(g.status));return g.json()}).then(g=>{if(n)return;const C={tripsEliminated:g.results.tripsEliminated,savings:g.results.savings,kmReduction:g.results.kmReduction,co2Reduction:g.results.co2Reduction,hoursSaved:g.results.hoursSaved,currentOccupancy:g.inputs.currentOcc,targetOccupancy:g.inputs.targetOcc,inputs:g.inputs};r(C),h(null),p(null),b(!0),k(N),A({name:g.name,company:g.company}),te("simulation_shared_open",{page_path:window.location.pathname}),setTimeout(()=>x.current?.scrollIntoView({behavior:"smooth",block:"start"}),120)}).catch(()=>{n||u({title:t.showroom.shareLoadError,variant:"destructive"})}).finally(()=>{n||R(!1)}),()=>{n=!0}},[I]);const B=(j,N,n)=>{r(j),h(N),p(n),b(!1),a(null),k(null),A(null),T(!1),setTimeout(()=>{x.current?.scrollIntoView({behavior:"smooth",block:"start"})},100)},w=()=>{r(null),h(null),p(null),b(!1),a(null),k(null),A(null),T(!1),window.location.search&&window.history.replaceState(null,"",window.location.pathname),window.scrollTo({top:0,behavior:"smooth"})},v=j=>{a(j),b(!0)},G=j=>{j&&k(j),T(!0)};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground overflow-hidden",children:[e.jsx(Ke,{}),e.jsxs("main",{id:"main-content",children:[e.jsxs("section",{"aria-labelledby":"showroom-title",className:"relative pt-32 pb-16 overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top,hsla(var(--primary)/0.08)_0%,transparent_60%)] pointer-events-none"}),e.jsx("div",{className:"absolute inset-0 pointer-events-none overflow-hidden","aria-hidden":"true",children:e.jsx("img",{src:Qe,alt:"",className:"absolute right-0 top-1/2 -translate-y-1/2 w-[75%] max-w-[900px] h-auto object-cover opacity-[0.38] hidden md:block",style:{maskImage:"linear-gradient(to left, rgba(0,0,0,0.6) 10%, rgba(0,0,0,0.2) 60%, transparent 100%)",WebkitMaskImage:"linear-gradient(to left, rgba(0,0,0,0.6) 10%, rgba(0,0,0,0.2) 60%, transparent 100%)"}})}),e.jsx("div",{className:"max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10",children:e.jsxs($.div,{initial:"hidden",animate:"visible",variants:W,children:[e.jsxs("a",{href:Ue(s),className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-primary transition-colors mb-8","data-testid":"link-back-home",children:[e.jsx(Xe,{className:"w-4 h-4"}),t.showroom.backHome]}),e.jsx("h1",{id:"showroom-title",className:"text-4xl md:text-5xl font-display font-bold leading-tight mb-6","data-testid":"text-showroom-title",children:t.showroom.heroTitle}),e.jsx("p",{className:"text-xl text-muted-foreground leading-relaxed max-w-3xl","data-testid":"text-showroom-subtitle",children:t.showroom.heroSubtitle})]})})]}),e.jsxs("section",{"aria-label":t.showroom.formTitle,className:"pt-10 pb-24 relative border-t border-primary/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-primary/[0.03] via-primary/[0.06] to-transparent pointer-events-none"}),e.jsxs("div",{ref:_,className:"max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10",children:[e.jsx(pt,{current:D,onStepClick:S,enabledSteps:{1:!0,2:!!d,3:!!d}}),F&&e.jsx("div",{className:"mb-8 rounded-xl border border-primary/40 bg-primary/10 px-5 py-4 text-sm","data-testid":"banner-shared-view",children:e.jsx("p",{className:"text-foreground/90",children:t.showroom.shareViewBanner.replace("{name}",F.name).replace("{company}",F.company)})}),E&&!d&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-12 text-muted-foreground","data-testid":"status-loading-shared",children:[e.jsx(ee,{className:"w-4 h-4 animate-spin"})," ",t.showroom.shareLoading]}),e.jsx(ce,{mode:"wait",children:d?e.jsx(ht,{results:d,onReset:w,resultsRef:x,initialShareSlug:O,sharedFrom:F,onEmailSent:G,requestEmailOpen:M,runId:o,runToken:l,unlocked:f||!!F,userInfo:L,onIdentified:v}):!E&&e.jsx(ct,{onResults:B})})]})]}),e.jsx(ze,{hideSimulatorCta:!0}),e.jsx("section",{className:"py-16 border-t border-primary/20",children:e.jsx("div",{className:"max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 text-center",children:e.jsxs($.div,{initial:"hidden",
5whileInView:"visible",viewport:{once:!0},variants:W,children:[e.jsx("p",{className:"text-muted-foreground mb-6",children:t.clientsPage.ctaSubtitle}),e.jsx(V,{size:"lg",className:"text-lg px-8",onClick:()=>{te("cta_click",{cta_name:"simulator_bottom_cta",page_path:window.location.pathname}),window.location.href=He(s,"contact")},"data-testid":"button-cta-demo-bottom",children:t.clientsPage.ctaButton})]})})}),e.jsx(Ve,{title:t.pageFaqs.simulator.title,titleHighlight:t.pageFaqs.simulator.titleHighlight,items:t.pageFaqs.simulator.items,testIdPrefix:"simulator-faq"})]}),e.jsx(qe,{})]})}export{Et as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.