1import{k as l,j as t}from"./vendor-Dfxs0MA2.js";import{u as ee,s as k,t as s}from"./index-CIKckvOq.js";import{d as te,u as se,s as ae,o as oe}from"./SellerConsole-DjgxrZyx.js";function le({sellerFirstName:H,onClose:S}){var $,A,D;ee();const J=te(),Q=se(),[c,w]=l.useState(!0),[n,U]=l.useState([]),[z,_]=l.useState(null),[I,G]=l.useState(!0),[r,L]=l.useState(new Set),[f,T]=l.useState(!1),[F,C]=l.useState(null);l.useEffect(()=>{(async()=>{if(!k){w(!1),_(s("apptRescue.sessionUnavailable"));return}try{const{data:e,error:d}=await k.functions.invoke("appt-rescue-scan",{body:{}});if(d||!(e!=null&&e.ok)){w(!1),_(s("apptRescue.scanFailed"));return}const a=e.candidates||[];U(a),L(new Set(a.map(p=>p.lead_id)))}catch{_(s("apptRescue.scanFailed"))}finally{w(!1)}})()},[]);const K=e=>L(d=>{const a=new Set(d);return a.has(e)?a.delete(e):a.add(e),a}),M=`Hola {nombre}, soy ${H}. Me dijiste que querÃas pasar a ver el carro y quiero apartarte el espacio para que no te toque esperar. ¿A qué hora te viene bien? Dime el dÃa y la hora y te lo dejo listo.`,P=`Hi {nombre}, it's ${H}. You mentioned you wanted to come see the car and I'd like to hold the spot for you so you don't have to wait. What time works for you? Just let me know the day and time and I'll set it up.`,O=((($=n[0])==null?void 0:$.language)==="en"?P:M).replace(/\{nombre\}/g,(((A=n[0])==null?void 0:A.name)||"").split(" ")[0]||(((D=n[0])==null?void 0:D.language)==="en"?"there":"")),W=n.filter(e=>e.in_cooldown&&r.has(e.lead_id)).length;async function V(){if(!(!k||f||r.size===0)){T(!0),C(null);try{const e=n.filter(u=>r.has(u.lead_id)),d=new Map;for(const u of e){const h=u.language==="en"?"en":"es";(d.get(h)||d.set(h,[]).get(h)).push(u)}let a=0,p=0,B=0,m=0,x=0,E=0,g=0,N=!1;const b=[];let q=0;e:for(const[u,h]of d){const X=u==="en"?P:M;for(let v=0;v<h.length;v+=400){const R=h.slice(v,v+400),{data:Z,error:Y}=await k.functions.invoke("ai-send-bulk-sms",{body:{lead_ids:R.map(j=>j.lead_id),template:X,personalize:I,channel:"sms",ai_initiated:!0}});if(Y){const j=await ae(Y);if(b.push(j.message),j.noCredits){g+=e.length-q;break e}p+=R.length,q+=R.length;continue}const o=Z||{};o.channel_configured===!1&&(N=!0),a+=o.sent??0,p+=o.failed??0,m+=o.quiet_hours_blocked??0,B+=o.blocked??0,x+=o.cooldown_skipped??0,E+=o.invalid??0,q+=R.length,o.error&&b.push(o.error)}}const i=[];a&&i.push(s("apptRescue.rSent",{count:a})),x&&i.push(s("apptRescue.rCooldown",{count:x})),B&&i.push(s("apptRescue.rBlocked",{count:B})),m&&i.push(s("apptRescue.rQuiet",{count:m})),E&&i.push(s("apptRescue.rBadNum",{count:E})),p&&i.push(s("apptRescue.rFailed",{count:p})),g&&i.push(s("apptRescue.rNoCredits",{count:g}));let y=i.join(" · ")||s("apptRescue.rNothing");N&&(y=s("apptRescue.testMode")+" "+y),C(y+(b.length?` â ${b[0]}`:"")),J.push(a&&!N?"success":x||m?"info":"error",y),g&&oe(Q,g)}catch(e){C(s("apptRescue.rError",{msg:e instanceof Error?e.message:s("apptRescue.rSendFailed")}))}finally{T(!1)}}}return t.jsx("div",{className:"mask",onClick:S,children:t.jsxs("div",{className:"modal-card",style:{maxWidth:580},onClick:e=>e.stopPropagation(),children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:8,alignItems:"center"},children:[t.jsxs("h2",{className:"modal-h",style:{marginBottom:0},children:["â° ",s("apptRescue.title")]}),t.jsx("button",{onClick:S,style:{background:"transparent",border:"none",color:"var(--text-tertiary)",fontSize:22,cursor:"pointer"},children:"Ã"})]}),t.jsxs("p",{className:"modal-sub",children:[s("apptRescue.subtitlePre")," ",t.jsx("strong",{children:s("apptRescue.subtitleHours")})," ",s("apptRescue.subtitlePost")]}),t.jsxs("div",{style:{padding:"12px 14px",background:"var(--tint-1)",border:"1px solid var(--border-subtle)",borderRadius:10,marginBottom:12},children:[t.jsx("div",{style:{fontSize:13,color:"var(--text-secondary)"},children:c?s("apptRescue.scanning"):s("apptRescue.readyToResume")}),t.jsx("div",{style:{fontSize:26,fontWeight:700,color:"var(--primary)"},children:c?"â¦":r.size}),t.jsxs("div",{style:{fontSize:11.5,color:"var(--text-tertiary)"},children:[s("apptRescue.eligibleHint"),W?` · ${s("apptRescue.cooldownSuffix",{count:W})}`:""]})]}),z&&t.jsx("div",{style:{padding:"8px 12px",background:"var(--tint-1)",borderRadius:8,fontSize:12.5,marginBottom:12},children:z}),!c&&!z&&n.length===0&&t.jsx("div",{style:{padding:"14px",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:10,fontSize:13,color:"var(--text-secondary)",marginBottom:12},children:s("apptRescue.emptyState")}),n.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:6},children:s("apptRescue.reviewHint")}),t.jsx("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border-subtle)",borderRadius:10,marginBottom:12},children:n.map(e=>t.jsxs("label",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"8px 10px",borderBottom:"1px solid var(--border-subtle)",cursor:"pointer",fontSize:12.5},children:[t.jsx("input",{type:"checkbox",checked:r.has(e.lead_id),onChange:()=>K(e.lead_id),style:{marginTop:2}}),t.jsxs("span",{style:{flex:1},children:[t.jsx("span",{style:{fontWeight:600},children:e.name||s("apptRescue.customerFallback")}),e.vehicle?t.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[" · ",e.vehicle]}):null,t.jsxs("span",{style:{display:"block",color:e.snippet_flag==="red"?"#b45309":"var(--text-secondary)",marginTop:2},title:e.snippet_flag==="red"?s("apptRescue.ambiguousTitle"):void 0,children:["â",e.snippet,"â",e.snippet_flag==="red"?" â ï¸":""]})]})]},e.lead_id))}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer",marginBottom:12},children:[t.jsx("input",{type:"checkbox",checked:I,onChange:e=>G(e.target.checked)}),t.jsx("span",{children:s("apptRescue.personalizeLabel")})]}),t.jsx("div",{style:{fontSize:12,color:"var(--text-tertiary)",marginBottom:6},children:s("apptRescue.exampleLabel")}),t.jsx("div",{style:{padding:"10px 12px",background:"var(--bg-elevated)",border:"1px solid var(--border-subtle)",borderRadius:10,fontSize:12.5,lineHeight:1.5,marginBottom:14,whiteSpace:"pre-wrap"},children:O})]}),F&&t.jsx("div",{style:{padding:"8px 12px",background:"var(--tint-1)",borderRadius:8,fontSize:12.5,marginBottom:12},children:F}),t.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[t.jsx("button",{className:"cta-ghost cta-sm",onClick:S,children:s("apptRescue.close")}),t.jsx("button",{className:"cta-btn",disabled:c||f||r.size===0,onClick:V,style:{opacity:c||f||r.size===0?.55:1},children:f?s("apptRescue.sending"):s("apptRescue.sendTo",{count:c?0:r.size})})]})]})})}export{le 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.