1import{j as e}from"./vendor-motion-BCX7EEar.js";import{u,C as a,c as l,k as i,l as r,L as c}from"./index-BO96xVPj.js";import{A as y}from"./AdminLayout-baKE9i_5.js";import{B as x}from"./badge-BYiSBuNC.js";import{c as f,n as b,B as v,K as w,o as k,O as C,C as d,D as o,Q as m,J as h,V as j,j as T,Y as g,F as A}from"./vendor-icons-B9EBoyoK.js";import"./vendor-charts-CBV0Rgbk.js";import"./button-BZ40igge.js";const N={NEW:"bg-blue-100 text-blue-800",CONTACTED:"bg-yellow-100 text-yellow-800",QUALIFIED:"bg-purple-100 text-purple-800",PROPOSAL_SENT:"bg-orange-100 text-orange-800",CLOSED:"bg-green-100 text-green-800",LOST:"bg-red-100 text-red-800"},L={NOTE:"bg-gray-100 text-gray-700",CALL:"bg-green-100 text-green-700",EMAIL:"bg-blue-100 text-blue-700",TEXT:"bg-purple-100 text-purple-700",STATUS_CHANGE:"bg-orange-100 text-orange-700",MEETING:"bg-pink-100 text-pink-700",TASK:"bg-yellow-100 text-yellow-700",BOOKING:"bg-emerald-100 text-emerald-700",DOCUMENT:"bg-indigo-100 text-indigo-700"};function U(){const{data:t,isLoading:p}=u({queryKey:["/api/admin/stats"],queryFn:async()=>{const s=await fetch("/api/admin/stats",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch stats");return s.json()}});return e.jsx(y,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900","data-testid":"text-dashboard-title",children:"CRM Dashboard"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"Overview of your mortgage pipeline & CRM"})]}),p?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[...Array(8)].map((s,n)=>e.jsx(a,{children:e.jsx(l,{className:"p-6",children:e.jsx("div",{className:"animate-pulse h-16 bg-gray-200 rounded"})})},n))}):t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(a,{"data-testid":"card-total-leads",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Total Leads"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.totalLeads})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-blue-50 flex items-center justify-center",children:e.jsx(f,{className:"h-5 w-5 text-blue-600"})})]})})}),e.jsx(a,{"data-testid":"card-total-prospects",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Prospects"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.totalProspects})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-indigo-50 flex items-center justify-center",children:e.jsx(b,{className:"h-5 w-5 text-indigo-600"})})]})})}),e.jsx(a,{"data-testid":"card-total-accounts",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Accounts"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.totalAccounts})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(v,{className:"h-5 w-5 text-emerald-600"})})]})})}),e.jsx(a,{"data-testid":"card-total-contacts",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Contacts"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.totalContacts})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-violet-50 flex items-center justify-center",children:e.jsx(w,{className:"h-5 w-5 text-violet-600"})})]})})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(a,{"data-testid":"card-active-pipeline",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Active Pipeline"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.activePipeline})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-orange-50 flex items-center justify-center",children:e.jsx(k,{className:"h-5 w-5 text-orange-600"})})]})})}),e.jsx(a,{"data-testid":"card-closed-deals",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Closed Deals"}),e.jsx("p",{className:"text-3xl font-bold text-emerald-600",children:t.closedDeals})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(C,{className:"h-5 w-5 text-emerald-600"})})]})})}),e.jsx(a,{"data-testid":"card-overdue",className:t.overdueCount>0?"ring-1 ring-red-200":"",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Overdue"}),e.jsx("p",{className:`text-3xl font-bold ${t.overdueCount>0?"text-red-600":"text-gray-900"}`,children:t.overdueCount})]}),e.jsx("div",{className:`h-11 w-11 rounded-lg flex items-center justify-center ${t.overdueCount>0?"bg-red-50":"bg-gray-50"}`,children:e.jsx(d,{className:`h-5 w-5 ${t.overdueCount>0?"text-red-600":"text-gray-400"}`})})]})})}),e.jsx(a,{"data-testid":"card-projected-revenue",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Projected Revenue"}),e.jsxs("p",{className:"text-3xl font-bold text-gray-900",children:["$",(t.totalProjectedRevenue||0).toLocaleStr
1ing()]})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-green-50 flex items-center justify-center",children:e.jsx(o,{className:"h-5 w-5 text-green-600"})})]})})})]}),t.totalAccounts>0&&e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:e.jsx(a,{"data-testid":"card-total-commission",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Total Commission"}),e.jsxs("p",{className:"text-3xl font-bold text-emerald-600",children:["$",(t.totalCommission||0).toLocaleString()]})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(o,{className:"h-5 w-5 text-emerald-600"})})]})})})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(a,{"data-testid":"card-total-bookings",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Calendly Bookings"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.totalBookings||0})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-cyan-50 flex items-center justify-center",children:e.jsx(m,{className:"h-5 w-5 text-cyan-600"})})]})})}),e.jsx(a,{"data-testid":"card-email-opens",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Open Rate"}),e.jsxs("p",{className:"text-3xl font-bold text-emerald-700",children:[t.emailTracking?.openRate??0,"%"]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[t.emailTracking?.totalOpens||0," opens · ",t.emailTracking?.uniqueOpens||0," unique"]})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(h,{className:"h-5 w-5 text-emerald-600"})})]})})}),e.jsx(a,{"data-testid":"card-email-clicks",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Click Rate"}),e.jsxs("p",{className:"text-3xl font-bold text-sky-700",children:[t.emailTracking?.clickRate??0,"%"]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[t.emailTracking?.totalClicks||0," clicks · ",t.emailTracking?.uniqueClicks||0," unique"]})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-sky-50 flex items-center justify-center",children:e.jsx(j,{className:"h-5 w-5 text-sky-600"})})]})})}),e.jsx(a,{"data-testid":"card-bounce-rate",children:e.jsx(l,{className:"p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Bounce Rate"}),e.jsxs("p",{className:"text-3xl font-bold text-red-600",children:[t.emailTracking?.bounceRate??0,"%"]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[t.emailTracking?.totalBounces||0," bounces · ",t.emailTracking?.totalSent||0," sent"]})]}),e.jsx("div",{className:"h-11 w-11 rounded-lg bg-red-50 flex items-center justify-center",children:e.jsx(d,{className:"h-5 w-5 text-red-500"})})]})})})]}),(t.overdueLeads?.length>0||t.upcomingFollowUps?.length>0)&&e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[t.overdueLeads?.length>0&&e.jsxs(a,{className:"border-red-200",children:[e.jsx(i,{className:"pb-2",children:e.jsxs(r,{className:"text-sm flex items-center gap-2 text-red-700",children:[e.jsx(d,{size:16}),"Overdue Follow-Ups"]})}),e.jsx(l,{children:e.jsx("div",{className:"space-y-2",children:t.overdueLeads.map(s=>e.jsxs(c,{href:"/admin/leads",className:"flex items-center justify-between py-1.5 px-2 rounded hover:bg-red-50 transition-colors","data-testid":`link-overdue-${s.id}`,children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:s.firstName?`${s.firstName} ${s.lastName||""}`.trim():s.fullName||s.email}),e.jsx("span",{className:"text-xs text-red-600",children:s.nextFollowUpAt&&`Due: ${new Date(s.nextFollowUpAt).toLocaleDateString()}`})]},s.id))})})]}),t.upcomingFollowUps?.length>0&&e.jsxs(a,{children:[e.jsx(i,{className:"pb-2",children:e.jsxs(r,{className:"text-sm flex items-center gap-2 text-orange-700",children:[e.jsx(T,{size:16}),"Upcoming Follow-Ups"]})}),e.jsx(l,{children:e.jsx("div",{className:"space-y-2",children:t.upcomingFollowUps.map(s=>e.jsxs(c,{href:"/admin/leads",className:"flex items-center justify-between py-1.5 px-2 rounded hover:bg-orange-50 transition-colors","data-testid":`link-followup-${s.id}`,children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:s.firstName?`${s.firstName} ${s.lastName||""}`.trim():s.fullName||s.email}),e.jsx("span",{className:"text-xs text-orange-600",children:s.nextFollowUpAt&&new Date(s.nextFollowUpAt).toLocaleDateString()})]},s.id))})})]})]}),t.upcomingBirthdays?.length>0&&e.jsxs(a,{children:[e.jsx(i,{className:"pb-2",children:e.jsxs(r,{className:"text-sm flex items-center gap-2 text-pink-700",children:[e.jsx(g,{size:16}),"Upcoming Birthdays (Next 30 Days)"]})}),e.jsx(l,{children:e.jsx("div",{className:"flex gap-3 flex-wrap",children:t.upcomingBirthdays.map(s=>e.jsxs("div",{className:"flex items-center gap-2 bg-pink-50 rounded-lg px-3 py-2",children:[e.jsx(g,{size:14,className:"text-pink-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.firstName?`${s.firstName} ${s.lastName||""}`.trim():s.fullName||s.email}),e.jsx("p",{className:"text-xs text-pink-600",children:s.birthday})]})]},s.id))})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(a,{children:[e.jsx(i,{children:e.jsx(r,{className:"text-lg",children:"Lead Pipeline"})}),e.jsx(l,{children:e.jsxs("div",{className:"space-y-3",children:[Object.entries(t.leadsByStatus||{}).map(([s,n])=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{className:N[s]||"bg-gray-100 text-gray-800",children:s.replace("_"," ")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-24 h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#0c2a6d] rounded-full",style:{width:`${Math.min(n/Math.max(t.totalLeads,1)*100,100)}%`}})}),e.jsx("span",{className:"text-sm font-semibold text-gray-700 w-8 text-right",children:n})]})]},s)),Object.keys(t.leadsByStatus||{}).length===0&&e.jsx("p",{className:"text-sm text-gray-400 text-center py-4",children:"No leads yet"})]})})]}),e.jsxs(a,{children:[e.jsx(i,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(r,{className:"text-lg",children:"Recent Activity"})})}),e.jsx(l,{children:e.jsxs("div",{className:"space-y-3",children:[(t.recentActivities||[]).slice(0,8).map(s=>e.jsxs("div",{className:"flex items-start gap-2 py-1.5 border-b border-gray-100 last:border-0",children:[e.jsx(x,{className:`${L[s.type]||"bg-gray-100"} text-xs shrink-0`,children:s.type}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-gray-800 truncate",children:s.content}),e.jsxs("p",{className:"text-xs text-gray-400",children:[s.createdByName&&`${s.createdByName}
1 · `,new Date(s.createdAt).toLocaleString()]})]})]},s.id)),(!t.recentActivities||t.recentActivities.length===0)&&e.jsx("p",{className:"text-sm text-gray-400 text-center py-4",children:"No recent activity"})]})})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(a,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r,{className:"text-lg",children:"Recent Leads"}),e.jsx(c,{href:"/admin/leads",className:"text-sm text-[#0c2a6d] hover:underline","data-testid":"link-view-all-leads",children:"View all"})]})}),e.jsx(l,{children:e.jsxs("div",{className:"space-y-3",children:[(t.recentLeads||[]).map(s=>e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-gray-100 last:border-0",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.firstName?`${s.firstName} ${s.lastName||""}`.trim():s.fullName||s.email}),e.jsx("p",{className:"text-xs text-gray-500",children:s.source||"N/A"})]}),e.jsx(x,{className:N[s.status]||"bg-gray-100 text-gray-800",children:s.status})]},s.id)),(!t.recentLeads||t.recentLeads.length===0)&&e.jsx("p",{className:"text-sm text-gray-400 text-center py-4",children:"No leads yet"})]})})]}),e.jsxs(a,{"data-testid":"card-recent-bookings",children:[e.jsx(i,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs(r,{className:"text-lg flex items-center gap-2",children:[e.jsx(m,{size:18,className:"text-cyan-600"}),"Recent Bookings"]})})}),e.jsx(l,{children:e.jsxs("div",{className:"space-y-3",children:[(t.recentBookings||[]).map(s=>e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-gray-100 last:border-0","data-testid":`row-booking-${s.id}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.inviteeName||"Guest"}),e.jsx("p",{className:"text-xs text-gray-500",children:s.inviteeEmail||"No email"})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-gray-600",children:s.eventName||"Meeting"}),e.jsx("p",{className:"text-xs text-gray-400",children:s.startTime?new Date(s.startTime).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):new Date(s.createdAt).toLocaleDateString()})]})]},s.id)),(!t.recentBookings||t.recentBookings.length===0)&&e.jsxs("div",{className:"text-center py-6 text-gray-400",children:[e.jsx(m,{size:32,className:"mx-auto mb-2 text-gray-300"}),e.jsx("p",{className:"text-sm",children:"No bookings yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Bookings from Calendly will appear here"})]})]})})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs(a,{children:[e.jsx(i,{children:e.jsx(r,{className:"text-lg",children:"Campaigns"})}),e.jsxs(l,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-center",children:[e.jsxs("div",{className:"bg-purple-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-2xl font-bold text-purple-700",children:t.activeCampaigns}),e.jsx("p",{className:"text-xs text-purple-600 mt-1",children:"Active"})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[e.jsx("p",{className:"text-2xl font-bold text-gray-700",children:t.totalCampaigns}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Total"})]})]}),e.jsx(c,{href:"/admin/campaigns",className:"block text-center text-sm text-[#0c2a6d] hover:underline mt-4",children:"Manage Campaigns"})]})]}),e.jsxs(a,{children:[e.jsx(i,{children:e.jsx(r,{className:"text-lg",children:"Strategy Forms"})}),e.jsxs(l,{children:[e.jsxs("div",{className:"text-center bg-green-50 rounded-lg p-4",children:[e.jsx(A,{className:"mx-auto h-8 w-8 text-green-600 mb-2"}),e.jsx("p",{className:"text-2xl font-bold text-green-700",children:t.totalResponses}),e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"Submissions"})]}),e.jsx(c,{href:"/admin/strategy",className:"block text-center text-sm text-[#0c2a6d] hover:underline mt-4",children:"View Submissions"})]})]}),e.jsxs(a,{children:[e.jsx(i,{children:e.jsx(r,{className:"text-lg",children:"Email Engagement"})}),e.jsxs(l,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{className:"bg-emerald-50 rounded-lg p-3",children:[e.jsx(h,{className:"mx-auto h-5 w-5 text-emerald-600 mb-1"}),e.jsxs("p",{className:"text-2xl font-bold text-emerald-700",children:[t.emailTracking?.o
1penRate??0,"%"]}),e.jsx("p",{className:"text-xs text-emerald-600 mt-1",children:"Open Rate"})]}),e.jsxs("div",{className:"bg-sky-50 rounded-lg p-3",children:[e.jsx(j,{className:"mx-auto h-5 w-5 text-sky-600 mb-1"}),e.jsxs("p",{className:"text-2xl font-bold text-sky-700",children:[t.emailTracking?.clickRate??0,"%"]}),e.jsx("p",{className:"text-xs text-sky-600 mt-1",children:"Click Rate"})]}),e.jsxs("div",{className:"bg-red-50 rounded-lg p-3",children:[e.jsx(d,{className:"mx-auto h-5 w-5 text-red-500 mb-1"}),e.jsxs("p",{className:"text-2xl font-bold text-red-600",children:[t.emailTracking?.bounceRate??0,"%"]}),e.jsx("p",{className:"text-xs text-red-500 mt-1",children:"Bounce Rate"})]})]}),e.jsx(c,{href:"/admin/email-analytics",className:"block text-center text-sm text-[#0c2a6d] hover:underline mt-4","data-testid":"link-email-analytics",children:"View full analytics"})]})]})]})]}):null]})})}export{U 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.