1import{c as z,u as K,a as I,r as i,bm as d,j as e,B as w,A as H,R as M,C as r,g as l,U,e as x,f as h,bC as j,y as W}from"./index-CfyOokG8.js";import{T as X,a as Y,b as p,c,d as q,e as n}from"./table-DqIW1Rtz.js";import{t as G}from"./index-CqIdYj8W.js";import{b as o}from"./waPersistentCache-lFhWPUn9.js";import{C as J}from"./check-check-luk0bOY9.js";import{E as O}from"./eye-Dz99-RCT.js";import{M as Q}from"./message-square-Bxq_sGFX.js";import{R as S,C,X as k,Y as R,T as D}from"./CartesianChart-DfuvniiI.js";import{L as V,a as _}from"./LineChart-D3rGH_Yt.js";import{L as Z}from"./Legend-Cd8QkZC8.js";import{B as ee,a as A}from"./BarChart-BvIHciAU.js";import"./string-CHAXtceq.js";import"./index-CX-TlZUJ.js";/** 2 * @license lucide-react v0.575.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const se=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]],ae=z("circle-stop",se);function ue(){const{id:t}=K(),m=I(),[g,y]=i.useState(!0),[s,L]=i.useState(null),[T,E]=i.useState([]),[F,P]=i.useState([]),[f,$]=i.useState([]),[re,le]=i.useState("Campaign");i.useEffect(()=>{t&&u()},[t]);const u=async()=>{y(!0);try{const a=await o(`${d}/drip-campaigns/${t}/analytics/summary`);a.ok&&L(await a.json());const b=await o(`${d}/drip-campaigns/${t}/analytics/daily`);b.ok&&P(await b.json());const N=await o(`${d}/drip-campaigns/${t}/analytics/funnel`);N.ok&&E(await N.json());const v=await o(`${d}/drip-campaigns/${t}/analytics/enrollments?per_page=10`);if(v.ok){const B=await v.json();$(B.enrollments)}}catch(a){console.error("Error fetching analytics:",a),G.error("Failed to load analytics data")}finally{y(!1)}};return t?e.jsxs("div",{className:"p-8 space-y-8 bg-gray-50/50 min-h-screen",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(w,{variant:"ghost",size:"icon",onClick:()=>m("/dashboard/whatsapp/drip-analytics"),children:e.jsx(H,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-gray-900",children:"Campaign Analytics"}),e.jsx("p",{className:"text-gray-500",children:"Performance insights and delivery reports"})]})]}),e.jsxs(w,{variant:"outline",onClick:u,disabled:g,children:[e.jsx(M,{className:`mr-2 h-4 w-4 ${g?"animate-spin":""}`}),"Refresh Data"]})]}),s&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(r,{className:"border-l-4 border-l-blue-500",children:e.jsxs(l,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between space-y-0 pb-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Total Enrolled"}),e.jsx(U,{className:"h-4 w-4 text-gray-400"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s.enrollment.total}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.enrollment.active," Active, ",s.enrollment.completed," Completed"]})]})}),e.jsx(r,{className:"border-l-4 border-l-green-500",children:e.jsxs(l,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between space-y-0 pb-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Delivered"}),e.jsx(J,{className:"h-4 w-4 text-green-500"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s.messages.delivered}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.messages.sent>0?(s.messages.delivered/s.messages.sent*100).toFixed(1):0,"% Delivery Rate"]})]})}),e.jsx(r,{className:"border-l-4 border-l-indigo-500",children:e.jsxs(l,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between space-y-0 pb-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Read"}),e.jsx(O,{className:"h-4 w-4 text-indigo-500"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s.messages.read}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.messages.delivered>0?(s.messages.read/s.messages.delivered*100).toFixed(1):0,"% Read Rate"]})]})}),e.jsx(r,{className:"border-l-4 border-l-purple-500 hidden",children:e.jsxs(l,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between space-y-0 pb-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Replied"}),e.jsx(Q,{className:"h-4 w-4 text-purple-500"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s.messages.replied})]})}),e.jsx(r,{className:"border-l-4 border-l-red-500",children:e.jsxs(l,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between space-y-0 pb-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"Stopped"}),e.jsx(ae,{className:"h-4 w-4 text-red-500"})]}),e.jsx("div",{className:"text-2xl font-bold",children:s.enrollment.paused+s.enrollment.failed}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.enrollment.paused," Paused, ",s.enrollment.failed," Failed"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsxs(r,{className:"col-span-1 lg:col-span-2 shadow-sm",children:[e.jsxs(x,{children:[e.jsx(h,{children:"Message Activity"}),e.jsx(j,{children:"Daily sent and read volume (Last 30 days)"})]}),e.jsx(l,{className:"h-[300px]",children:e.jsx(S,{width:"100%",height:"100%",children:e.jsxs(V,{data:F,children:[e.jsx(C,{strokeDasharray:"3 3",vertical:!1}),e.jsx(k,{dataKey:"date",tick:{fontSize:12}}),e.jsx(R,{tick:{fontSize:12}}),e.jsx(D,{contentStyle:{borderRadius:"8px",border:"none",boxShadow:"0 4px 12px rgba(0,0,0,0.1)"}}),e.jsx(Z,{}),e.jsx(_,{type:"monotone",dataKey:"sent",name:"Sent",stroke:"#3b82f6",strokeWidth:2,dot:!1,activeDot:{r:6}}),e.jsx(_,{type:"monotone",dataKey:"read",name:"Read",stroke:"#10b981",strokeWidth:2,dot:!1,activeDot:{r:6}})]})})})]}),e.jsxs(r,{className:"col-span-1 shadow-sm",children:[e.jsxs(x,{children:[e.jsx(h,{children:"Funnel Analysis"}),e.jsx(j,{children:"Drop-off between steps"})]}),e.jsx(l,{className:"h-[300px]",children:e.jsx(S,{width:"100%",height:"100%",children:e.jsxs(ee,{layout:"vertical",data:T,margin:{top:5,right:30,left:40,bottom:5},children:[e.jsx(C,{strokeDasharray:"3 3",horizontal:!0,vertical:!1}),e.jsx(k,{type:"number",hide:!0}
6),e.jsx(R,{dataKey:"step_name",type:"category",width:60,tick:{fontSize:12}}),e.jsx(D,{cursor:{fill:"transparent"}}),e.jsx(A,{dataKey:"sent",name:"Sent",fill:"#3b82f6",radius:[0,4,4,0],barSize:20}),e.jsx(A,{dataKey:"read",name:"Read",fill:"#10b981",radius:[0,4,4,0],barSize:20})]})})})]})]}),e.jsxs(r,{className:"shadow-sm",children:[e.jsxs(x,{children:[e.jsx(h,{children:"Recent Enrollments"}),e.jsx(j,{children:"Live status of enrolled contacts"})]}),e.jsx(l,{children:e.jsxs(X,{children:[e.jsx(Y,{children:e.jsxs(p,{children:[e.jsx(c,{children:"Contact"}),e.jsx(c,{children:"Phone"}),e.jsx(c,{children:"Status"}),e.jsx(c,{children:"Current Step"}),e.jsx(c,{children:"Last Activity"}),e.jsx(c,{children:"Next Run"})]})}),e.jsx(q,{children:f.length===0?e.jsx(p,{children:e.jsx(n,{colSpan:6,className:"text-center py-8 text-gray-500",children:"No enrollments found"})}):f.map(a=>e.jsxs(p,{children:[e.jsx(n,{className:"font-medium",children:a.contact_name}),e.jsx(n,{children:a.phone_number}),e.jsx(n,{children:e.jsx(te,{status:a.status})}),e.jsxs(n,{children:["Step ",a.current_step]}),e.jsx(n,{className:"text-gray-500",children:a.joined_at?new Date(a.joined_at).toLocaleDateString():"-"}),e.jsx(n,{className:"text-gray-500",children:a.next_run_at?new Date(a.next_run_at).toLocaleString():"-"})]},a.id))})]})})]})]}):e.jsx("div",{children:"Invalid Campaign ID"})}function te({status:t}){const m={active:"bg-green-100 text-green-700 hover:bg-green-100",completed:"bg-blue-100 text-blue-700 hover:bg-blue-100",paused:"bg-yellow-100 text-yellow-700 hover:bg-yellow-100",failed:"bg-red-100 text-red-700 hover:bg-red-100"};return e.jsx(W,{variant:"secondary",className:m[t]||"",children:t.charAt(0).toUpperCase()+t.slice(1)})}
6export{ue 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.