1import{j as e}from"./ui-components-CrH3hhmI.js";import{e as B,r as C}from"./react-core-Df-1f7lZ.js";import{f as D,by as he,C as L,a7 as $,a8 as R,a9 as U,I as me,W as pe,n as ue,aa as z,bf as xe,bP as K,bg as ge,bh as fe,bi as je,bj as T,ae as E,E as we,M as ye,a as G,a3 as Ce,V as be,N as Ne}from"./index-baCrhAE7.js";import{_ as u,R as P,n as Se,a as _,X as I,Y as V,T as O,e as W,L as ve,f as De,b as ke}from"./charts-DACaTPEh.js";import{f as w}from"./utils-BZSOOpUI.js";import{S as Y,a as X,b as q,c as J,d as N}from"./select-Ble92Qbb.js";import{C as Ae}from"./calendar-DkELgzD8.js";import{P as Fe,a as Me,b as Te}from"./popover-JkRdX4HH.js";import{T as Q,a as Z,b as A,c as x,d as ee,e as g}from"./table-E2WjTH_r.js";import{T as te,a as se,b as ae,c as ne}from"./tooltip-DKqZMvs-.js";import{S as y}from"./skeleton-BAxah5Y5.js";import{S as Le}from"./switch-ChDQayde.js";import{c as $e}from"./contactsService-o7kjEWYr.js";import{A as Re}from"./arrow-up-down-DkF5DC5S.js";import{E as Ue}from"./ellipsis-vertical-DMYS6511.js";import{P as Ee}from"./phone-Cuv_7-pV.js";import{A as Pe}from"./arrow-up-right-CwE6zgCg.js";import{A as _e}from"./arrow-down-right-scaUeI26.js";import"./editor-wwdhYSyT.js";import"./apiClient-DGYJXd9L.js";const Ie=()=>/^((?!chrome|android).)*safari/i.test(navigator.userAgent),re=s=>Array.isArray(s)&&s.every(t=>typeof t=="object"&&!(t instanceof Array)),Ve=s=>Array.isArray(s)&&s.every(t=>Array.isArray(t)),Oe=s=>Array.from(s.map(t=>Object.keys(t)).reduce((t,a)=>new Set([...t,...a]),[])),We=(s,t)=>{t=t||Oe(s);let a=t,o=t;re(t)&&(a=t.map(i=>i.label),o=t.map(i=>i.key));const n=s.map(i=>o.map(l=>He(l,i)));return[a,...n]},He=(s,t)=>{const a=s.replace(/\[([^\]]+)]/g,".$1").split(".").reduce(function(o,n,i,l){const d=o[n];if(d==null)l.splice(1);else return d},t);return a===void 0?s in t?t[s]:"":a},Be=s=>typeof s>"u"||s===null?"":s,oe=(s,t=",",a='"')=>s.filter(o=>o).map(o=>o.map(n=>Be(n)).map(n=>`${a}${n}${a}`).join(t)).join(` 2`),ze=(s,t,a,o)=>oe(t?[t,...s]:s,a,o),Ke=(s,t,a,o)=>oe(We(s,t),a,o),Ge=(s,t,a,o)=>t?`${t.join(a)} 3${s}`:s.replace(/"/g,'""'),le=(s,t,a,o)=>{if(re(s))return Ke(s,t,a,o);if(Ve(s))return ze(s,t,a,o);if(typeof s=="string")return Ge(s,t,a);throw new TypeError('Data should be a "String", "Array of arrays" OR "Array of objects" ')},ie=(s,t,a,o,n)=>{const i=le(s,a,o,n),l=Ie()?"application/csv":"text/csv",d=new Blob([t?"\uFEFF":"",i],{type:l}),c=`data:${l};charset=utf-8,${t?"\uFEFF":""}${i}`,m=window.URL||window.webkitURL;return typeof m.createObjectURL>"u"?c:m.createObjectURL(d)},ce={data:u.oneOfType([u.string,u.array,u.func]).isRequired,headers:u.array,target:u.string,separator:u.string,filename:u.string,uFEFF:u.bool,onClick:u.func,asyncOnClick:u.bool,enclosingCharacter:u.string},de={separator:",",filename:"generatedBy_react-csv.csv",uFEFF:!0,asyncOnClick:!1,enclosingCharacter:'"'},Ye={target:"_blank"};class kt extends B.Component{static defaultProps=Object.assign(de,Ye);static propTypes=ce;constructor(t){super(t),this.state={}}buildURI(){return ie(...arguments)}componentDidMount(){const{data:t,headers:a,separator:o,enclosingCharacter:n,uFEFF:i,target:l,specs:d,replace:c}=this.props;this.state.page=window.open(this.buildURI(t,i,a,o,n),l,d,c)}getWindow(){return this.state.page}render(){return null}}let Xe=class extends B.Component{static defaultProps=de;static propTypes=ce;constructor(t){super(t),this.buildURI=this.buildURI.bind(this)}buildURI(){return ie(...arguments)}handleLegacy(t,a=!1){if(window.navigator.msSaveOrOpenBlob){t.preventDefault();const{data:o,headers:n,separator:i,filename:l,enclosingCharacter:d,uFEFF:c}=this.props,m=a&&typeof o=="function"?o():o;let f=new Blob([c?"\uFEFF":"",le(m,n,i,d)]);return window.navigator.msSaveBlob(f,l),!1}}handleAsyncClick(t){const a=o=>{if(o===!1){t.preventDefault();return}this.handleLegacy(t,!0)};this.props.onClick(t,a)}handleSyncClick(t){if(this.props.onClick(t)===!1){t.preventDefault();return}this.handleLegacy(t)}handleClick(){return t=>{if(typeof this.props.onClick=="function")return this.props.asyncOnClick?this.handleAsyncClick(t):this.handleSyncClick(t);this.handleLegacy(t)}}render(){const{data:t,headers:a,separator:o,filename:n,uFEFF:i,children:l,onClick:d,asyncOnClick:c,enclosingCharacter:m,...f}=this.props,r=typeof window>"u"?"":this.buildURI(t,i,a,o,m);return e.jsx("a",{download:n,...f,ref:p=>this.link=p,target:"_self",href:r,onClick:this.handleClick(),children:l})}};const qe=Xe;function Je({users:s}){const t=o=>o?.length?o.map(n=>
3{const i=n?.phone?`'${n.phone.toString().replace(/^'|'$/g,"")}'`:"N/A";return{"Full Name":n.name,"Email Address":n.email,"Phone Number":i,"Funnel Stage":`Stage v${n.funnel}`,"Sign Up Date":w(new Date(n.createdAt),"MMM dd, yyyy"),Websites:n.existingWebsites?.join(", ")||"N/A","Last Updated":w(new Date(n.updatedAt),"MMM dd, yyyy HH:mm:ss"),Status:n.status||"Active",Notes:n.notes||"N/A","Total Visits":n.visits||0,Source:n.source||"Direct",Country:n.country||"N/A",Industry:n.industry||"N/A","Company Size":n.companySize||"N/A"}}):[],a=[{label:"Full Name",key:"Full Name"},{label:"Email Address",key:"Email Address"},{label:"Phone Number",key:"Phone Number"},{label:"Funnel Stage",key:"Funnel Stage"},{label:"Sign Up Date",key:"Sign Up Date"},{label:"Websites",key:"Websites"},{label:"Last Updated",key:"Last Updated"},{label:"Status",key:"Status"},{label:"Notes",key:"Notes"},{label:"Total Visits",key:"Total Visits"},{label:"Source",key:"Source"},{label:"Country",key:"Country"},{label:"Industry",key:"Industry"},{label:"Company Size",key:"Company Size"}];return e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Waitlist Management"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage and track your waitlist users effectively"})]}),e.jsx(qe,{data:t(s),headers:a,filename:`waitlist-${w(new Date,"yyyy-MM-dd-HH-mm")}.csv`,className:"no-underline",children:e.jsxs(D,{variant:"outline",className:"w-full sm:w-auto",children:[e.jsx(he,{className:"mr-2 h-4 w-4"}),"Export Data"]})})]})}const Qe=(s,t)=>{if(!s.length)return[];const a=new Date,n={week:7,month:30,year:365}[t]||7;return new Array(n).fill(0).map((l,d)=>{const c=new Date(a);return c.setDate(c.getDate()-(n-1-d)),c}).map(l=>{const d=new Date(l.setHours(0,0,0,0)),c=new Date(l.setHours(23,59,59,999)),m=s.filter(f=>{const h=new Date(f.createdAt);return h>=d&&h<=c}).length;return{name:l.toLocaleDateString("en-US",{month:"short",day:"numeric"}),value:m}})};function Ze({data:s,timeFrame:t,onTimeFrameChange:a}){const o=C.useMemo(()=>Qe(s,t),[s,t]);return e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(L,{children:[e.jsx($,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(R,{children:"Sign-up Trends"}),e.jsxs(Y,{value:t,onValueChange:a,children:[e.jsx(X,{className:"w-[180px]",children:e.jsx(q,{placeholder:"Select timeframe"})}),e.jsxs(J,{children:[e.jsx(N,{value:"week",children:"Last Week"}),e.jsx(N,{value:"month",children:"Last Month"}),e.jsx(N,{value:"year",children:"Last Year"})]})]})]})}),e.jsx(U,{children:e.jsx(P,{width:"100%",height:300,children:e.jsxs(Se,{data:o,children:[e.jsx(_,{strokeDasharray:"3 3"}),e.jsx(I,{dataKey:"name"}),e.jsx(V,{}),e.jsx(O,{}),e.jsx(W,{}),e.jsx(ve,{type:"monotone",dataKey:"value",stroke:"#8884d8"})]})})})]}),e.jsxs(L,{children:[e.jsx($,{children:e.jsx(R,{children:"Funnel Distribution"})}),e.jsx(U,{children:e.jsx(P,{width:"100%",height:300,children:e.jsxs(De,{data:[{name:"Stage 1",value:s.filter(n=>n.funnel===1).length},{name:"Stage 2",value:s.filter(n=>n.funnel===2).length},{name:"Stage 3",value:s.filter(n=>n.funnel===3).length}],children:[e.jsx(_,{strokeDasharray:"3 3"}),e.jsx(I,{dataKey:"name"}),e.jsx(V,{}),e.jsx(O,{}),e.jsx(W,{}),e.jsx(ke,{dataKey:"value",fill:"#82ca9d"})]})})})]})]})}function et({search:s,dateRange:t,funnelStage:a,onSearchChange:o,onDateRangeChange:n,onFunnelStageChange:i}){const[l,d]=C.useState({from:t[0],to:t[1]});return e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row",children:[e.jsx(me,{placeholder:"Search users...",value:s,onChange:c=>o(c.target.value),className:"md:w-[300px]"}),e.jsxs(Fe,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:`w-[300px] justify-start text-left font-normal ${!l&&"text-muted-foreground"}`,children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),l?.from?l.to?e.jsxs(e.Fragment,{children:[w(l.from,"LLL dd, y")," -"," ",w(l.to,"LLL dd, y")]}):w(l.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date range"})]})}),e.jsx(Te,{className:"w-auto p-0",align:"start",children:e.jsx(Ae,{initialFocus:!0,mode:"range",defaultMonth:l?.from,selected:l,onSelect:c=>{d(c),n([c?.from,c?.to])},numberOfMonths:2})})]}),e.jsxs(Y,{value:a,onValueChange:i,children:[e.jsx(X,{className:"w-[180px]",children:e.jsx(q,{placeholder:"Funnel Stage"})}),e.jsxs(J,{children:[e.jsx(N,{value:"all",children:"All Stages"}),e.jsx(N,{value:"0",children:"Stage 0"}),e.jsx(N,{value:"1",children:"Stage 1"})]})]})]})}function tt(){return e.jsx("div",{className:"rounded-md border",children:e.jsxs(Q,{children:[e.jsx(Z,{children:e.jsxs(A,{children:[e.jsx(x,{children:"User Details"}),e.jsx(x,{children:"Contact"}),e.jsx(x,{children:"Funnel Stage"}),e.jsx(x,{children:"Date Added"}),e.jsx(x,{className:"w-[50px]"})]})}),e.jsx(ee,{children:[...Array(5)].map((s,t)=>e.jsxs(A,{children:[e.jsx(g,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(y,{className:"h-4 w-[150px]"}),e.jsx(y,{className:"h-4 w-[200px]"})]})}),e.jsx(g,{children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(y,{className:"h-8 w-8 rounded-md"}),e.jsx(y,{className:"h-8 w-8 rounded-md"})]})}),e.jsx(g,{children:e.jsx(y,{className:"h-6 w-[100px]"})}),e.jsx(g,{children:e.jsx(y,{className:"h-4 w-[120px]"})}),e.jsx(g,{children:e.jsx(y,{className:"h-8 w-8 rounded-md"})})]},t))})]})})}function H({value:s,type:t}){const a=()=>{navigator.clipboard.writeText(s)};return e.jsx(te,{children:e.jsxs(se,{children:[e.jsx(ae,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:a,children:t==="email"?e.jsx(ye,{className:"h-4 w-4"}):e.jsx(Ee,{className:"h-4 w-4"})})}),e.jsx(ne,{side:"bottom",children:e.jsxs("p",{children:["Copy ",t]})})]})})}function st(s){switch(s){case 0:return"bg-blue-100 text-blue-800";case 1:return"bg-green-100 text-green-800";
3case 2:return"bg-yellow-100 text-yellow-800";default:return"bg-gray-100 text-gray-800"}}function at({users:s,sortConfig:t,loading:a,onSort:o,onDataChange:n}){const{selected:i}=ue(),{handletoast:l}=z(),[d,c]=C.useState({});if(a)return e.jsx(tt,{});if(!s?.length)return e.jsx("div",{className:"rounded-md border p-8 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"No users found"})});const m=r=>{o&&o(r)},f=async(r,p)=>{try{(await G.put(`/waitlist/${r}/contacted`,{contacted:!p})).data.success&&n?.()}catch(b){console.error("Error updating contacted status:",b)}},h=async r=>{if(!i?.database?.encrypted){l({type:"error",message:"Please select a CMS database first"});return}c(p=>({...p,[r._id]:!0}));try{const p=r.name.trim().split(" "),b=p[0]||"",S=p.slice(1).join(" ")||"",v={first_name:b,last_name:S,email:r.email,phone:r.phone||"",tags:["waitlist",`funnel-stage-${r.funnel}`],notes:`Imported from waitlist on ${w(new Date,"MMM d, yyyy")}`,metadata:{waitlist_id:r._id,funnel_stage:r.funnel,contacted:r.contacted,created_at:r.createdAt,existing_websites:r.existingWebsites||[]}};await $e.createContact(i.database.encrypted,v),l({type:"success",message:`${r.name} added to contacts successfully`})}catch(p){console.error("Error adding to contacts:",p),l({type:"error",message:p.message||"Failed to add contact"})}finally{c(p=>({...p,[r._id]:!1}))}};return e.jsx("div",{className:"rounded-md border",children:e.jsxs(Q,{children:[e.jsx(Z,{children:e.jsxs(A,{children:[e.jsx(x,{children:"User Details"}),e.jsx(x,{children:"Contact"}),e.jsx(x,{children:"Funnel Stage"}),e.jsx(x,{children:"Contacted"}),e.jsx(x,{className:"cursor-pointer",onClick:()=>m("createdAt"),children:e.jsxs("div",{className:"flex items-center gap-2",children:["Date Added",e.jsx(Re,{className:"h-4 w-4"})]})}),e.jsx(x,{children:"Actions"}),e.jsx(x,{className:"w-[50px]"})]})}),e.jsx(ee,{children:s.map(r=>e.jsxs(A,{className:"group",children:[e.jsx(g,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:r.name}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r.email})]})}),e.jsx(g,{children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(H,{value:r.email,type:"email"}),r.phone&&e.jsx(H,{value:r.phone,type:"phone"})]})}),e.jsx(g,{children:e.jsxs(xe,{variant:"secondary",className:`${st(r.funnel)}`,children:["Stage ",r.funnel]})}),e.jsx(g,{children:e.jsx(Le,{checked:r?.contacted||!1,onCheckedChange:()=>f(r._id,r.contacted)})}),e.jsx(g,{children:w(new Date(r.createdAt),"MMM d, yyyy")}),e.jsx(g,{children:e.jsx(te,{children:e.jsxs(se,{children:[e.jsx(ae,{asChild:!0,children:e.jsxs(D,{variant:"outline",size:"sm",className:"h-8 gap-2",onClick:()=>h(r),disabled:d[r._id],children:[d[r._id]?e.jsx("div",{className:"w-4 h-4 border-2 border-gray-300 border-t-blue-500 rounded-full animate-spin"}):e.jsx(K,{className:"h-4 w-4"}),!d[r._id]&&e.jsx("span",{className:"hidden sm:inline",children:"Add to CMS"})]})}),e.jsx(ne,{side:"top",children:e.jsx("p",{children:"Add this person to your CMS Contacts"})})]})})}),e.jsx(g,{children:e.jsxs(ge,{children:[e.jsx(fe,{asChild:!0,children:e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 opacity-0 group-hover:opacity-100",children:e.jsx(Ue,{className:"h-4 w-4"})})}),e.jsxs(je,{align:"end",children:[e.jsxs(T,{onClick:()=>navigator.clipboard.writeText(r.email),children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Copy email"]}),r.phone&&e.jsxs(T,{onClick:()=>navigator.clipboard.writeText(r.phone),children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Copy phone"]}),r.existingWebsites?.length>0&&e.jsxs(T,{onClick:()=>window.open(r.existingWebsites[0],"_blank"),children:[e.jsx(we,{className:"mr-2 h-4 w-4"}),"Visit website"]})]})]})})]},r.id))})]})})}function nt({analytics:s}){const t=[{title:"Total Users",value:s?.total||0,change:s?.changes?.total||"+0%",description:"From last month",icon:Ce,trend:s?.trends?.total||"up"},{title:"New Sign-ups",value:s?.newSignups||0,change:s?.changes?.newSignups||"+0%",description:"From last week",icon:K,trend:s?.trends?.newSignups||"up"},{title:"Pending Confirmations",value:s?.pending||0,change:s?.changes?.pending||"+0%",description:"From yesterday",icon:be,trend:s?.trends?.pending||"up"},{title:"Growth Rate",value:`${s?.growthRate||0}x`,change:s?.changes?.growth||"+0%",description:"From last month",icon:Ne,trend:s?.trends?.growth||"up"}];return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:t.map((a,o)=>e.jsxs(L,{children:[e.jsxs($,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(R,{className:"text-sm font-medium",children:a.title}),e.jsx(a.icon,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(U,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.description})]}),e.jsxs("div",{className:`flex items-center space-x-1 ${a.trend==="up"?"text-emerald-500":"text-red-500"}`,children:[e.jsx("span",{className:"text-sm font-medium",children:a.change}),a.trend==="up"?e.jsx(Pe,{className:"h-4 w-4"}):e.jsx(_e,{className:"h-4 w-4"})]})]})})]},o))})}const rt=s=>{if(!s.length)return null;const t=new Date,a=new Date(t);a.setMonth(a.getMonth()-1);const o=new Date(t);o.setDate(o.getDate()-7);const n=new Date(t);n.setDate(n.getDate()-1);const i=s.filter(j=>new Date(j.createdAt)>=o).length,l=s.filter(j=>j.contacted===!1).length,d=s.filter(j=>new Date(j.createdAt)>=a).length,c=s.filter(j=>{const k=new Date(j.createdAt),M=new Date(a);return M.setMonth(M.getMonth()-1),k>=M&&k<a}).length,m=c>0?((d-c)/c*100).toFixed(1):d>0?100:0,f=[...s].sort((j,k)=>new Date(j.createdAt)-new Date(k.createdAt)),h=new Date(f[0].createdAt),p=Math.max(1,Math.ceil((new Date-h)/(1e3*60*60*24))),b=(s.length/p*100).toFixed(1),S=((s.length-(s.length-d))/Math.max(1,s.length-d)*100).toFixed(1),v=c>0?((i-c)/c*100).toFixed(1):i>0?100:0,F=(l/s.length*100).toFixed(1);return{total:s.length,newSignups:i,pending:l,growthRate:b,changes:{total:`${S>0?"+":""}${S}%`,newSignups:`${v>0?"+":""}${v}%`,pending:`${F>0?"+":""}${F}%`,growth:`${m>0?"+":""}${m}%`},trends:{total:S>=0?"up":"down",newSignups:v>
3=0?"up":"down",pending:F>=0?"up":"down",growth:m>=0?"up":"down"}}},ot=(s,t,a,o)=>s.filter(n=>{const i=t.toLowerCase().trim()===""||n.name.toLowerCase().includes(t.toLowerCase())||n.email.toLowerCase().includes(t.toLowerCase())||n.phone?.toLowerCase().includes(t.toLowerCase()),l=o==="all"||n.funnel.toString()===o,d=!a[0]||!a[1]||new Date(n.createdAt)>=a[0]&&new Date(n.createdAt)<=a[1];return i&&l&&d});function Ft(){const{handletoast:s}=z(),[t,a]=C.useState({search:"",dateRange:[null,null],funnelStage:"all",graphTimeFrame:"week",users:[],loading:!0,sortConfig:{key:"createdAt",direction:"desc"}});C.useEffect(()=>{n()},[]);const o=()=>{n()},n=async()=>{try{a(r=>({...r,loading:!0}));const h=await G.get("/waitlist");a(r=>({...r,users:h.data,loading:!1}))}catch(h){s({type:"error",message:h.message}),a(r=>({...r,loading:!1}))}},i=C.useMemo(()=>t.users.length?rt(t.users):null,[t.users]),l=h=>{a(r=>({...r,search:h}))},d=h=>{a(r=>({...r,dateRange:h}))},c=h=>{a(r=>({...r,funnelStage:h}))},m=h=>{a(r=>({...r,graphTimeFrame:h}))},f=C.useMemo(()=>ot(t.users,t.search,t.dateRange,t.funnelStage),[t.users,t.search,t.dateRange,t.funnelStage]);return e.jsxs("div",{className:"container mx-auto p-6 space-y-8",children:[e.jsx(Je,{users:t.users}),e.jsx(nt,{analytics:i}),e.jsx(Ze,{data:t.users,timeFrame:t.graphTimeFrame,onTimeFrameChange:m}),e.jsx(et,{search:t.search,dateRange:t.dateRange,funnelStage:t.funnelStage,onSearchChange:l,onDateRangeChange:d,onFunnelStageChange:c}),e.jsx(at,{users:f,sortConfig:t.sortConfig,loading:t.loading,onDataChange:o})]})}export{Ft 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.