PageSourceSearch

https://vagle.ai/assets/FollowUpTemplateWizard-x6BjXIhD.js

js vagle.ai collected 2026-10-05 13:13:14 UTC 51,493 bytes, 335 lines download raw bytes

1import{j as e,d as B,a as z,f as Ys}from"./index-CbtKD9GF.js";import{b as l,d as Js}from"./vendor-gmoby7Lc.js";import{g as Ks,T as Xs,L as Qs,C as Le,aI as Zs,aj as M,p as et,M as st,_ as tt,W as Ae,Z as us}from"./icons-BYq1EogD.js";const at=`
2  .ftw-backdrop {
3    position: fixed; inset: 0; z-index: 10000;
4    background: rgba(8, 12, 22, 0.54);
5    backdrop-filter: blur(18px) saturate(120%);
6    -webkit-backdrop-filter: blur(18px) saturate(120%);
7    display: flex; align-items: flex-start; justify-content: center;
8    padding: 24px;
9    overflow-y: auto;
10    overscroll-behavior: contain;
11  }
12  .ftw-shell {
13    background: rgba(255,255,255,.96);
14    border: 1px solid rgba(255,255,255,.72);
15    border-radius: 28px;
16    width: 100%;
17    max-width: 920px;
18    max-height: calc(100vh - 48px);
19    display: flex; flex-direction: column;
20    box-shadow: 0 38px 120px rgba(8,12,22,.34), inset 0 1px 0 rgba(255,255,255,.8);
21    overflow: hidden;
22    margin: auto 0;
23    min-height: 0;
24    font-family: Inter, ui-sans-serif, system-ui, sans-serif;
25    animation: ftw-in 180ms ease-out;
26  }
27  @keyframes ftw-in { from { opacity: 0; transform: translateY(10px) scale(.985); } }
28  .ftw-head {
29    padding: 18px 22px;
30    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
31    display: flex; align-items: center; justify-content: space-between;
32    background: #FAFBFC;
33  }
34  .ftw-head h2 { margin: 0; font-size: 1.08rem; font-weight: 800; }
35  .ftw-head .ftw-step-pill {
36    background: #F97316; color: #FFFFFF;
37    font-size: 0.72rem; font-weight: 700;
38    padding: 4px 10px; border-radius: 999px;
39    text-transform: uppercase; letter-spacing: 0.06em;
40  }
41  .ftw-head button.close {
42    background: transparent; border: 0; color: #475569;
43    cursor: pointer; padding: 6px; border-radius: 8px;
44  }
45  .ftw-head button.close:hover { background: rgba(15, 23, 42, 0.08); }
46  .ftw-progress {
47    height: 4px; background: rgba(15, 23, 42, 0.06);
48    width: 100%; overflow: hidden;
49  }
50  .ftw-progress > div {
51    height: 100%; background: #F97316;
52    transition: width 240ms ease;
53  }
54  .ftw-body {
55    padding: 22px 26px;
56    overflow-y: auto;
57    overscroll-behavior: contain;
58    touch-action: pan-y;
59    flex: 1;
60    min-height: 0;
61  }
62  .ftw-body h3 {
63    margin: 0 0 6px 0; font-size: 1rem; font-weight: 800;
64  }
65  .ftw-body .ftw-sub {
66    margin: 0 0 18px 0; color: #64748B; font-size: 0.86rem;
67  }
68  .ftw-foot {
69    padding: 14px 22px;
70    border-top: 1px solid rgba(15, 23, 42, 0.06);
71    background: #FAFBFC;
72    display: flex; justify-content: space-between; align-items: center;
73  }
74  .ftw-card-grid {
75    display: grid; grid-template-columns: 1fr 1fr;
76    gap: 10px;
77  }
78  @media (max-width: 720px) { .ftw-card-grid { grid-template-columns: 1fr; } }
79  .ftw-tcard {
80    border: 1px solid rgba(15, 23, 42, 0.10);
81    background: #FFFFFF;
82    border-radius: 12px;
83    padding: 14px 16px;
84    cursor: pointer;
85    text-align: left;
86    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
87  }
88  .ftw-tcard:hover { background: #FAFBFC; }
89  .ftw-tcard.is-selected {
90    border-color: #F97316;
91    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.14);
92  }
93  .ftw-tcard .ftw-tcard-head {
94    display: flex; align-items: center; gap: 8px;
95    margin-bottom: 6px;
96  }
97  .ftw-tcard .ftw-tcard-head .icon {
98    font-size: 1.25rem;
99  }
100  .ftw-tcard h4 {
101    margin: 0; font-size: 0.95rem; font-weight: 700;
102  }
103  .ftw-tcard p {
104    margin: 0; color: #64748B; font-size: 0.8rem;
105    line-height: 1.45;
106  }
107  .ftw-tcard .ftw-chips {
108    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px;
109  }
110  .ftw-tcard .ftw-chip {
111    font-size: 0.68rem; font-weight: 700;
112    padding: 3px 7px; border-radius: 999px;
113    background: rgba(249, 115, 22, 0.12); color: #C2410C;
114    text-transform: uppercase; letter-spacing: 0.04em;
115  }
116  .ftw-tcard .ftw-chip.muted {
117    background: rgba(15, 23, 42, 0.06); color: #475569;
118  }
119
120  .ftw-tabs {
121    display: flex; gap: 4px;
122    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
123    margin-bottom: 16px;
124  }
125  .ftw-tab {
126    background: transparent; border: 0;
127    padding: 10px 14px;
128    font-size: 0.86rem; font-weight: 700;
129    color: #64748B; cursor: pointer;
130    border-bottom: 2px solid transparent;
131    margin-bottom: -1px;
132  }
133  .ftw-tab:hover { color: #111111; }
134  .ftw-tab.active { color: #F97316; border-bottom-color: #F97316; }
135  .ftw-tab.disabled { color: #CBD5E1;
135 cursor: not-allowed; }
136
137  .ftw-skip-card {
138    display: flex;
139    align-items: center;
140    justify-content: space-between;
141    gap: 12px;
142    margin: 0 0 16px;
143    padding: 12px 14px;
144    border: 1px solid rgba(15, 23, 42, 0.08);
145    border-radius: 12px;
146    background: #F8FAFC;
147  }
148  .ftw-skip-card strong {
149    display: block;
150    margin-bottom: 2px;
151    color: #111827;
152    font-size: 0.86rem;
153  }
154  .ftw-skip-card span {
155    color: #64748B;
156    font-size: 0.8rem;
157    line-height: 1.35;
158  }
159  .ftw-skip-card button {
160    flex: 0 0 auto;
161    border: 1px solid rgba(15, 23, 42, 0.12);
162    border-radius: 999px;
163    background: #FFFFFF;
164    color: #111827;
165    padding: 8px 12px;
166    font-size: 0.78rem;
167    font-weight: 800;
168    cursor: pointer;
169  }
170  .ftw-skip-card button:hover { background: #F1F5F9; }
171  @media (max-width: 640px) {
172    .ftw-skip-card { align-items: flex-start; flex-direction: column; }
173  }
174
175  .ftw-drop {
176    border: 2px dashed rgba(15, 23, 42, 0.15);
177    border-radius: 12px;
178    padding: 28px;
179    text-align: center;
180    background: #FAFBFC;
181    transition: border-color 120ms ease, background 120ms ease;
182  }
183  .ftw-drop.is-drag { border-color: #F97316; background: #FFF7ED; }
184  .ftw-drop input[type=file] { display: none; }
185  .ftw-drop button.pick {
186    background: #FFFFFF; border: 1px solid rgba(15, 23, 42, 0.12);
187    border-radius: 10px; padding: 8px 14px;
188    font-weight: 700; font-size: 0.86rem; cursor: pointer;
189  }
190  .ftw-drop button.pick:hover { background: #F1F5F9; }
191
192  .ftw-table {
193    width: 100%; border-collapse: collapse;
194    margin-top: 14px;
195    font-size: 0.84rem;
196  }
197  .ftw-table thead th {
198    text-align: left; padding: 8px 10px;
199    background: #F8FAFC;
200    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
201    font-weight: 700; color: #475569;
202    text-transform: uppercase; font-size: 0.7rem;
203    letter-spacing: 0.05em;
204  }
205  .ftw-table tbody td {
206    padding: 8px 10px;
207    border-bottom: 1px solid rgba(15, 23, 42, 0.05);
208    vertical-align: top;
209  }
210
211  .ftw-row {
212    display: grid; grid-template-columns: 1fr 1fr;
213    gap: 12px;
214  }
215  @media (max-width: 720px) { .ftw-row { grid-template-columns: 1fr; } }
216  .ftw-field { display: flex; flex-direction: column; gap: 6px; }
217  .ftw-field label {
218    font-size: 0.78rem; font-weight: 700; color: #334155;
219  }
220  .ftw-field input, .ftw-field select, .ftw-field textarea {
221    width: 100%; padding: 10px 12px;
222    border: 1px solid rgba(15, 23, 42, 0.12);
223    border-radius: 8px;
224    font-size: 0.9rem;
225    background: #FFFFFF; color: #111111;
226    font-family: inherit;
227  }
228  .ftw-field input:focus, .ftw-field select:focus, .ftw-field textarea:focus {
229    outline: none; border-color: #F97316;
230    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.18);
231  }
232
233  .ftw-day-row {
234    display: flex; flex-wrap: wrap; gap: 6px;
235  }
236  .ftw-day-chip {
237    background: #FFFFFF;
238    border: 1px solid rgba(15, 23, 42, 0.12);
239    border-radius: 999px;
240    padding: 6px 12px; font-size: 0.82rem; font-weight: 700;
241    cursor: pointer; user-select: none;
242    color: #475569;
243  }
244  .ftw-day-chip.active {
245    background: #F97316; border-color: #F97316; color: #FFFFFF;
246  }
247
248  .ftw-summary-card {
249    background: #FAFBFC; border: 1px solid rgba(15, 23, 42, 0.06);
250    border-radius: 12px; padding: 14px 16px;
251    margin-bottom: 12px;
252  }
253  .ftw-summary-card h4 {
254    margin: 0 0 8px 0; font-size: 0.82rem;
255    text-transform: uppercase; letter-spacing: 0.06em;
256    color: #475569; font-weight: 700;
257  }
258  .ftw-summary-card .row {
259    display: flex; justify-content: space-between;
260    padding: 4px 0; font-size: 0.88rem;
261  }
262  .ftw-summary-card .row span:first-child { color: #64748B; }
263  .ftw-summary-card .row span:last-child {
264    color: #111111; font-weight: 600; text-align: right;
265  }
266
267  .ftw-banner {
268    border-radius: 10px; padding: 12px 14px;
269    margin-bottom: 14px; font-size: 0.86rem;
270    display: flex; align-items: flex-start; gap: 8px;
271  }
272  .ftw-banner.error {
273    background: #FFF1F2; color: #B91C1C;
274    border: 1px solid rgba(220, 38, 38, 0.28);
275  }
276  .ftw-banner.warn {
277    background: #FFF7ED; color: #9A3412;
278    border: 1px solid rgba(249, 115, 22, 0.35);
279  }
280  .ftw-banner.info {
281    background: #EFF6FF; color: #1D4ED8;
282    border: 1px solid rgba(59, 130, 246, 0.28);
283  }
284  .ftw-inline-actions {
285    display: flex; flex-wrap: wrap; gap: 8px;
286    align-items: center;
287  }
288  .ftw-inline-actions input {
289    flex: 1 1 220px;
290    min-width: 0;
291  }
292  .ftw-inline-actions .fuf-btn {
293    white-space: nowrap;
294  }
295  .ftw-guide {
296    border: 1px solid rgba(15, 23, 42, 0.08);
297    background: #F8FAFC;
298    border-radius: 10px;
299    padding: 12px 14px;
300    margin-bottom: 12px;
301    color: #475569;
302    font-size: 0.84rem;
303    line-height: 1.5;
304  }
305  .ftw-guide strong { color: #111827; }
306  .ftw-manual-lead {
307    border: 1px solid rgba(15, 23, 42, 0.08);
308    border-radius: 12px;
309    padding: 14px;
310    margin-bottom: 12px;
311    background: #FFFFFF;
312  }
313  .ftw-manual-lead-head {
314    display: flex;
315    justify-content: space-between;
316    gap: 10px;
317    align-items: flex-start;
318    margin-bottom: 10px;
319  }
320  .ftw-manual-lead-head strong {
321    color: #111827;
322    font-size: 0.9rem;
323  }
324  .ftw-manual-lead-head span {
325    color: #64748B;
326    font-size: 0.78rem;
327  }
328  .ftw-manual-grid {
329    display: grid;
330    grid-template-columns: 1fr 1fr;
331    gap: 10px;
332  }
333  @media (max-width: 720px) { .ftw-manual-grid { grid-template-columns: 1fr; } }
334`,Te=[{id:1,label:"Template"},{id:2,label:"Assistant"},{id:3,label:"Leads"},{id:4,label:"Mapping"},{id:5,label:"Schedule"},{id:6,label:"Review"}],nt=["mon","tue","wed","thu","fri","sat","sun"],ps={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},ms=["phone","phone_number","phonenumber","mobile","contact","number"],fs=["name","full_name","first_name","lead_name","customer"],xs=["email","email_address","mail"],gs=["Name","Phone","Email","Notes"],hs=[{id:"missed_call_recovery",t
334itle:"Missed Call Recovery",icon:"📞",description:"Re-engage callers you missed. Same-day recovery → Day 1 → Day 3.",flow:["Recover","Retry","Book"],saveFieldCount:7},{id:"real_estate_site_visit",title:"Real Estate Site Visit",icon:"🏠",description:"Move property leads from inquiry → site visit → booking across 4 calls.",flow:["Qualify","Schedule","Recover"],saveFieldCount:8},{id:"clinic_appointment",title:"Clinic Appointment",icon:"🏥",description:"Confirm patient interest, book the right doctor, follow up gently.",flow:["Confirm","Book","Remind"],saveFieldCount:8}];function G(i){const n=(i||[]).map(t=>String(t||"").toLowerCase().trim()),r=t=>{for(const o of t){const f=n.findIndex(m=>m===o||m.includes(o));if(f!==-1)return i[f]}return""};return{phone:r(ms),name:r(fs),email:r(xs)}}function rt(i){if(i==null)return"";let n=String(i).replace(/\D/g,"");return n?n.length===11&&n.startsWith("1")?`+${n}`:n.length===10?`+1${n}`:n.length>10?`+${n}`:"":""}function Ye(i){return typeof i=="string"&&/^\+[1-9]\d{7,14}$/.test(i)}function lt(i){return(i?.sheets||i?.tabs||i?.spreadsheet?.sheets||[]).map(r=>({sheetId:r.sheetId,title:String(r.title||r.name||"").trim(),index:Number.isFinite(Number(r.index))?Number(r.index):0})).filter(r=>r.title).sort((r,t)=>r.index-t.index)}function Ee(i,n,r){const t=(i||[]).map(o=>String(o||"").toLowerCase().trim());for(const o of n){const f=t.findIndex(m=>m===o||m.includes(o));if(f!==-1)return i[f]}return i.includes(r)?r:""}function it(i,n){const r=Array.isArray(i)&&i.filter(Boolean).length>0?i.filter(Boolean):gs,t=Ee(r,fs,"Name"),o=Ee(r,ms,"Phone"),f=Ee(r,xs,"Email"),m=Ee(r,["notes","note","requirement","summary","details"],"Notes"),a={};return r.forEach(h=>{a[h]=""}),a[t||"Name"]=n.Name||"",a[o||"Phone"]=n.Phone||"",a[f||"Email"]=n.Email||"",a[m||"Notes"]=n.Notes||"",{columns:r,row:a}}function ot(i){const n=[...gs];(i?.saveFields||[]).forEach(t=>{const o=String(t?.label||t?.key||"").trim();o&&n.push(o)});const r=new Set;return n.filter(t=>{const o=String(t||"").trim().toLowerCase();return!o||r.has(o)?!1:(r.add(o),!0)})}function jt({onClose:i,onCreated:n,initialTemplateId:r=null}){const[t,o]=l.useState(1),[f,m]=l.useState(hs),[a,h]=l.useState(!1),[v,C]=l.useState(r||null),g=l.useRef(!1),[D,E]=l.useState([]),[F,I]=l.useState(""),[j,T]=l.useState("auto"),[w,U]=l.useState([]),[L,ce]=l.useState(""),[ee,Pe]=l.useState(""),[y,De]=l.useState("csv"),[he,Ie]=l.useState(null),[O,Y]=l.useState([]),[we,se]=l.useState([]),[te,ue]=l.useState([]),[R,pe]=l.useState(!1),[be,je]=l.useState(!1),[N,ve]=l.useState(""),[ye,J]=l.useState([]),[k,me]=l.useState(""),[Re,$]=l.useState([]),[A,W]=l.useState(""),[K,Ne]=l.useState("Leads"),[ae,V]=l.useState([]),[q,d]=l.useState([]),[S,ne]=l.useState(!1),[ws,Ke]=l.useState(!1),[bs,Xe]=l.useState(!1),[js,re]=l.useState(!1),[vs,P]=l.useState(null),[ys,le]=l.useState(""),[Be,Qe]=l.useState({Name:"",Phone:"",Email:"",Notes:""}),[ze,Ns]=l.useState(""),[Ze,es]=l.useState(["Name","Phone","Email","Notes"]),[ss,Se]=l.useState([]),[Ss,Cs]=l.useState({Name:"",Phone:"",Email:"",Notes:""}),[Fs,ts]=l.useState(!1),[ks,_e]=l.useState(null),[H,X]=l.useState({phone:"",name:"",email:""}),[fe,Ts]=l.useState("10:30"),[as,Es]=l.useState(!0),[xe,As]=l.useState(["mon","tue","wed","thu","fri"]),[Me,Ls]=l.useState("10:00"),[$e,Ps]=l.useState("18:00"),[We,Ds]=l.useState(1),[He,Is]=l.useState(30),[Ue,Rs]=l.useState(50),[Q,ns]=l.useState(!1),[Bs,rs]=l.useState(null),zs=l.useRef(null),ls=l.useRef(null);l.useEffect(()=>{let s=!1;async function u(){m(hs),h(!1);try{const b=await(await B.authedFetch(z.getApiUrl("/api/follow-up/templates"))).json().catch(()=>({}));!s&&b?.success&&Array.isArray(b.templates)&&b.templates.length>0&&m(b.templates)}catch{}}async function p(){try{const b=await(await B.authedFetch(z.getApiUrl("/api/assistants"))).json().catch(()=>({}));!s&&b?.success&&E(b.assistants||[])}catch{}}async function x(){try{const b=await(await B.authedFetch(z.getApiUrl("/api/tools"))).json().catch(()=>({}));!s&&b?.success&&U(b.tools||[])}catch{}}return u(),p(),x(),()=>{s=!0}},[]),l.useEffect(()=>{g.current||r&&f.some(s=>s.id===r)&&(g.current=!0,C(r),o(s=>s===1?2:s))},[f,r]);const Z=l.useMemo(()=>f.find(s=>
334s.id===v)||null,[f,v]),ie=l.useMemo(()=>ot(Z),[Z]);l.useEffect(()=>{Z&&!L&&ce(Z.title)},[Z?.id]);async function _s(s){if(s){Ie(s),pe(!0),ue([]);try{const u=await s.text(),p=dt(u);Y(p.headers),se(p.rows),X(G(p.headers))}catch(u){ue([u.message||"Could not parse CSV"]),Y([]),se([])}finally{pe(!1)}}}const Ms=l.useMemo(()=>w.filter(s=>["google_sheets","google_sheets_lead"].includes(s.type)),[w]);function Oe(s,u){return s?.message||s?.details?.message||s?.error||u}async function is(s){if(s){P(null),ne(!0);try{const u=await B.authedFetch(z.getApiUrl(`/api/tools/${s}/google-sheets/spreadsheets`)),p=await u.json().catch(()=>({}));if(!u.ok||!p.success)throw new Error(Oe(p,"Could not list spreadsheets"));J(p.spreadsheets||p.items||[])}catch(u){P(u.message||"Could not list spreadsheets"),J([])}finally{ne(!1)}}}async function Ce(s,u){if(!(!s||!u)){P(null),Xe(!0);try{const p=await B.authedFetch(z.getApiUrl(`/api/tools/${s}/google-sheets/spreadsheets/${encodeURIComponent(u)}/sheets`)),x=await p.json().catch(()=>({}));if(!p.ok||!x.success)throw new Error(Oe(x,"Could not list sheet tabs"));const c=lt(x);$(c),!A&&c.length===1&&(W(c[0].title),await oe(s,u,c[0].title))}catch(p){P(p.message||"Could not list sheet tabs"),$([])}finally{Xe(!1)}}}async function oe(s,u,p){if(!(!u||!p)){Ke(!0),P(null);try{const x=new URLSearchParams({toolId:s||"",spreadsheetId:u,sheetName:p,limit:"500"}),c=await B.authedFetch(z.getApiUrl(`/api/follow-up/lead-sources/google-sheets/preview?${x.toString()}`)),b=await c.json().catch(()=>({}));if(!c.ok||!b.success)throw new Error(Oe(b,"Could not read sheet"));V(b.headers||[]),d(b.rows||[]),X(G(b.headers||[]))}catch(x){P(x.message||"Could not read sheet"),V([]),d([])}finally{Ke(!1)}}}async function $s(){if(!k||!A)return;const s=String(Be.Phone||"").trim();if(!s){P("Phone is required before adding a lead.");return}const{columns:u,row:p}=it(ae,{...Be,Phone:s});re(!0),P(null),le("");try{const x=await B.authedFetch(z.getApiUrl(`/api/tools/google/spreadsheets/${encodeURIComponent(k)}/sheets/${encodeURIComponent(A)}/rows`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({columns:u,rows:[p],ensureHeaders:ae.length===0})}),c=await x.json().catch(()=>({}));if(!x.ok||!c.success)throw new Error(c.message||c.error||"Could not add lead");Qe({Name:"",Phone:"",Email:"",Notes:""}),le("Lead added to this sheet tab. The preview below has been refreshed."),await oe(N,k,A)}catch(x){P(x.message||"Could not add lead")}finally{re(!1)}}async function Ws(){if(!k)return;const s=String(K||"Leads").trim().slice(0,80)||"Leads";re(!0),P(null),le("");try{const u=await B.authedFetch(z.getApiUrl(`/api/tools/google/spreadsheets/${encodeURIComponent(k)}/sheets`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sheetName:s,columns:ie})}),p=await u.json().catch(()=>({}));if(!u.ok||!p.success)throw new Error(p.message||p.error||"Could not create sheet tab");const x=p.sheet?.sheetName||s;W(x),$(c=>c.some(b=>b.title===x)?c:[...c,{title:x,sheetId:p.sheet?.sheetId||x}]),V(ie),d([]),X(G(ie)),le(`Created "${x}" with the required header row. Add a lead here to continue.`),Promise.allSettled([Ce(N,k),oe(N,k,x)])}catch(u){P(u.message||"Could not create sheet tab")}finally{re(!1)}}async function Hs(){if(!N)return;const s=`${ee.trim()||L.trim()||"Vagle AI"} Follow-up Leads`,u=String(K||"Leads").trim().slice(0,80)||"Leads";re(!0),P(null),le("");try{const p=await B.authedFetch(z.getApiUrl("/api/tools/google/spreadsheets"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:s,sheetName:u,columns:ie})}),x=await p.json().catch(()=>({}));if(!p.ok||!x.success)throw new Error(x.message||x.error||"Could not create spreadsheet");const c=x.spreadsheet||{};if(!c.spreadsheetId)throw new Error("Spreadsheet was created but no ID was returned");const b=c.sheetName||u;me(c.spreadsheetId),W(b),J(qe=>qe.some(Gs=>Gs.id===c.spreadsheetId)?qe:[{id:c.spreadsheetId,name:c.title||s,url:c.url},...qe]),$([{title:b,sheetId:b}]),V(ie),d([]),X(G(ie)),le(`Created "${c.title||s}" with the required header row. Add a lead here to continue.`),Promise.allSettled([is(N),Ce(N,c.spreadsheetId),oe(N,c.spreadsheetId,b)])}catch(p){P(p.message||"Could not create spreadsheet")}finally{re(!1)}}async function os(s,u=ze){if(!(!s||!u)){ts(!0),_e(null);try{const p=new URLSearchParams({toolId:u,limit:"500"}),x=await B.authedFetch(z.getApiUrl(`/api/follow-up/lead-sources/${s}/preview?${p.toString()}`)),c=await x.json().catch(()=>({}));if(!x.ok||!c.success)throw new Error(c.error||`Could not read ${s} records`);const b=Array.isArray(c.headers)&&c.headers.length?c.headers:["Name","Phone","Email","Notes"];es(b),Se(Array.isArray(c.rows)?c.rows:[]),X(G(b))}catch(p){_e(p.message||`Could not read ${s} records`),Se([])}finally{ts(!1)}}}const de=y==="csv"?O:y==="sheets"?ae:Ze,_=y==="csv"?we:y==="sheets"?q:ss,Fe=y==="sheets"?"google_sheets":y==="airtable"?"airtable":y==="notion"?"notion":null,Ve=y==="sheets"?N:ze,Us=l.useMemo(()=>Ge(de,_,H).slice(0,5),[de,_,H]),ge=l.useMemo(()=>Ge(de,_,H).filter(s=>Ye(s.phone)).length,[de,_,H]),ds=l.useMemo(()=>{switch(t){case 1:return!!v;case 2:return j==="auto"||!!F;case 3:return Fe?!!Ve&&_.length>0:_.length>0;case 4:return!!H.phone&&ge>0;case 5:return/^\d{2}:\d{2}$/.test(fe)&&xe.length>0;case 6:return!0;default:return!1}},[t,v,F,j,_.length,H.phone,ge,fe,xe.length,Fe,Ve]);async function Os(){if(!Q){ns(!0),rs(null);try{const s=Ge(de,_,H).filter(b=>Ye(b.phone)),p={assistantId:j==="existing"?F:void 0,assistantSetup:{mode:j,assistantId:j==="existing"?F:void 0},funnelName:L,sourceType:y==="sheets"?"google_sheets":y==="airtable"?"airtable":y==="notion"?"notion":"csv",leads:s,fieldMapping:H,scheduleOverrides:{callWindowStart:Me,callWindowEnd:$e,allowedDays:xe,maxConcurrentCalls:Number(We)||1,secondsBetweenCalls:Number(He)||30,dailyCallLimit:Number(Ue)||50,businessHoursOnly:as},firstCallTime:fe,businessName:ee.trim()};Fe&&(p.externalSyncTool={toolId:Ve,destinationType:Fe,spreadsheetId:y==="sheets"?k:void 0,sheetName:y==="sheets"?A:void 0});const x=await B.authedFetch(z.getApiUrl(`/api/follow-up/templates/${v}/start`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)}),c=await x.json().catch(()=>({}));if(!x.ok||!c.success)throw new Error(c.error||"Could not start funnel");n?.(c.funnel)}catch(s){rs(s.message||"Could not start funnel")}finally{ns(!1)}}}const Vs=t/Te.length*100,qs=s=>{const u=ls.current;if(!u||u.scrollHeight<=u.clientHeight)return;const p=u.scrollTop;u.scrollTop+=s.deltaY,u.scrollTop!==p&&(s.preventDefault(),s.stopPropagation())},cs=!!(t>1||v||he||_.length||L||ee);async function ke(){Q||cs&&!await Ys({title:"Leave guided setup?",message:"Your current setup choices have not been used to create a journey yet.",confirmLabel:"Discard setup",cancelLabel:"Keep going",kind:"warning"})||i()}return l.useEffect(()=>{const s=u=>{u.key==="Escape"&&ke()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[cs,Q]),typeof document>"u"?null:Js.createPortal(e.jsxs("div",{className:"ftw-backdrop",onMouseDown:ke,role:"presentation",children:[e.jsx("style",{children:at}),e.jsxs("div",{className:"ftw-shell",role:"dialog","aria-modal":"true","aria-labelledby":"ftw-title",onMouseDown:s=>s.stopPropagation(),onWheelCapture:qs,children:[e.jsxs("div",{className:"ftw-head",children:[e.jsx("h2",{id:"ftw-title",children:"Guided follow-up setup"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsxs("span",{className:"ftw-step-pill",children:["Step ",t," of ",Te.length," — ",Te[t-1].label]}),e.jsx("button",{type:"button",className:"close",onClick:ke,"aria-label":"Close",children:e.jsx(Ks,{size:18})})]})]}),e.jsx("div",{className:"ftw-progress",children:e.jsx("div",{style:{width:`${Vs}%`}})}),e.jsxs("div",{className:"ftw-body",ref:ls,children:[t===1&&e.jsx(ct,{templates:f,loading:a,templateId:v,setTemplateId:C}),t===2&&e.jsx(ht,{assistants:D,assistantId:F,setAssistantId:I,assistantSetupMode:j,setAssistantSetupMode:T,template:Z,funnelName:L,setFunnelName:ce,businessName:ee,setBusinessName:Pe}),t===3&&e.jsx(ut,{leadSourceTab:y,setLeadSourceTab:De,csvFile:he,csvHeaders:O,csvRows:we,csvErrors:te,csvLoading:R,dragOver:be,
334setDragOver:je,fileInputRef:zs,handleCsvFile:_s,sheetsTools:Ms,sheetsToolId:N,setSheetsToolId:s=>{ve(s),J([]),me(""),$([]),W(""),V([]),d([]),s&&is(s)},sheetSpreadsheetsLoading:S,sheetSpreadsheets:ye,sheetSpreadsheetId:k,setSheetSpreadsheetId:s=>{me(s),$([]),W(""),V([]),d([]),N&&s&&Ce(N,s)},sheetTabs:Re,sheetTabsLoading:bs,sheetName:A,setSheetName:s=>{W(s),k&&s&&oe(N,k,s)},sheetTabDraftName:K,setSheetTabDraftName:Ne,createSheetTab:Ws,createSpreadsheet:Hs,refreshSheetTabs:async()=>{await Ce(N,k),k&&A&&await oe(N,k,A)},sheetLeadDraft:Be,setSheetLeadDraft:Qe,addSheetLead:$s,sheetsHeaders:ae,sheetsRows:q,sheetsLoading:ws,sheetsActionLoading:js,sheetsActionMessage:ys,sheetsError:vs,tools:w,externalToolId:ze,setExternalToolId:s=>{Ns(s),Se([]),_e(null),es(["Name","Phone","Email","Notes"]),(y==="airtable"||y==="notion")&&s&&os(y,s)},externalRows:ss,setExternalRows:Se,externalHeaders:Ze,externalLoading:Fs,externalError:ks,loadExternalPreview:os,externalLeadDraft:Ss,setExternalLeadDraft:Cs,setMapping:X}),t===4&&e.jsx(mt,{headers:de,previewLeads:Us,mapping:H,setMapping:X,totalValidLeads:ge,totalRows:_.length}),t===5&&e.jsx(ft,{firstCallTime:fe,setFirstCallTime:Ts,businessHoursOnly:as,setBusinessHoursOnly:Es,allowedDays:xe,setAllowedDays:As,callWindowStart:Me,setCallWindowStart:Ls,callWindowEnd:$e,setCallWindowEnd:Ps,maxConcurrentCalls:We,setMaxConcurrentCalls:Ds,secondsBetweenCalls:He,setSecondsBetweenCalls:Is,dailyCallLimit:Ue,setDailyCallLimit:Rs}),t===6&&e.jsx(xt,{template:Z,funnelName:L,assistantSetupMode:j,assistant:j==="existing"?D.find(s=>(s.id||s._id)===F):null,source:y==="csv"?`CSV (${he?.name||"uploaded"})`:y==="sheets"?`Google Sheets (${A})`:y==="airtable"?"Airtable records":"Notion database",totalValidLeads:ge,firstCallTime:fe,allowedDays:xe,callWindowStart:Me,callWindowEnd:$e,maxConcurrentCalls:We,secondsBetweenCalls:He,dailyCallLimit:Ue,submitError:Bs})]}),e.jsxs("div",{className:"ftw-foot",children:[e.jsx("button",{type:"button",className:"fuf-btn subtle",onClick:ke,disabled:Q,children:"Cancel"}),e.jsxs("div",{style:{display:"flex",gap:8},children:[t>1&&e.jsxs("button",{type:"button",className:"fuf-btn",onClick:()=>o(t-1),disabled:Q,children:[e.jsx(Xs,{})," Back"]}),t<Te.length?e.jsxs("button",{type:"button",className:"fuf-btn primary",onClick:()=>o(t+1),disabled:!ds,children:["Next ",e.jsx(Qs,{})]}):e.jsx("button",{type:"button",className:"fuf-btn primary",onClick:Os,disabled:Q||!ds||ge===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(Le,{style:{animation:"spin 1s linear infinite"}})," Starting…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Zs,{})," Create and Start Funnel"]})})]})]})]})]}),document.body)}function dt(i){const n=[];let r=[],t="",o=!1;for(let a=0;a<i.length;a++){const h=i[a];o?h==='"'&&i[a+1]==='"'?(t+='"',a++):h==='"'?o=!1:t+=h:h==='"'?o=!0:h===","?(r.push(t),t=""):h===`
335`?(r.push(t),n.push(r),r=[],t=""):h==="\r"||(t+=h)}if((t.length>0||r.length>0)&&(r.push(t),n.push(r)),n.length===0)throw new Error("Empty CSV");const f=n[0].map(a=>String(a||"").trim()),m=n.slice(1).filter(a=>a.some(h=>String(h||"").trim()!==""));return{headers:f,rows:m.map((a,h)=>({values:a,rowNumber:h+2}))}}function Ge(i,n,r){if(!Array.isArray(i)||!Array.isArray(n))return[];const t=a=>i.indexOf(a),o=t(r.phone),f=t(r.name),m=t(r.email);return n.map(a=>{const h=a.values||[],v={};return i.forEach((C,g)=>{C&&g!==o&&g!==f&&g!==m&&(v[C]=h[g]||"")}),{phone:o>=0?rt(h[o]):"",name:f>=0?String(h[f]||""):"",email:m>=0?String(h[m]||""):"",customFields:v,rowNumber:a.rowNumber,externalRecordId:a.externalRecordId||a.recordId||a.pageId||void 0,recordId:a.recordId||a.externalRecordId||void 0,pageId:a.pageId||a.externalRecordId||void 0}})}function ct({templates:i,loading:n,templateId:r,setTemplateId:t}){return n?e.jsxs("div",{style:{color:"#64748B"},children:[e.jsx(Le,{style:{animation:"spin 1s linear infinite"}})," Loading templates…"]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Choose a template"}),e.jsx("p",{className:"ftw-sub",children:"Pick the playbook closest to your use case. You can edit the funnel after."}),e.jsx("div",{className:"ftw-card-grid",children:i.map(o=>
335e.jsxs("button",{type:"button",className:`ftw-tcard ${r===o.id?"is-selected":""}`,onClick:()=>t(o.id),children:[e.jsxs("div",{className:"ftw-tcard-head",children:[e.jsx("span",{className:"icon",children:o.icon||"📋"}),e.jsx("h4",{children:o.title})]}),e.jsx("p",{children:o.description}),e.jsxs("div",{className:"ftw-chips",children:[(o.flow||[]).slice(0,6).map((f,m)=>e.jsx("span",{className:"ftw-chip",children:f},m)),e.jsxs("span",{className:"ftw-chip muted",children:[o.saveFieldCount," fields saved"]})]})]},o.id))})]})}function ht({assistants:i,assistantId:n,setAssistantId:r,assistantSetupMode:t,setAssistantSetupMode:o,template:f,funnelName:m,setFunnelName:a,businessName:h,setBusinessName:v}){const C=`${f?.title||"Template"} Follow-up Assistant`;return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Assistant setup"}),e.jsx("p",{className:"ftw-sub",children:"Create a follow-up assistant from this template, or link one you already use."}),e.jsxs("div",{className:"ftw-card-grid",style:{marginBottom:14},children:[e.jsxs("button",{type:"button",className:`ftw-tcard ${t==="auto"?"is-selected":""}`,onClick:()=>o("auto"),children:[e.jsxs("div",{className:"ftw-tcard-head",children:[e.jsx("span",{className:"icon",children:"★"}),e.jsx("h4",{children:"Create ready follow-up assistant"})]}),e.jsx("p",{children:"Creates an assistant in your Assistants page and links it to this funnel with follow-up memory, outcome routing, and template instructions."}),e.jsxs("div",{className:"ftw-chips",children:[e.jsx("span",{className:"ftw-chip",children:"Short context memory"}),e.jsx("span",{className:"ftw-chip",children:"Lead fields"}),e.jsx("span",{className:"ftw-chip",children:"Call outcome capture"})]})]}),e.jsxs("button",{type:"button",className:`ftw-tcard ${t==="existing"?"is-selected":""}`,onClick:()=>o("existing"),children:[e.jsxs("div",{className:"ftw-tcard-head",children:[e.jsx("span",{className:"icon",children:"↗"}),e.jsx("h4",{children:"Use existing assistant"})]}),e.jsx("p",{children:"Use your own assistant if it already has the right voice, prompt, tools, and follow-up behavior configured."}),e.jsx("div",{className:"ftw-chips",children:e.jsxs("span",{className:"ftw-chip muted",children:[i.length," available"]})})]})]}),t==="auto"?e.jsxs("div",{className:"ftw-summary-card",children:[e.jsx("h4",{children:"Assistant preview"}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:C})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"LLM"}),e.jsx("span",{children:"Llama 3.3 70B"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Transcriber"}),e.jsx("span",{children:"Deepgram nova-2"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Voice"}),e.jsx("span",{children:"MiniMax professional voice"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Memory"}),e.jsx("span",{children:"Uses previous summary, lead fields, current step, and saved outcomes"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Prompt"}),e.jsx("span",{children:"Template-specific follow-up prompt with opt-out and human handoff handling"})]})]}):e.jsxs(e.Fragment,{children:[i.length===0?e.jsxs("div",{className:"ftw-banner warn",children:[e.jsx(M,{}),e.jsx("span",{children:"You do not have any assistants yet. Choose the recommended option to create one automatically."})]}):null,e.jsxs("div",{className:"ftw-field",style:{marginBottom:12},children:[e.jsx("label",{children:"Assistant"}),e.jsxs("select",{value:n,onChange:g=>r(g.target.value),children:[e.jsx("option",{value:"",children:"Pick an assistant…"}),i.map(g=>e.jsx("option",{value:g.id||g._id,children:g.name},g.id||g._id))]})]})]}),e.jsx("div",{className:"ftw-row",children:e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Funnel name"}),e.jsx("input",{type:"text",value:m,onChange:g=>a(g.target.value),placeholder:"e.g., Spring promo follow-up"})]})}),e.jsxs("div",{className:"ftw-field",style:{marginTop:12},children:[e.jsx("label",{children:"Business name (optional)"}),e.jsx("input",{type:"text",value:h,onChange:g=>v(g.target.value),placeholder:"Used in the lead-source label and review summary"})]})]})}function ut(i){const{leadSourceTab:n,setLeadSourceTab:r,csvFile:t,csvHeaders:o,csvRows:f,csvErrors:m,csvLoading:a,dragOver:h,setDragOver:v,fileInputRef:C,handleCsvFile:g,sheetsTools:D,sheetsToolId:E,setSheetsToolId:F,sheetSpreadsheetsLoading:I,sheetSpreadsheets:j,sheetSpreadsheetId:T,setSheetSpreadsheetId:w,sheetTabs:U,sheetTabsLoading:L,sheetName:ce,setSheetName:ee,sheetTabDraftName:Pe,setSheetTabDraftName:y,createSheetTab:De,createSpreadsheet:he,refreshSheetTabs:Ie,sheetLeadDraft:O,setSheetLeadDraft:Y,addSheetLead:we,sheetsHeaders:se,sheetsRows:te,sheetsLoading:ue,sheetsActionLoading:R,sheetsActionMessage:pe,sheetsError:be,tools:je,externalToolId:N,setExternalToolId:ve,externalRows:ye,setExternalRows:J,externalHeaders:k,externalLoading:me,externalError:Re,loadExternalPreview:$,externalLeadDraft:A,setExternalLeadDraft:W,setMapping:K}=i,Ne=d=>{const S=d==="airtable"?["airtable","airtable_lead"]:["notion","notion_lead"];return(je||[]).filter(ne=>S.includes(ne.type))},ae=(je||[]).find(d=>d.id===N),V=()=>{const d=String(A.Phone||"").trim();d&&(J(S=>[...S,{values:[A.Name||"",d,A.Email||"",A.Notes||""],rowNumber:S.length+2}]),W({Name:"",Phone:"",Email:"",Notes:""}),K(G(k)))},q=d=>{if(r(d),d==="airtable"||d==="notion"){const S=Ne(d);if(N&&!S.some(ne=>ne.id===N)){ve(""),J([]),K(G(k));return}K(G(k)),N&&ye.length===0&&$?.(d,N)}};return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Where are your leads coming from?"}),e.jsx("p",{className:"ftw-sub",children:"Choose or add lead rows here. External sources must use a connected Tool Workspace destination."}),e.jsxs("div",{className:"ftw-tabs",children:[e.jsxs("button",{type:"button",className:`ftw-tab ${n==="csv"?"active":""}`,onClick:()=>q("csv"),children:[e.jsx(et,{style:{marginRight:6,verticalAlign:"-2px"}})," Upload CSV"]}),e.jsxs("button",{type:"button",className:`ftw-tab ${n==="sheets"?"active":""}`,onClick:()=>q("sheets"),children:[e.jsx(st,{style:{marginRight:6,verticalAlign:"-2px"}})," Google Sheets"]}),e.jsx("button",{type:"button",className:`ftw-tab ${n==="airtable"?"active":""}`,onClick:()=>q("airtable"),children:"Airtable"}),e.jsx("button",{type:"button",className:`ftw-tab ${n==="notion"?"active":""}`,onClick:()=>q("notion"),children:"Notion"})]}),e.jsxs("div",{className:"ftw-skip-card",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Add tools later"}),e.jsx("span",{children:"Start with CSV or manual lead upload now. You can connect Google Sheets, Airtable, Notion, or webhooks later from Tool Workspace."})]}),n!=="csv"&&e.jsx("button",{type:"button",onClick:()=>q("csv"),children:"Use CSV for now"})]}),n==="csv"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`ftw-drop ${h?"is-drag":""}`,onDragOver:d=>{d.preventDefault(),v(!0)},onDragLeave:()=>v(!1),onDrop:d=>{d.preventDefault(),v(!1);const S=d.dataTransfer.files?.[0];S&&g(S)},children:[e.jsx("div",{style:{marginBottom:10},children:e.jsx(tt,{size:28,color:"#F97316"})}),e.jsx("div",{style:{marginBottom:6,fontWeight:700},children:t?t.name:"Drop a CSV here"}),e.jsxs("div",{style:{color:"#64748B",fontSize:"0.84rem",marginBottom:12},children:["Required column: ",e.jsx("strong",{children:"phone"}),". Other columns become custom fields."]}),e.jsx("input",{ref:C,type:"file",accept:".csv",onChange:d=>{const S=d.target.files?.[0];S&&g(S)}}),e.jsx("button",{type:"button",className:"pick",onClick:()=>C.current?.click(),children:t?"Pick another file":"Choose CSV file"})]}),a&&e.jsx("div",{style:{marginTop:12,color:"#64748B"},children:"Parsing…"}),m.length>0&&e.jsxs("div",{className:"ftw-banner error",style:{marginTop:12},children:[e.jsx(M,{}),e.jsx("span",{children:m[0]})]}),o.length>0&&f.length>0&&e.jsx(Je,{headers:o,rows:f.slice(0,5),totalRows:f.length})]}),n==="sheets"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ftw-guide",children:[e.jsx("strong",{children:"Use this step in either direction:"})," select an existing sheet tab to import leads, or add a lead directly below and Vagle will write it into the selected Google Sheet for you. A valid phone number is required before the funnel can continue."]}),D.length===0?e.jsxs("div",{className:"ftw-banner warn",children:[e.jsx(M,{}),e.jsx("span",{children:"No Google Sheets tools yet. Create a Google Sheets tool first in Tool Workspace, then return here."})]}):e.jsxs("div",{className:"ftw-row",style:{marginBottom:12},children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Connected tool"}),e.jsxs("select",{value:E,onChange:d=>F(d.target.value),children:[e.jsx("option",{value:"",children:"Pick a Google Sheets tool…"}),D.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Spreadsheet"}),e.jsxs("select",{value:T,onChange:d=>w(d.target.value),disabled:!E||I,children:[e.jsx("option",{value:"",children:I?"Loading spreadsheets…":"Pick a spreadsheet…"}),j.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]})]}),E&&!I&&j.length===0&&e.jsxs("div",{className:"ftw-banner info",children:[e.jsx(M,{}),e.jsx("span",{children:"No spreadsheets were returned. Create one here with starter columns, or refresh after creating one in Google Sheets."})]}),E&&e.jsxs("div",{className:"ftw-field",style:{marginBottom:12},children:[e.jsx("label",{children:T?"Create a sheet tab":"Create a spreadsheet"}),e.jsxs("div",{className:"ftw-inline-actions",children:[e.jsx("input",{type:"text",value:Pe,onChange:d=>y(d.target.value),placeholder:"Leads",disabled:R}),T?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"fuf-btn",onClick:Ie,disabled:L||R,children:[e.jsx(Le,{})," Refresh tabs"]}),e.jsxs("button",{type:"button",className:"fuf-btn primary",onClick:De,disabled:R,children:[e.jsx(Ae,{})," Create tab"]})]}):e.jsxs("button",{type:"button",className:"fuf-btn primary",onClick:he,disabled:R,children:[e.jsx(Ae,{})," Create spreadsheet"]})]})]}),T&&e.jsxs("div",{className:"ftw-field",style:{marginBottom:12},children:[e.jsx("label",{children:"Sheet tab"}),e.jsxs("select",{value:ce,onChange:d=>
335ee(d.target.value),disabled:L,children:[e.jsx("option",{value:"",children:"Pick a tab…"}),U.map(d=>e.jsx("option",{value:d.title,children:d.title},d.sheetId||d.title))]}),L?e.jsx("small",{style:{color:"#64748B"},children:"Loading tabs…"}):null]}),T&&ce&&e.jsxs("div",{className:"ftw-manual-lead",children:[e.jsx("div",{className:"ftw-manual-lead-head",children:e.jsxs("div",{children:[e.jsx("strong",{children:"Add lead here"}),e.jsx("span",{children:" This writes a new row to the selected tab and refreshes the preview."})]})}),e.jsxs("div",{className:"ftw-manual-grid",children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Name"}),e.jsx("input",{type:"text",value:O.Name,onChange:d=>Y(S=>({...S,Name:d.target.value})),placeholder:"Customer name",disabled:R})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsxs("label",{children:["Phone ",e.jsx("span",{style:{color:"#DC2626"},children:"*"})]}),e.jsx("input",{type:"tel",value:O.Phone,onChange:d=>Y(S=>({...S,Phone:d.target.value})),placeholder:"+919876543210",disabled:R})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Email"}),e.jsx("input",{type:"email",value:O.Email,onChange:d=>Y(S=>({...S,Email:d.target.value})),placeholder:"[email protected]",disabled:R})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Notes"}),e.jsx("input",{type:"text",value:O.Notes,onChange:d=>Y(S=>({...S,Notes:d.target.value})),placeholder:"Requirement or context",disabled:R})]})]}),e.jsxs("div",{className:"ftw-inline-actions",style:{marginTop:10,justifyContent:"space-between"},children:[e.jsx("small",{style:{color:"#64748B"},children:"Tip: use country code for best calling accuracy. Example: +91 or +1."}),e.jsxs("button",{type:"button",className:"fuf-btn primary",onClick:we,disabled:R||!O.Phone.trim(),children:[e.jsx(Ae,{})," Add lead"]})]})]}),T&&!L&&U.length===0&&e.jsxs("div",{className:"ftw-banner warn",children:[e.jsx(M,{}),e.jsx("span",{children:"No sheet tabs were returned for this spreadsheet. Create a tab above, then add leads here or refresh."})]}),ue&&e.jsx("div",{style:{color:"#64748B"},children:"Reading sheet…"}),pe&&e.jsxs("div",{className:"ftw-banner info",children:[e.jsx(us,{}),e.jsx("span",{children:pe})]}),be&&e.jsxs("div",{className:"ftw-banner error",children:[e.jsx(M,{}),e.jsx("span",{children:be})]}),se.length>0&&te.length>0&&e.jsx(Je,{headers:se,rows:te.slice(0,5),totalRows:te.length}),se.length>0&&te.length===0&&!ue&&e.jsxs("div",{className:"ftw-banner warn",children:[e.jsx(M,{}),e.jsx("span",{children:"This tab has headers but no lead rows yet. Add one directly above or paste rows in Google Sheets, then refresh the preview."})]})]}),(n==="airtable"||n==="notion")&&e.jsx(pt,{kind:n,tools:Ne(n),toolId:N,setToolId:ve,selectedTool:ae,headers:k,rows:ye,loading:me,error:Re,loadPreview:()=>$?.(n,N),draft:A,setDraft:W,addLead:V})]})}function pt({kind:i,tools:n,toolId:r,setToolId:t,selectedTool:o,headers:f,rows:m,loading:a,error:h,loadPreview:v,draft:C,setDraft:g,addLead:D}){const E=i==="airtable"?"Airtable":"Notion",F=o?.config||{},I=i==="airtable"?[F.baseName||F.baseId,F.tableName||F.tableId].filter(Boolean).join(" / "):F.databaseName||F.databaseId||"";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ftw-guide",children:[e.jsxs("strong",{children:[E," sync is mandatory:"]})," pick a configured Tool Workspace tool. Vagle will save short follow-up context back through that tool after every call."]}),n.length===0?e.jsxs("div",{className:"ftw-banner warn",children:[e.jsx(M,{}),e.jsxs("span",{children:["No ",E," lead tools found. Create and configure one in Tool Workspace first."]})]}):e.jsxs("div",{className:"ftw-row",style:{marginBottom:12},children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Connected tool"}),e.jsxs("select",{value:r,onChange:j=>t(j.target.value),children:[e.jsxs("option",{value:"",children:["Pick a ",E," tool…"]}),n.map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:i==="airtable"?"Base / table":"Database"}),e.jsx("input",{type:"text",value:I||"Configure destination in Tool Workspace",readOnly:!0})]})]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ftw-inline-actions",style:{marginBottom:12,justifyContent:"space-between"},children:[e.jsxs("small",{style:{color:"#64748B"},children:["Load existing rows from ",E,", or add a quick test lead below."]}),e.jsxs("button",{type:"button",className:"fuf-btn",onClick:v,disabled:a,children:[e.jsx(Le,{style:a?{animation:"spin 1s linear infinite"}:void 0}),a?"Loading records...":"Load records"]})]}),h&&e.jsxs("div",{className:"ftw-banner error",children:[e.jsx(M,{}),e.jsx("span",{children:h})]}),e.jsxs("div",{className:"ftw-manual-lead",children:[e.jsx("div",{className:"ftw-manual-lead-head",children:e.jsxs("div",{children:[e.jsx("strong",{children:"Add lead here"}
335),e.jsxs("span",{children:[" These rows start the funnel; after calls, short memory syncs to ",E," through the selected tool."]})]})}),e.jsxs("div",{className:"ftw-manual-grid",children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Name"}),e.jsx("input",{value:C.Name,onChange:j=>g(T=>({...T,Name:j.target.value})),placeholder:"Customer name"})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsxs("label",{children:["Phone ",e.jsx("span",{style:{color:"#DC2626"},children:"*"})]}),e.jsx("input",{value:C.Phone,onChange:j=>g(T=>({...T,Phone:j.target.value})),placeholder:"+919876543210"})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Email"}),e.jsx("input",{value:C.Email,onChange:j=>g(T=>({...T,Email:j.target.value})),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Notes"}),e.jsx("input",{value:C.Notes,onChange:j=>g(T=>({...T,Notes:j.target.value})),placeholder:"Requirement or context"})]})]}),e.jsxs("div",{className:"ftw-inline-actions",style:{marginTop:10,justifyContent:"space-between"},children:[e.jsx("small",{style:{color:"#64748B"},children:"Phone is required. Map the Phone column in the next step."}),e.jsxs("button",{type:"button",className:"fuf-btn primary",onClick:D,disabled:!C.Phone.trim(),children:[e.jsx(Ae,{})," Add lead"]})]})]})]}),m.length>0&&e.jsx(Je,{headers:f,rows:m.slice(0,5),totalRows:m.length})]})}function Je({headers:i,rows:n,totalRows:r}){return e.jsxs(e.Fragment,{children:[e.jsxs("p",{style:{marginTop:14,marginBottom:6,fontSize:"0.82rem",color:"#475569"},children:["Preview (",n.length," of ",r," rows)"]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{className:"ftw-table",children:[e.jsx("thead",{children:e.jsx("tr",{children:i.map((t,o)=>e.jsx("th",{children:t||"—"},o))})}),e.jsx("tbody",{children:n.map((t,o)=>e.jsx("tr",{children:i.map((f,m)=>e.jsx("td",{children:(t.values||[])[m]||""},m))},o))})]})})]})}function mt({headers:i,previewLeads:n,mapping:r,setMapping:t,totalValidLeads:o,totalRows:f}){const m=(a,h)=>t(v=>({...v,[a]:h}));return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Map your columns"}),e.jsxs("p",{className:"ftw-sub",children:["Phone is required. We auto-suggest the rest. ",o," of ",f," rows have a valid phone number."]}),e.jsxs("div",{className:"ftw-row",children:[e.jsxs("div",{className:"ftw-field",children:[e.jsxs("label",{children:["Phone column ",e.jsx("span",{style:{color:"#DC2626"},children:"*"})]}),e.jsxs("select",{value:r.phone||"",onChange:a=>m("phone",a.target.value),children:[e.jsx("option",{value:"",children:"Pick a column…"}),i.map((a,h)=>e.jsx("option",{value:a,children:a},h))]})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Name column"}),e.jsxs("select",{value:r.name||"",onChange:a=>m("name",a.target.value),children:[e.jsx("option",{value:"",children:"— None —"}),i.map((a,h)=>e.jsx("option",{value:a,children:a},h))]})]})]}),e.jsxs("div",{className:"ftw-row",style:{marginTop:12},children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Email column"}),e.jsxs("select",{value:r.email||"",onChange:a=>m("email",a.target.value),children:[e.jsx("option",{value:"",children:"— None —"}),i.map((a,h)=>e.jsx("option",{value:a,children:a},h))]})]}),e.jsx("div",{})]}),e.jsx("p",{style:{marginTop:18,marginBottom:6,fontSize:"0.82rem",color:"#475569"},children:"Preview leads"}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{className:"ftw-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Phone"}),e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Email"}),e.jsx("th",{children:"Status"})]})}),e.jsx("tbody",{children:n.map((a,h)=>e.jsxs("tr",{children:[e.jsx("td",{children:a.phone||e.jsx("span",{style:{color:"#DC2626"},children:"(missing)"})}),e.jsx("td",{children:a.name||"—"}),e.jsx("td",{children:a.email||"—"}),e.jsx("td",{children:Ye(a.phone)?e.jsx("span",{style:{color:"#15803D",fontWeight:700},children:"Valid"}):e.jsx("span",{style:{color:"#DC2626",fontWeight:700},children:"Skipped"})})]},h))})]})})]})}function ft(i){const{firstCallTime:n,setFirstCallTime:r,businessHoursOnly:t,setBusinessHoursOnly:o,allowedDays:f,setAllowedDays:m,callWindowStart:a,setCallWindowStart:h,callWindowEnd:v,setCallWindowEnd:C,maxConcurrentCalls:g,setMaxConcurrentCalls:D,secondsBetweenCalls:E,setSecondsBetweenCalls:F,dailyCallLimit:I,setDailyCallLimit:j}=i,T=w=>{m(U=>U.includes(w)?U.filter(L=>L!==w):[...U,w])};return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Schedule"}),e.jsx("p",{className:"ftw-sub",children:"When should the first call go out, and what's your daily pace?"}),e.jsxs("div",{className:"ftw-row",children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"First call time"}),e.jsx("input",{type:"time",value:n,onChange:w=>r(w.target.value)})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Daily call limit"}),e.jsx("input",{type:"number",min:"0",max:"100000",value:I,onChange:w=>j(w.target.value)})]})]}),e.jsxs("div",{className:"ftw-field",style:{marginTop:12},children:[e.jsx("label",{children:"Allowed days"}),e.jsx("div",{className:"ftw-day-row",children:nt.map(w=>e.jsx("button",{type:"button",className:`ftw-day-chip ${f.includes(w)?"active":""}`,onClick:()=>T(w),children:ps[w]},w))})]}),e.jsxs("div",{className:"ftw-row",style:{marginTop:12},children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Business hours start"}),e.jsx("input",{type:"time",value:a,onChange:w=>h(w.target.value)})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Business hours end"}
335),e.jsx("input",{type:"time",value:v,onChange:w=>C(w.target.value)})]})]}),e.jsxs("div",{className:"ftw-row",style:{marginTop:12},children:[e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Max concurrent calls"}),e.jsx("input",{type:"number",min:"1",max:"50",value:g,onChange:w=>D(w.target.value)})]}),e.jsxs("div",{className:"ftw-field",children:[e.jsx("label",{children:"Seconds between calls"}),e.jsx("input",{type:"number",min:"0",max:"600",value:E,onChange:w=>F(w.target.value)})]})]}),e.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center",marginTop:14,fontSize:"0.88rem",color:"#334155"},children:[e.jsx("input",{type:"checkbox",checked:t,onChange:w=>o(w.target.checked)}),"Only call during business hours"]})]})}function xt(i){const{template:n,funnelName:r,assistantSetupMode:t,assistant:o,source:f,totalValidLeads:m,firstCallTime:a,allowedDays:h,callWindowStart:v,callWindowEnd:C,maxConcurrentCalls:g,secondsBetweenCalls:D,dailyCallLimit:E,submitError:F}=i;return e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Review and start"}),e.jsx("p",{className:"ftw-sub",children:"We'll create the funnel as a draft, schedule each lead's first call, then activate it."}),F&&e.jsxs("div",{className:"ftw-banner error",children:[e.jsx(M,{}),e.jsx("span",{children:F})]}),e.jsxs("div",{className:"ftw-summary-card",children:[e.jsx("h4",{children:"Funnel"}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Template"}),e.jsx("span",{children:n?.title||"—"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Name"}),e.jsx("span",{children:r||"—"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Assistant"}),e.jsx("span",{children:t==="auto"?"Create ready follow-up assistant":o?.name||"—"})]}),t==="auto"&&e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Assistant memory"}),e.jsx("span",{children:"Short context, lead fields, previous outcome, and current step"})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Days"}),e.jsx("span",{children:(n?.flow||[]).slice(1,-1).join(" → ")})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Save fields"}),e.jsxs("span",{children:[n?.saveFieldCount," per call"]})]})]}),e.jsxs("div",{className:"ftw-summary-card",children:[e.jsx("h4",{children:"Leads"}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Source"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Valid leads"}),e.jsx("span",{children:m})]})]}),e.jsxs("div",{className:"ftw-summary-card",children:[e.jsx("h4",{children:"Schedule"}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"First call time"}),e.jsx("span",{children:a})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Allowed days"}),e.jsx("span",{children:h.map(I=>ps[I]).join(", ")})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Window"}),e.jsxs("span",{children:[v," – ",C]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Concurrency"}),e.jsxs("span",{children:[g," concurrent · ",D,"s gap"]})]}),e.jsxs("div",{className:"row",children:[e.jsx("span",{children:"Daily limit"}),e.jsx("span",{children:E||"Unlimited"})]})]}),e.jsxs("p",{style:{fontSize:"0.82rem",color:"#64748B",marginTop:6},children:[e.jsx(us,{style:{verticalAlign:"-3px",marginRight:4}}),"After starting, you'll land on the funnel canvas where you can review the flow."]})]})}export{jt 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.