1import{r as h,e,w as ee,t as ue,C as pe}from"./react-vendor-DGH7E8PJ.js";import{a as te}from"./clerk-vendor-08HSh_wb.js";import{p as W,B as U,M as Y,fB as he,fC as z,dK as ae,a as xe,q as be,em as fe,fD as ge,dD as ye,dC as je,dG as we,a1 as ve,S as Ne,eq as ke}from"./index-CXbZxsi1.js";import{D as Ce}from"./dashboard-layout-CfvHr2V3.js";import{p as qe}from"./csv-parse-VCAnvQUh.js";import{D as se,b as ie,c as le,d as ne,e as re,f as oe}from"./dialog-Dps7YF5b.js";import{S as Se,a as Fe,b as Le,c as $e,d as Z}from"./select-DupAHoYW.js";import{_ as Ae,a6 as ce,L as X,a8 as De,s as Oe,aG as Ee,D as Te,aa as Ie,H as Me}from"./icons-vendor-CE-SoUfG.js";import{f as de}from"./date-vendor-D78Ae0Pv.js";import"./ui-vendor-C9szsJt4.js";import"./locale-data-CFiiwNZm.js";import"./page-activity-CoP2VHDH.js";import"./confetti-Yoll5z1z.js";import"./command-BdNprNpM.js";import"./dropdown-menu-Dc7x3MA3.js";const V="__none__";function Re({formId:t,form:a,formName:d,open:w,onOpenChange:v,onImported:f}){const{getToken:m}=te(),{toast:N}=W(),x=h.useRef(null),[D,k]=h.useState("upload"),[R,L]=h.useState(!1),[l,O]=h.useState([]),[j,o]=h.useState([]),[g,P]=h.useState({email:null,firstName:null,lastName:null,phone:null,questions:{}}),C=h.useMemo(()=>{const n=[{kind:"contact",key:"email",label:"Email",required:!0},{kind:"contact",key:"firstName",label:"First name",required:!1},{kind:"contact",key:"lastName",label:"Last name",required:!1},{kind:"contact",key:"phone",label:"Phone",required:!1}],u=a?.questions.map(q=>({kind:"question",id:q.id,label:q.label||"Untitled question"}))??[];return[...n,...u]},[a]);function s(){k("upload"),L(!1),O([]),o([]),P({email:null,firstName:null,lastName:null,phone:null,questions:{}}),x.current&&(x.current.value="")}function r(n){n||s(),v(n)}function p(n){return n.kind==="contact"?g[n.key]:g.questions[n.id]??null}function E(n,u){P(q=>n.kind==="contact"?{...q,[n.key]:u}:{...q,questions:{...q.questions,[n.id]:u}})}async function b(n){const u=n.target.files?.[0];if(u){L(!0);try{const q=await u.text(),i=qe(q).filter(S=>S.some(K=>K.trim()!==""));if(i.length<2){N({title:"Nothing to import",description:"That file has no data rows below the header.",variant:"destructive"}),L(!1),x.current&&(x.current.value="");return}const c=i[0].map(S=>S.trim()),y=i.slice(1);O(c),o(y);let $={email:null,firstName:null,lastName:null,phone:null,questions:Object.fromEntries((a?.questions??[]).map(S=>[S.id,null]))};try{const S=await m(),K=await Y(`/application-forms/${t}/import/map`,{method:"POST",token:S,json:{columns:c,samples:y.slice(0,5)}});K.mapping&&($={...$,...K.mapping})}catch{}P($),k("mapping")}catch{N({title:"Couldn't read that file",description:"Make sure it's a valid .csv export.",variant:"destructive"}),x.current&&(x.current.value="")}finally{L(!1)}}}async function Q(){if(g.email==null){N({title:"Map the email column",description:"Every submission needs an email address.",variant:"destructive"});return}k("importing");try{const n=await m(),u=await Y(`/application-forms/${t}/import`,{method:"POST",token:n,json:{mapping:g,rows:j}});N({title:"Submissions imported",description:`${u.imported} imported`+(u.skipped>0?` · ${u.skipped} skipped (no email)`:"")}),f(),r(!1)}catch(n){N({title:"Couldn't import",description:n instanceof Error?n.message:"Please try again.",variant:"destructive"}),k("mapping")}}return e.jsx(se,{open:w,onOpenChange:r,children:e.jsxs(ie,{className:"bg-[#111] border-white/10 text-white sm:max-w-lg","data-testid":"dialog-import-submissions",children:[e.jsxs(le,{children:[e.jsx(ne,{children:"Import submissions"}),e.jsx(re,{className:"text-gray-400",children:D==="mapping"?`We matched your CSV columns to ${d||"this form"} with AI - confirm each field below before importing.`:"Upload a CSV of submissions. We'll use AI to match its columns to this form's fields."})]}),D==="upload"&&e.jsxs("div",{className:"py-2",children:[e.jsx("button",{type:"button",onClick:()=>x.current?.click(),disabled:R,className:"flex w-full flex-col items-center justify-center gap-2 rounded-xl border border-dashed border-white/15 bg-white/[0.02] px-4 py-10 text-sm text-gray-400 transition-colors hover:border-white/30 hover:text-white disabled:opacity-60","data-testid":"button-choose-csv",children:R?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-6 w-6 animate-pulse text-primary"}),"Reading file and matching columnsâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"h-6 w-6"}),"Choose a CSV file"]})}),e.jsx("input",{ref:x,type:"file",accept:".csv,text/csv",onChange:b,className:"hidden","data-testid":"input-import-csv"})]}),D==="mapping"&&e.jsx("div",{className:"max-h-[55vh] space-y-3 overflow-y-auto py-1 pr-1",children:C.map(n=>{const u=p(n),q=u!=null?j[0]?.[u]?.trim()??"":"",i=n.kind==="contact"?n.key:n.id;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"truncate text-sm text-white",children:[n.label,n.kind==="contact"&&n.required&&e.jsx("span",{className:"text-primary",children:" *"})]}),q&&e.jsxs("div",{className:"truncate text-xs text-gray-500",children:["e.g. ",q]})]}),e.jsxs(Se,{value:u==null?V:String(u),onValueChange:c=>E(n,c===V?null:Number(c)),children:[e.jsx(Fe,{className:"w-44 shrink-0 border-white/10 bg-white/[0.02] text-sm text-white","data-testid":`select-map-${i}`,children:e.jsx(Le,{placeholder:"Not mapped"})}),e.jsxs($e,{className:"bg-[#0a0a0a] border-white/10 text-white",children:[e.jsx(Z,{value:V,children:"Not mapped"}),l.map((c,y)=>e.jsx(Z,{value:String(y),children:c||`Column ${y+1}`},y))]})]})]},i)})}),D==="importing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-10 text-sm text-gray-400",children:[e.jsx(X,{className:"h-6 w-6 animate-spin text-primary"}),"Importing ",j.length," row",j.length===1?"":"s","â¦"]}),D==="mapping"&&e.jsxs(oe,{children:[e.jsx(U,{variant:"ghost",onClick:()=>s(),className:"text-gray-400 hover:bg-white/5 hover:text-white","data-testid":"button-import-back",children:"Choose another file"}),e.jsxs(U,{onClick:Q,className:"bg-primary text-black hover:bg-primary-hover","data-testid":"button-confirm-import",children:[e.jsx(De,{className:"mr-1 h-4 w-4"}),"Import ",j.length," row",j.length===1?"":"s"]})]})]})})}
1function Pe(t){return t==null?"$0":`$${(t/100).toLocaleString(void 0,{maximumFractionDigits:2})}`}function H(t){return t==null||Array.isArray(t)&&t.length===0?" - ":Array.isArray(t)?t.join(", "):t||" - "}const B="w-full rounded-lg border border-white/10 bg-white/[0.02] px-3 py-2 text-sm text-white placeholder:text-gray-500 focus:border-white/20 focus:outline-none",T="text-3xs uppercase tracking-wider text-gray-500";function M({label:t,value:a}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:T,children:t}),e.jsx("div",{className:"mt-0.5 text-sm text-gray-200 break-words",children:a})]})}function G({value:t,onChange:a,onLabel:d,offLabel:w,accent:v="green"}){const f=v==="blue"?"bg-blue-400/15 text-blue-200 border-blue-400/30":"bg-primary/15 text-primary border-primary/30";return e.jsx("div",{className:"inline-flex rounded-lg border border-white/10 bg-white/[0.02] p-1",children:[{on:!0,label:d},{on:!1,label:w}].map(m=>{const N=t===m.on;return e.jsx("button",{type:"button",onClick:()=>a(m.on),className:"rounded-md border px-3 py-1.5 sm:py-1 text-xs font-medium transition-colors "+(N?f:"border-transparent text-gray-400 hover:text-white"),"data-testid":`toggle-${m.label.toLowerCase().replace(/\s+/g,"-")}`,children:m.label},m.label)})})}function _(t){const a={};for(const d of Object.keys(t.questionLabels??{}))a[d]=H(t.answers?.[d])===" - "?"":H(t.answers?.[d]);return{firstName:t.firstName??"",lastName:t.lastName??"",email:t.email??"",phone:t.phone??"",outcome:t.outcome==="qualified"?"qualified":"disqualified",attended:t.attended===!0,bought:t.bought===!0,amount:t.amountCents!=null?String(t.amountCents/100):"",answers:a}}function Qe({formId:t,submission:a,isCall:d,isSales:w,usesQualify:v=!0,open:f,onOpenChange:m,onSaved:N}){const{toast:x}=W(),D=ee(),k=he(),[R,L]=h.useState(!1),[l,O]=h.useState(null);h.useEffect(()=>{f&&a&&(L(!1),O(_(a)))},[f,a]);const j=h.useMemo(()=>Object.entries(a?.questionLabels??{}),[a]);if(!a)return null;const o=a,g=[o.firstName,o.lastName].filter(Boolean).join(" ").trim();function P(){if(!l||!a)return;const s={};for(const[p]of Object.entries(a.questionLabels??{})){const E=a.answers?.[p],b=Array.isArray(E),Q=(l.answers[p]??"").trim(),n=b?E.join(", "):E??"";Q!==n.trim()&&(s[p]=b?Q.split(",").map(u=>u.trim()).filter(Boolean):Q)}const r={firstName:l.firstName.trim(),lastName:l.lastName.trim(),email:l.email.trim(),phone:l.phone.trim(),answers:Object.keys(s).length?s:void 0};if(v)a.partial||(r.outcome=l.outcome);else if(d&&(r.attended=l.attended,w)){r.bought=l.attended?l.bought:!1;const p=Math.max(0,Math.round((parseFloat(l.amount)||0)*100));r.amountCents=l.attended&&l.bought?p:0}k.mutate({id:t,submissionId:a.id,data:r},{onSuccess:p=>{D.invalidateQueries({queryKey:z(t)}),D.invalidateQueries({queryKey:ae(t)}),L(!1),O(_(p)),N?.(p),x({title:"Submission updated"})},onError:()=>{x({title:"Couldn't save",description:"Please try again.",variant:"destructive"})}})}const C=(s,r)=>O(p=>p&&{...p,[s]:r});return e.jsx(se,{open:f,onOpenChange:m,children:e.jsxs(ie,{className:"bg-[#111] border-white/10 text-white sm:max-w-2xl max-h-[85vh] overflow-y-auto","data-testid":"dialog-submission-detail",children:[e.jsxs(le,{children:[e.jsx(ne,{children:g||o.email||"Submission"}),e.jsxs(re,{children:[d?"Logged call":"Application"," ·"," ",de(new Date(o.createdAt),"MMM d, yyyy · h:mm a"),o.funnelTitle?` · via ${o.funnelTitle}`:""]})]}),R?l&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:"First name"}),e.jsx("input",{className:B+" mt-1",value:l.firstName,onChange:s=>C("firstName",s.target.value),"data-testid":"input-edit-firstName"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:"Last name"}),e.jsx("input",{className:B+" mt-1",value:l.lastName,onChange:s=>C("lastName",s.target.value),"data-testid":"input-edit-lastName"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:"Email"}),e.jsx("input",{className:B+" mt-1",value:l.email,onChange:s=>C("email",s.target.value),"data-testid":"input-edit-email"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:"Phone"}),e.jsx("input",{className:B+" mt-1",value:l.phone,onChange:s=>C("phone",s.target.value),"data-testid":"input-edit-phone"})]})]}),(v||d)&&e.jsx("div",{className:"border-t border-white/5 pt-4",children:v?o.partial?e.jsx("p",{className:"text-xs text-gray-500",children:"Incomplete application - the visitor hasn't submitted, so there's no outcome to edit yet."}):e.jsxs("div",{children:[e.jsx("div",{className:T+" mb-1.5",children:"Outcome"}),e.jsx(G,{value:l.outcome==="qualified",onChange:s=>C("outcome",s?"qualified":"disqualified"),onLabel:"Qualified",offLabel:"Disqualified"})]}):e.jsxs("div",{className:"flex flex-wrap items-end gap-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:T+" mb-1.5",children:"Attendance"}),e.jsx(G,{value:l.attended,onChange:s=>C("attended",s),onLabel:"Showed",offLabel:"No-show",accent:"blue"})]}),w&&l.attended&&e.jsxs("div",{children:[e.jsx("div",{className:T+" mb-1.5",children:"Sale"}),e.jsx(G,{value:l.bought,onChange:s=>C("bought",s),onLabel:"Closed",offLabel:"No sale"})]}),w&&l.attended&&l.bought&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:"Amount collected ($)"}),e.jsx("input",{type:"number",min:0,step:"0.01",className:B+" mt-1 w-40",value:l.amount,onChange:s=>C("amount",s.target.value),"data-testid":"input-edit-amount"})]})]})}),j.length>0&&e.jsx("div",{className:"grid gap-3 border-t border-white/5 pt-4",children:j.map(([s,r])=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:T,children:r}),e.jsx("textarea",{rows:2,className:B+" mt-1 resize-y",value:l.answers[s]??"",onChange:p=>C("answers",{...l.answers,[s]:p.target.value}),"data-testid":`input-edit-answer-${s}`})]},s))})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(M,{label:"First name",value:o.firstName||" - "}),e.jsx(M,{label:"Last name",value:o.lastName||" - "}),e.jsx(M,{label:"Email",value:o.email||" - "}),e.jsx(M,{label:"Phone",value:o.phone||" - "}),d?e.jsxs(e.Fragment,{children:[e.jsx(M,{label:"Attendance",value:o.attended===!0?"Showed":"No-show"}),w&&e.jsx(M,{label:"Sale",value:o.bought===!0?`Closed · ${Pe(o.amountCents)}`:"No sale"})]}):v?e.jsx(M,{label:"Outcome",value:o.partial?"Incomplete":o.outcome==="qualified"?"Qualified":"Disqualified"}):o.partial?e.jsx(M,{label:"Status",value:"Incomplete"}):null]}),j.length>0&&e.jsx("div",{className:"grid gap-3 border-t border-white/5 pt-4 sm:grid-cols-2",children:j.map(([s,r])=>e.jsx(M,{label:r,value:H(o.answers?.[s])},s))})]}),e.jsx(oe,{children:R?e.jsxs(e.Fragment,{children:[e.jsx(U,{type:"button",variant:"ghost",onClick:()=>{L(!1),O(_(o))},disabled:k.isPending,"data-testid":"button-cancel-edit",children:"Cancel"}),e.jsxs(U,{type:"button",onClick:P,disabled:k.isPending,"data-testid":"button-save-submission",children:[k.isPending&&e.jsx(X,{className:"h-4 w-4 animate-spin"}),"Save changes"]})]}):e.jsxs(U,{type:"button",onClick:()=>L(!0),"data-testid":"button-edit-submission",children:[e.jsx(Oe,{className:"h-4 w-4"}),"Edit"]})})]})})}
1function me(t){return t==null?"$0":`$${(t/100).toLocaleString(void 0,{maximumFractionDigits:2})}`}function Ke({outcome:t,partial:a}){if(a)return e.jsx("span",{className:"inline-flex items-center text-3xs font-semibold uppercase tracking-wider px-2 py-0.5 rounded-md border bg-amber-400/10 text-amber-400 border-amber-400/30","data-testid":"chip-submission-outcome-incomplete",children:"Incomplete"});const d=t==="qualified";return e.jsx("span",{className:"inline-flex items-center text-3xs font-semibold uppercase tracking-wider px-2 py-0.5 rounded-md border "+(d?"bg-primary/15 text-primary border-primary/30":"bg-gray-500/10 text-gray-400 border-gray-500/25"),"data-testid":`chip-submission-outcome-${d?"qualified":"disqualified"}`,children:d?"Qualified":"Disqualified"})}function Be({s:t}){const a=t.attended===!0;return e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-1.5",children:[e.jsx("span",{className:"inline-flex items-center rounded-md border px-2 py-0.5 text-3xs font-semibold uppercase tracking-wider "+(a?"border-blue-400/30 bg-blue-400/10 text-blue-300":"border-gray-500/25 bg-gray-500/10 text-gray-400"),"data-testid":`chip-call-attended-${a?"yes":"no"}`,children:a?"Showed":"No-show"}),t.callType==="sales"&&t.bought===!0&&e.jsxs("span",{className:"inline-flex items-center rounded-md border border-primary/30 bg-primary/15 px-2 py-0.5 text-3xs font-semibold uppercase tracking-wider text-primary",children:["Closed ",me(t.amountCents)]}),t.callType==="sales"&&t.attended===!0&&t.bought===!1&&e.jsx("span",{className:"inline-flex items-center rounded-md border border-gray-500/25 bg-gray-500/10 px-2 py-0.5 text-3xs font-semibold uppercase tracking-wider text-gray-400",children:"No sale"})]})}function F({value:t,label:a,accent:d=!1}){return e.jsxs("div",{className:"flex-1 text-center",children:[e.jsx("div",{className:"text-xl font-semibold tabular-nums "+(d?"text-primary":"text-white"),children:t}),e.jsx("div",{className:"mt-0.5 text-3xs uppercase tracking-wider text-gray-500",children:a})]})}function Ue(t){return t==null?" - ":Array.isArray(t)?t.join(", "):t}function Ve({s:t,isCall:a,usesQualify:d,onOpen:w}){const v=[t.firstName,t.lastName].filter(Boolean).join(" ").trim(),f=Object.entries(t.questionLabels??{});return e.jsxs("div",{role:"button",tabIndex:0,onClick:w,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),w())},className:"cursor-pointer rounded-2xl border border-white/10 bg-[#111] p-5 transition-colors hover:border-white/20 hover:bg-white/[0.03] focus:outline-none focus-visible:border-white/30","data-testid":`row-submission-${t.id}`,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-base font-semibold text-white",children:v||t.email||"Anonymous"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:[t.email||(a?"No contact on file":""),t.phone?` · ${t.phone}`:""]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1.5",children:[a?e.jsx(Be,{s:t}):d||t.partial?e.jsx(Ke,{outcome:t.outcome,partial:t.partial}):null,e.jsx("span",{className:"text-xs text-gray-500",children:de(new Date(t.createdAt),"MMM d, yyyy · h:mm a")})]})]}),!a&&(t.funnelId==null||t.funnelTitle)&&e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:t.funnelId==null?e.jsxs(e.Fragment,{children:["via ",e.jsx("span",{className:"text-gray-400",children:"Public page"})]}):e.jsxs(e.Fragment,{children:["via ",e.jsx("span",{className:"text-gray-400",children:t.funnelTitle})]})}),f.length>0&&e.jsx("dl",{className:"mt-4 grid gap-3 border-t border-white/5 pt-4 sm:grid-cols-2",children:f.map(([m,N])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-3xs uppercase tracking-wider text-gray-500",children:N}),e.jsx("dd",{className:"mt-0.5 text-sm text-gray-200 break-words",children:Ue(t.answers?.[m])})]},m))})]})}function nt(){const[,t]=ue(),{id:a}=pe(),{getToken:d}=te(),{toast:w}=W(),v=ee(),{data:f}=xe(),[m,N]=h.useState(""),[x,D]=h.useState("all"),[k,R]=h.useState(!1),[L,l]=
1h.useState(!1),[O,j]=h.useState(null),o=f?.betaFeatures?.["application-forms"]!==!1||f?.isAdmin===!0&&be(f?.betaFeatures,"sales-kpi"),{data:g}=fe(a,{query:{enabled:o&&!!a,queryKey:ke(a)}}),{data:P,isLoading:C}=ge(a,{query:{enabled:o&&!!a,queryKey:z(a)}}),s=h.useMemo(()=>P??[],[P]),r=g?ye(g.form):s.some(i=>!!i.callType),p=g?je(g.form)==="sales_call":s.some(i=>i.callType==="sales"),E=g?we(g.form):!r,b=h.useMemo(()=>{const i=s.filter(A=>A.partial===!0).length,c=s.filter(A=>A.partial!==!0),y=c.length,$=c.filter(A=>A.attended===!0).length,S=c.filter(A=>A.bought===!0).length,K=c.reduce((A,J)=>A+(J.bought===!0?J.amountCents??0:0),0),I=c.filter(A=>A.outcome==="qualified").length;return{total:y,incomplete:i,showed:$,showRate:y>0?Math.round($/y*100):0,closed:S,cashCents:K,qualified:I,disqualified:y-I,qualifiedRate:y>0?Math.round(I/y*100):0}},[s]),Q=h.useMemo(()=>{const i=m.trim().toLowerCase();return s.filter(c=>x==="qualified"&&(c.partial===!0||c.outcome!=="qualified")||x==="disqualified"&&(c.partial===!0||c.outcome!=="disqualified")||x==="incomplete"&&c.partial!==!0||x==="showed"&&c.attended!==!0||x==="noshow"&&c.attended!==!1?!1:i?[c.firstName,c.lastName,c.email,c.phone].filter(Boolean).join(" ").toLowerCase().includes(i):!0)},[s,m,x]);if(h.useEffect(()=>{f&&!o&&t("/dashboard")},[f,o,t]),f&&!o)return null;async function n(){if(!(!a||k)){R(!0);try{const i=await d(),c=await Ne(`/application-forms/${a}/submissions.csv`,{token:i}),y=await c.blob(),$=Number(c.headers.get("X-Submission-Count")??"0"),S=URL.createObjectURL(y),K=(g?.name||"form").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40)||"form",I=document.createElement("a");I.href=S,I.download=`${K}-${r?"calls":"applications"}.csv`,document.body.appendChild(I),I.click(),I.remove(),URL.revokeObjectURL(S),w({title:$>0?"Export downloaded":"Nothing to export yet",description:$>0?`${$} ${r?"call":"submission"}${$===1?"":"s"} exported.`:r?"Once you log a call on this form, it'll land here.":"Once someone completes this form, their application will land here."})}catch{w({title:"Couldn't export",description:"Please try again.",variant:"destructive"})}finally{R(!1)}}}const u=s.length>0,q=r?[{key:"all",label:"all"},{key:"showed",label:"showed"},{key:"noshow",label:"no-show"}]:E?[{key:"all",label:"all"},{key:"qualified",label:"qualified"},{key:"disqualified",label:"disqualified"},{key:"incomplete",label:"incomplete"}]:[{key:"all",label:"all"},{key:"incomplete",label:"incomplete"}];return e.jsxs(Ce,{children:[e.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>t(r?`/dashboard/forms/${a}`:"/dashboard/forms"),className:"inline-flex items-center gap-1.5 text-sm text-gray-400 hover:text-white transition-colors","data-testid":"link-submissions-back",children:[e.jsx(Ee,{className:"w-4 h-4"}),r?"Back to form":"All application forms"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!r&&e.jsxs("button",{type:"button",onClick:()=>l(!0),disabled:!g,className:"inline-flex items-center gap-1.5 rounded-lg border border-white/10 px-3 py-1.5 text-sm text-gray-300 transition-colors hover:bg-white/5 hover:text-white disabled:opacity-50","data-testid":"button-import-submissions",children:[e.jsx(ce,{className:"w-4 h-4"}),"Import CSV"]}),u&&e.jsxs("button",{type:"button",onClick:n,disabled:k,className:"inline-flex items-center gap-1.5 rounded-lg border border-white/10 px-3 py-1.5 text-sm text-gray-300 transition-colors hover:bg-white/5 hover:text-white disabled:opacity-50","data-testid":"button-export-submissions",children:[k?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsx(Te,{className:"w-4 h-4"}),"Export CSV"]})]})]}),e.jsx("header",{className:"mb-6",children:e.jsx("h1",{className:"text-2xl font-semibold text-white",children:r?"Call history":"Submissions"})}),C?e.jsx("div",{className:"text-sm text-gray-500 py-12 text-center",children:"Loadingâ¦"}):u?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mb-5 grid grid-cols-3 gap-y-3 rounded-xl border border-black/[0.06] dark:border-white/5 bg-black/[0.04] dark:bg-white/[0.02] py-3 sm:flex sm:items-stretch sm:divide-x sm:divide-transparent sm:dark:divide-white/5","data-testid":"submissions-summary",children:r?e.jsxs(e.Fragment,{children:[e.jsx(F,{value:b.total??0,label:"Calls"}),e.jsx(F,{value:b.showed??0,label:"Showed"}),e.jsx(F,{value:`${b.showRate??0}%`,label:"Show-up %",accent:!0}),p&&e.jsx(F,{value:b.closed??0,label:"Closed"}),p&&e.jsx(F,{value:me(b.cashCents??0),label:"Cash"})]}):E?e.jsxs(e.Fragment,{children:[e.jsx(F,{value:b.total,label:"Total"}),e.jsx(F,{value:b.qualified??0,label:"Qualified",accent:!0}),e.jsx(F,{value:b.disqualified??0,label:"Disqualified"}),e.jsx(F,{value:`${b.qualifiedRate??0}%`,label:"Qualified %"}),b.incomplete>0&&e.jsx(F,{value:b.incomplete,label:"Incomplete"})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{value:b.total,label:"Total"}),b.incomplete>0&&e.jsx(F,{value:b.incomplete,label:"Incomplete"})]})}),e.jsxs("div",{className:"mb-5 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx(Me,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500"}),e.jsx("input",{value:m,onChange:i=>N(i.target.value),placeholder:"Search by name, email or phone",className:"w-full rounded-lg border border-white/10 bg-white/[0.02] py-2 pl-9 pr-3 text-sm text-white placeholder:text-gray-500 focus:border-white/20 focu
1s:outline-none","data-testid":"input-search-submissions"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-lg border border-black/10 dark:border-white/10 bg-black/[0.04] dark:bg-white/[0.02] p-1",children:q.map(i=>e.jsx("button",{type:"button",onClick:()=>D(i.key),className:"rounded-md px-2.5 py-1.5 sm:px-3 sm:py-1 text-xs font-medium capitalize transition-colors "+(x===i.key?"bg-white/10 text-white":"text-gray-400 hover:text-white"),"data-testid":`filter-outcome-${i.key}`,children:i.label},i.key))})]}),Q.length===0?e.jsxs("div",{className:"rounded-2xl border border-white/10 bg-[#0c0c0c] p-10 text-center text-sm text-gray-500","data-testid":"empty-submissions-filtered",children:["No ",r?"calls":"submissions"," match your filters."]}):e.jsx("div",{className:"grid gap-4",children:Q.map(i=>e.jsx(Ve,{s:i,isCall:r,usesQualify:E,onOpen:()=>j(i)},i.id))})]}):e.jsx(ve,{icon:e.jsx("span",{className:"inline-flex w-14 h-14 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(Ie,{className:"w-7 h-7 text-primary"})}),title:r?"No calls logged yet":"No submissions yet",description:r?"Open this form on a call and submit it - every call you log shows up here.":"Once someone completes this form on a funnel's thank-you page, their application shows up here.",testId:"empty-submissions"})]}),e.jsx(Qe,{formId:a,submission:O,isCall:r,isSales:p,usesQualify:E,open:!!O,onOpenChange:i=>{i||j(null)},onSaved:i=>j(i)}),e.jsx(Re,{formId:a,form:g?.form,formName:g?.name??"",open:L,onOpenChange:l,onImported:()=>{v.invalidateQueries({queryKey:z(a)}),v.invalidateQueries({queryKey:ae(a)})}})]})}export{nt 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.