1import{aa as R,u as H,k as W,r as c,j as e,S as _,B as x,a5 as X,a2 as Y,C as b,A as E,y as Z,av as I,s as j}from"./index-BiDfH7tX.js";import{D as y,G as ee}from"./DashboardLayout-BF3DdFbK.js";import{B as se}from"./badge-SSnDuyLm.js";import{S as te}from"./switch-Dax9UKcf.js";import{i as ae}from"./isToday-CeUgHryU.js";import{P as ie}from"./pencil-BiZbHiGS.js";import{U as le}from"./users-CP8JwjiL.js";import{C as ne}from"./calendar-check-Dz9P30jg.js";import{C as re}from"./circle-check-Cx2ErogA.js";import{C as L}from"./calendar-clock-TMRyagtF.js";import{V as Q}from"./video-CVLaxB74.js";import{f as k}from"./format-D1d1hBBF.js";import"./useWhatsAppConnections-B85Sh32f.js";import"./circle-alert-KmaIewz3.js";import"./plus-Bt_BaSif.js";import"./scroll-area-9jOnv_Ut.js";import"./index-BdQq_4o_.js";import"./useMutation-ByfiAoaM.js";import"./rocket-BVs13ZeM.js";import"./file-text-Cn3QWfn7.js";import"./megaphone-C6LYbfQA.js";import"./settings-DmvFVmPY.js";import"./layout-dashboard-Dcp6oYyf.js";import"./shield-DwiDVEsn.js";import"./arrow-up-xXi1BMDI.js";import"./sheet-BVfJEJT6.js";import"./index-vl6vSx_6.js";import"./constructNow-Ns6dv8Vy.js";import"./en-US-CulqtCeB.js";function De(){var B,F,M,P,A,T,U,D,z;const{flowId:n}=R(),o=H(),{toast:v}=W(),[t,f]=c.useState(null),[u,w]=c.useState([]),[m,O]=c.useState([]),[V,C]=c.useState(!0),[a,g]=c.useState("all"),J=async()=>{if(!n)return;C(!0);const[{data:s},{data:i},{data:l}]=await Promise.all([j.from("automation_flows").select("id, name, is_active, config, campaign_id").eq("id",n).maybeSingle(),j.from("automation_flow_sessions").select("id, instagram_user_id, status, started_at, context_data").eq("flow_id",n).order("started_at",{ascending:!1}).limit(200),j.from("booked_calls").select("id, status, scheduled_at_utc, join_url, invitee_name, showed, duration_minutes, contact:contacts(instagram_username, full_name, profile_picture_url)").eq("flow_id",n).order("scheduled_at_utc",{ascending:!1}).limit(200)]);f(s),w(i||[]),O(l||[]),C(!1)};c.useEffect(()=>{J()},[n]);const p=c.useMemo(()=>{const s=u.length,i=u.filter(d=>{var h;return d.status==="completed"||((h=d.context_data)==null?void 0:h.qualified)===!0}).length,l=m.filter(d=>d.status!=="canceled").length,r=m.filter(d=>d.showed===!0).length;return{triggered:s,qualified:i,booked:l,showed:r}},[u,m]),S=c.useMemo(()=>m.filter(s=>s.scheduled_at_utc&&ae(new Date(s.scheduled_at_utc))&&s.status!=="canceled"),[m]),K=async s=>{t&&(await j.from("automation_flows").update({is_active:s}).eq("id",t.id),f({...t,is_active:s}),v({title:s?"Funnel resumed":"Funnel paused"}))};if(V)return e.jsx(y,{title:"Coaching",children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-4",children:[e.jsx(_,{className:"h-12 w-1/2"}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:[0,1,2,3].map(s=>e.jsx(_,{className:"h-24 rounded-2xl"},s))}),e.jsx(_,{className:"h-80 rounded-2xl"})]})});if(!t)return e.jsx(y,{title:"Coaching",children:e.jsxs("div",{className:"max-w-md mx-auto text-center py-20",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Funnel not found"}),e.jsx(x,{className:"mt-4",onClick:()=>o("/coaching"),children:"Back to coaching"})]})});const q=a==="all"||a==="booked"||a==="showed"?m.filter(s=>a==="showed"?s.showed===!0:!0):[],$=a==="all"||a==="triggered"||a==="qualified"?u.filter(s=>{var i;return a==="qualified"?s.status==="completed"||((i=s.context_data)==null?void 0:i.qualified):!0}):[];return e.jsx(y,{title:t.name,children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-6 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>o("/coaching"),children:e.jsx(X,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ee,{className:"h-3.5 w-3.5"})," Coaching funnel"]}),e.jsx("h1",{className:"text-2xl font-semibold",children:t.name})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-9 rounded-lg border",children:[e.jsx(te,{checked:t.is_active,onCheckedChange:K}),e.jsx("span",{className:"text-sm",children:t.is_active?"Active":"Paused"})]}),e.jsxs(x,{variant:"outline",onClick:()=>o(`/flow-builder/${t.id}`),children:[e.jsx(ie,{className:"h-4 w-4 mr-1.5"})," Edit"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(N,{active:a==="triggered",onClick:()=>g(a==="triggered"?"all":"triggered"),icon:le,label:"Triggered",value:p.triggered,tone:"slate"}),e.jsx(N,{active:a==="qualified",onClick:()=>g(a==="qualified"?"all":"qualified"),icon:Y,label:"Qualified",value:p.qualified,tone:"violet"}),e.jsx(N,{active:a==="booked",onClick:()=>g(a==="booked"?"all":"booked"),icon:ne,label:"Booked",value:p.booked,tone:"amber"}),e.jsx(N,{active:a==="showed",onClick:()=>g(a==="showed"?"all":"showed"),icon:re,label:"Showed",value:p.showed,tone:"emerald"})]}),e.jsxs("div",{className:"grid lg:grid-cols-[1fr_300px] gap-4",children:[e.jsxs(b,{className:"rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"px-5 py-3 border-b flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:"Leads"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a==="all"?"Everyone in this funnel":`Filtered: ${a}`," · click a stage above to filter"]})]})}),q.length===0&&$.length===0?e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"No leads in this stage yet. Once people comment on your trigger post, they'll show up here."}):e.jsxs("ul",{className:"divide-y",children:[q.map(s=>{var i,l,r,d,h;return e.jsxs("li",{className:"px-5 py-3 flex items-center gap-3 hover:bg-muted/40",children:[e.jsxs(E,{className:"h-9 w-9",children:[((i=s.contact)==null?void 0:i.profile_picture_url)&&e.jsx(Z,{src:s.contact.profile_picture_url}),e.jsx(I,{children:(((l=s.contact)==null?void 0:l.instagram_username)||s.invitee_name||"?").slice(0,2).toUpperCase()})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:((r=s.contact)==null?void 0:r.full_name)||s.invitee_name||((d=s.contact)==null?void 0:d.instagram_username)||"Unknown"}),((h=s.contact)==null?void 0:h.instagram_username)&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["@",s.contact.
1instagram_username]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(L,{className:"h-3 w-3"}),s.scheduled_at_utc?k(new Date(s.scheduled_at_utc),"MMM d, h:mm a"):"Time pending",s.duration_minutes?` · ${s.duration_minutes} min`:""]})]}),e.jsx(G,{value:s.status==="canceled"?"Canceled":s.showed===!0?"Showed":"Booked"}),s.join_url&&e.jsxs(x,{size:"sm",variant:"outline",onClick:()=>window.open(s.join_url,"_blank"),children:[e.jsx(Q,{className:"h-3.5 w-3.5 mr-1"})," Join"]})]},`b-${s.id}`)}),$.filter(s=>!m.some(i=>{var l,r;return((l=i.contact)==null?void 0:l.instagram_username)&&((r=s.context_data)==null?void 0:r.username)===i.contact.instagram_username})).slice(0,50).map(s=>{var i,l,r;return e.jsxs("li",{className:"px-5 py-3 flex items-center gap-3 hover:bg-muted/40",children:[e.jsx(E,{className:"h-9 w-9",children:e.jsx(I,{children:(((i=s.context_data)==null?void 0:i.username)||"?").slice(0,2).toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:(l=s.context_data)!=null&&l.username?`@${s.context_data.username}`:`IG user ${(r=s.instagram_user_id)==null?void 0:r.slice(-6)}`}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Started ",k(new Date(s.started_at),"MMM d, h:mm a")]})]}),e.jsx(G,{value:s.status==="completed"?"Qualified":"Triggered"})]},`s-${s.id}`)})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(b,{className:"p-4 rounded-2xl",children:[e.jsxs("h3",{className:"text-sm font-semibold mb-2 flex items-center gap-1.5",children:[e.jsx(L,{className:"h-4 w-4"})," Today's calls"]}),S.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Nothing scheduled today."}):e.jsx("ul",{className:"space-y-2",children:S.map(s=>{var i;return e.jsxs("li",{className:"text-sm flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:((i=s.contact)==null?void 0:i.full_name)||s.invitee_name||"Unknown"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.scheduled_at_utc&&k(new Date(s.scheduled_at_utc),"h:mm a")})]}),s.join_url&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>window.open(s.join_url,"_blank"),children:e.jsx(Q,{className:"h-3.5 w-3.5"})})]},s.id)})})]}),e.jsxs(b,{className:"p-4 rounded-2xl",children:[e.jsx("h3",{className:"text-sm font-semibold mb-2",children:"Configuration"}),e.jsxs("dl",{className:"text-xs space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Keywords"}),e.jsx("dd",{className:"font-medium truncate ml-2",children:(((B=t.config)==null?void 0:B.keywords)||[]).join(", ")||"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Posts"}),e.jsx("dd",{className:"font-medium",children:(F=t.config)!=null&&F.anyPost?"Any post":`${((P=(M=t.config)==null?void 0:M.postIds)==null?void 0:P.length)||0} selected`})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Qualifiers"}),e.jsxs("dd",{className:"font-medium",children:[((T=(A=t.config)==null?void 0:A.qualifiers)==null?void 0:T.length)||0," questions"]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Provider"}),e.jsx("dd",{className:"font-medium capitalize",children:((U=t.config)==null?void 0:U.provider)||"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Follow-ups"}),e.jsx("dd",{className:"font-medium",children:((z=(D=t.config)==null?void 0:D.followUps)==null?void 0:z.length)||0})]})]}),e.jsx(x,{size:"sm",variant:"outline",className:"w-full mt-3",onClick:()=>o(`/flow-builder/${t.id}`),children:"Open in flow builder"})]})]})]})]})})}function N({icon:n,label:o,value:v,tone:t,active:f,onClick:u}){const w={slate:"bg-slate-50 text-slate-700 border-slate-200",violet:"bg-violet-50 text-violet-700 border-violet-200",amber:"bg-amber-50 text-amber-700 border-amber-200",emerald:"bg-emerald-50 text-emerald-700 border-emerald-200"};return e.jsxs("button",{onClick:u,className:`text-left p-4 rounded-2xl border transition ${w[t]} ${f?"ring-2 ring-offset-2 ring-primary/50":"hover:shadow-sm"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(n,{className:"h-4 w-4 opacity-80"}),e.jsx("span",{className:"text-xs uppercase tracking-wide opacity-70",children:o})]}),e.jsx("div",{className:"text-2xl font-semibold mt-2",children:v})]})}function G({value:n}){const o={Triggered:"bg-slate-100 text-slate-700",Qualified:"bg-violet-100 text-violet-700",Booked:"bg-amber-100 text-amber-700",Showed:"bg-emerald-600 text-white",Canceled:"bg-red-100 text-red-700"};return e.jsx(se,{className:`${o[n]} border-0 font-medium`,children:n})}export{De 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.