1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[42294],{42294:function(e,a,s){s.r(a),s.d(a,{default:function(){return I}});var t=s(57437),l=s(2265),n=s(14438),r=s(84286),i=s(83578),d=s(15863),c=s(82431),o=s(17689),u=s(22839),x=s(33276),m=s(89227),p=s(92735),h=s(61649),g=s(12381),j=s(74291),f=s(33804),v=s(71837);let b={statement:async(e,a,s)=>(await v.api.get("/call-campaigns/usage/statement",{params:{from_day:e,to_day:a,campaign_id:s}})).data,statementXlsx:async(e,a,s)=>{let t=await v.api.get("/call-campaigns/usage/statement.xlsx",{params:{from_day:e,to_day:a,campaign_id:s},responseType:"blob",timeout:12e4}),l=URL.createObjectURL(t.data),n=document.createElement("a");n.href=l,n.download="statement_".concat(null!=e?e:"from","_").concat(null!=a?a:"to",".xlsx"),document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(l)},reconciliation:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:30;return(await v.api.get("/call-campaigns/usage/reconciliation",{params:{days:e}})).data},reconcileNow:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3;return(await v.api.post("/call-campaigns/usage/reconcile",{days_back:e})).data},overview:async()=>(await v.api.get("/call-campaigns/overview")).data,planTerms:async e=>(await v.api.patch("/call-campaigns/plans",e)).data,topup:async(e,a,s)=>(await v.api.post("/call-campaigns/plans/topup",{minutes:e,extend_days:a,note:s})).data,enabled:async()=>{try{var e;let a=await v.api.get("/call-campaigns/enabled");return!!(null===(e=a.data)||void 0===e?void 0:e.enabled)}catch(e){return!1}},list:async()=>{var e;return null!==(e=(await v.api.get("/call-campaigns")).data.campaigns)&&void 0!==e?e:[]},pipelines:async()=>{var e;return null!==(e=(await v.api.get("/call-campaigns/pipelines")).data.pipelines)&&void 0!==e?e:[]},upload:async(e,a,s)=>{let t=new FormData;return t.append("file",e),t.append("pipeline_id",a),s&&t.append("name",s),(await v.api.post("/call-campaigns/upload",t,{headers:{"Content-Type":"multipart/form-data"},timeout:12e4})).data},status:async e=>(await v.api.get("/call-campaigns/".concat(e))).data,rows:async(e,a)=>{var s;return null!==(s=(await v.api.get("/call-campaigns/".concat(e,"/rows"),{params:a?{status:a}:{}})).data.rows)&&void 0!==s?s:[]},captures:async e=>{var a;return null!==(a=(await v.api.get("/call-campaigns/".concat(e,"/captures"))).data.outcomes)&&void 0!==a?a:[]},infra:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:24;return(await v.api.get("/call-campaigns/infra",{params:{hours:e}})).data},call:async e=>(await v.api.get("/call-campaigns/calls/".concat(e))).data,kill:async e=>(await v.api.post("/call-campaigns/kill",{reason:e})).data,killClear:async()=>(await v.api.post("/call-campaigns/kill/clear")).data,controls:async(e,a)=>(await v.api.patch("/call-campaigns/".concat(e,"/controls"),a)).data,retryNow:async e=>(await v.api.post("/call-campaigns/".concat(e,"/retry-now"))).data,drain:async e=>(await v.api.post("/call-campaigns/".concat(e,"/drain"))).data,stop:async(e,a)=>(await v.api.post("/call-campaigns/".concat(e,"/stop"),{reason:a})).data,start:async e=>(await v.api.post("/call-campaigns/".concat(e,"/start"))).data,pause:async(e,a)=>(await v.api.post("/call-campaigns/".concat(e,"/pause"),{reason:a})).data,resume:async e=>(await v.api.post("/call-campaigns/".concat(e,"/resume"))).data,exportXlsx:async(e,a)=>{let s=await v.api.get("/call-campaigns/".concat(e,"/export.xlsx"),{responseType:"blob",timeout:12e4}),t=URL.createObjectURL(s.data),l=document.createElement("a");l.href=t,l.download=a,document.body.appendChild(l),l.click(),l.remove(),URL.revokeObjectURL(t)}};function N(e){var a,s,t;let l=null==e?void 0:null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail;return l&&"object"==typeof l&&"brand_validation_failed"===l.error?null!==(t=l.failures)&&void 0!==t?t:[]:null}let y={draft:"bg-muted text-muted-foreground ring-border",running:"bg-emerald-50 text-emerald-700 ring-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-300 dark:ring-emerald-900",paused:"bg-amber-50 text-amber-700 ring-amber-200 dark:bg-amber-950/40 dark:text-amber-300 dark:ring-amber-900",done:"bg-sky-50 text-sky-700 ring-sky-200 dark:bg-sky-950/40 dark:text-sky-300 dark:ring-sky-900"};function w(e){var a;let{state:s}=e;return(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium ring-1 ring-inset ".concat(null!==(a=y[s])&&void 0!==a?a:y.draft),children:["running"===s&&(0,t.jsx)("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-emerald-500"}),s]})}let _={connected:"text-emerald-700 bg-emerald-50 ring-emerald-200",no_answer:"text-amber-700 bg-amber-50 ring-amber-200",busy:"text-amber-700 bg-amber-50 ring-amber-200",wrong_number:"text-rose-700 bg-rose-50 ring-rose-200",not_interested:"text-rose-700 bg-rose-50 ring-rose-200",do_not_call:"text-rose-700 bg-rose-50 ring-rose-200",dnd_rejected:"text-rose-700 bg-rose-50 ring-rose-200",gate_blocked:"text-rose-700 bg-rose-50 ring-rose-200",callback_requested:"text-sky-700 bg-sky-50 ring-sky-200",originate_error:"text-amber-700 bg-amber-50 ring-amber-200"};function k(e){var a;let{d:s}=e;return s?(0,t.jsx)("span",{className:"inline-flex rounded-full px-2 py-0.5 text-[11px] font-medium ring-1 ring-inset ".concat(null!==(a=_[s])&&void 0!==a?a:"bg-muted text-muted-foreground ring-border"),children:s.replace(/_/g," ")}):(0,t.jsx)("span",{className:"text-muted-foreground",children:"â"})}function C(e){let{label:a,value:s,tone:l}=e;return(0,t.jsxs)("div",{className:"rounded-xl border bg-card px-3 py-2",children:[(0,t.jsx)("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:a}),(0,t.jsx)("div",{className:"text-lg font-semibold tabular-nums ".concat(null!=l?l:""),children:s})]})}function S(e){let{r:a}=e;return a?a.ok?(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-xl border border-emerald-200 bg-emerald-50 px-3 py-2 text-[12.5px] text-emerald-800 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300",children:[(0,t.jsx)(r.Z,{className:"h-4 w-4"})," Brand identity verified â this tenant may dial."]}):(0,t.jsxs)("div",{className:"rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-[12.5px] text-rose-800 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-300",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 font-medium",children:[(0,t.jsx)(i.Z,{className:"h-4 w-4"})," Cannot start â fix these first:"]}),(0,t.jsx)("ul",{className:"mt-1 list-disc space-y-0.5 pl-6",children:a.failures.map(e=>(0,t.jsx)("li",{children:e},e))})]}):null}function z(e){var a,s,n,r,i;let{callId:d}=e,[c,o]=(0,l.useState)(null),[u,x]=(0,l.useState)(null);return((0,l.useEffect)(()=>{let e=!0;return b.call(d).then(a=>{e&&o(a)}).catch(a=>{e&&x((0,v.getErrorMessage)(a,"Could not load the call"))}),()=>{e=!1}},[d]),u)?(0,t.jsx)("div",{className:"px-4 py-3 text-[12.5px] text-rose-700",children:u}):c?(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-3 px-4 py-3 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[c.recording_url?(0,t.jsx)("audio",{controls:!0,preload:"metadata",src:c.recording_url,className:"w-full"}):(0,t.jsx)("div",{className:"text-[12px] text-muted-foreground",children:"No recording stored for this call."}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 text-[12px]",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Lead"}),(0,t.jsx)("br",{}),null!==(s=c.lead_name)&&void 0!==s?s:"â"," \xb7 ",c.phone]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Line"}),(0,t.jsx)("br",{}),c.caller_id?"â¦".concat(c.caller_id.slice(-4)):"â"," \xb7 ",null!==(n=c.direction)&&void 0!==n?n:"outbound"]}
1),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Outcome"}),(0,t.jsx)("br",{}),(0,t.jsx)(k,{d:null!==(r=c.disposition)&&void 0!==r?r:c.outcome})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Latency"}),(0,t.jsx)("br",{}),(null===(a=c.latency)||void 0===a?void 0:a.median)!=null?"".concat(Number(c.latency.median).toFixed(1),"s median \xb7 p90 ").concat(Number(null!==(i=c.latency.p90)&&void 0!==i?i:0).toFixed(1),"s"):"â"]})]}),c.summary&&(0,t.jsxs)("div",{className:"rounded-lg border bg-card px-3 py-2 text-[12.5px]",children:[(0,t.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Summary"}),(0,t.jsx)("div",{children:c.summary})]}),c.captures.length>0&&(0,t.jsxs)("div",{className:"rounded-lg border bg-card px-3 py-2 text-[12px]",children:[(0,t.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Captured on this call"}),(0,t.jsx)("div",{className:"mt-1 grid grid-cols-1 gap-x-4 gap-y-0.5 sm:grid-cols-2",children:c.captures.map((e,a)=>(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:e.field})," ",(0,t.jsx)("b",{children:"string"==typeof e.value?e.value:JSON.stringify(e.value)})]},a))})]})]}),(0,t.jsxs)("div",{className:"max-h-80 overflow-y-auto rounded-lg border bg-card px-3 py-2 text-[12.5px] leading-relaxed",children:[(0,t.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Transcript"}),0===c.transcript.length&&(0,t.jsx)("div",{className:"text-muted-foreground",children:"No transcript stored."}),c.transcript.map((e,a)=>(0,t.jsxs)("div",{className:"mt-1",children:[(0,t.jsx)("span",{className:"mr-1 font-medium ".concat("customer"===e.role.toLowerCase()?"text-sky-700":"text-emerald-700"),children:e.role||"\xb7"}),(0,t.jsx)("span",{children:e.text})]},a))]})]}):(0,t.jsx)("div",{className:"px-4 py-3 text-[12.5px] text-muted-foreground",children:"Loading callâ¦"})}function M(e){var a;let{points:s,label:n,unit:r,max:i,tone:d}=e,[c,o]=(0,l.useState)(null),u=s.map(e=>e.v).filter(e=>null!=e),x=null!=i?i:Math.max(1,...u),m=e=>3+(s.length>1?e/(s.length-1)*214:0),p=e=>41-Math.min(e,x)/x*38,h=s.map((e,a)=>null==e.v?null:"".concat(0===a||null==s[a-1].v?"M":"L").concat(m(a).toFixed(1),",").concat(p(e.v).toFixed(1))).filter(Boolean).join(" "),g=u.length?u[u.length-1]:null,j=null!=c?s[c]:null;return(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-baseline justify-between text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{children:n}),(0,t.jsx)("span",{className:"tabular-nums text-foreground",children:j?"".concat(null!==(a=j.v)&&void 0!==a?a:"â").concat(r," \xb7 ").concat(new Date(j.t).toLocaleTimeString("en-IN",{hour:"2-digit",minute:"2-digit"})):null!=g?"".concat(g).concat(r):"â"})]}),(0,t.jsxs)("svg",{viewBox:"0 0 ".concat(220," ").concat(44),className:"block h-11 w-full",onMouseLeave:()=>o(null),onMouseMove:e=>{let a=e.currentTarget.getBoundingClientRect(),t=Math.round((e.clientX-a.left)/a.width*(s.length-1));o(Math.max(0,Math.min(s.length-1,t)))},children:[(0,t.jsx)("line",{x1:3,x2:217,y1:41,y2:41,stroke:"currentColor",strokeOpacity:"0.15"}),(0,t.jsx)("path",{d:h,fill:"none",stroke:d,strokeWidth:"1.75",strokeLinejoin:"round",strokeLinecap:"round"}),j&&null!=j.v&&(0,t.jsx)("circle",{cx:m(c),cy:p(j.v),r:"3.5",fill:d,stroke:"var(--background, #fff)",strokeWidth:"2"}),!j&&null!=g&&(0,t.jsx)("circle",{cx:m(s.length-1),cy:p(g),r:"3",fill:d})]})]})}function R(){let[e,a]=(0,l.useState)(24),[s,n]=(0,l.useState)(null),[r,i]=(0,l.useState)(null),d=(0,l.useCallback)(async()=>{try{n(await b.infra(e)),i(null)}catch(e){i((0,v.getErrorMessage)(e,"Could not load infrastructure history"))}},[e]);(0,l.useEffect)(()=>{d();let e=setInterval(()=>{d()},6e4);return()=>clearInterval(e)},[d]);let c=e=>e<60?"".concat(e,"s"):e<3600?"".concat(Math.round(e/60)," min"):"".concat((e/3600).toFixed(1)," h"),o={node_down:"Media node down",redis_down:"Shared state store unreachable",originate_errors:"Carrier originate failures",control_restart:"Control plane restarted"};return(0,t.jsxs)("div",{className:"border-t",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-3 py-2 text-[12.5px]",children:[(0,t.jsx)("span",{className:"font-medium",children:"Resource usage & outages"}),(0,t.jsx)("div",{className:"ml-2 flex overflow-hidden rounded-md border text-[11.5px]",children:[6,24,168].map(s=>(0,t.jsx)("button",{type:"button",onClick:()=>a(s),className:"px-2 py-0.5 ".concat(e===s?"bg-foreground text-background":"bg-card hover:bg-muted"),children:168===s?"7 d":"".concat(s," h")},s))}),s&&(0,t.jsxs)("span",{className:"ml-auto text-muted-foreground",children:["availability ",(0,t.jsxs)("b",{className:"tabular-nums ".concat(s.availability_pct<99.5?"text-amber-700":"text-emerald-700"),children:[s.availability_pct.toFixed(2),"%"]})," \xb7 sampled every ",s.bucket_minutes," min"]})]}),r&&(0,t.jsx)("div",{className:"px-3 pb-2 text-[12px] text-rose-700",children:r}),s&&0===s.series.length&&(0,t.jsx)("div",{className:"px-3 pb-3 text-[12px] text-muted-foreground",children:"No samples yet â the monitor writes its first row a minute after the control plane starts."}),s&&s.series.length>0&&(0,t.jsx)("div",{className:"grid grid-cols-1 gap-2 px-2 pb-2 lg:grid-cols-3",children:s.series.map(e=>{var a;return(0,t.jsxs)("div",{className:"rounded-lg border px-3 py-2",children:[(0,t.jsxs)("div",{className:"mb-1 text-[12.5px] font-medium",children:[e.node," ",(0,t.jsxs)("span",{className:"text-[11px] font-normal text-muted-foreground",children:["control"
1===e.role?"control plane":"media node",e.cpus?" \xb7 ".concat(e.cpus," cpu"):""]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-3 lg:grid-cols-1 xl:grid-cols-3",children:[(0,t.jsx)(M,{label:"active calls",unit:"",points:e.points.map(e=>({t:e.t,v:e.live})),tone:"#0E6E8C"}),(0,t.jsx)(M,{label:"load / cpu",unit:"",max:Math.max(1,null!==(a=e.cpus)&&void 0!==a?a:1),points:e.points.map(e=>({t:e.t,v:e.load1})),tone:"#5B4A9E"}),(0,t.jsx)(M,{label:"memory",unit:"%",max:100,points:e.points.map(e=>({t:e.t,v:e.mem_pct})),tone:"#B7791F"})]})]},e.node)})}),s&&(0,t.jsx)("div",{className:"overflow-x-auto border-t",children:(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"Outage / event"}),(0,t.jsx)(f.ss,{children:"Server"}),(0,t.jsx)(f.ss,{children:"Started"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Duration"}),(0,t.jsx)(f.ss,{children:"Detail"})]})}),(0,t.jsxs)(f.RM,{children:[0===s.events.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:5,className:"text-center text-[12px] text-muted-foreground",children:"No outages in this window"})}),s.events.map(e=>{var a,s,l;return(0,t.jsxs)(f.SC,{className:e.ended_at?"":"bg-rose-50/60",children:[(0,t.jsxs)(f.pj,{className:"text-[12.5px]",children:[(0,t.jsx)("span",{className:"mr-1.5 inline-block h-2 w-2 rounded-full ".concat("control_restart"===e.kind?"bg-sky-500":e.ended_at?"bg-muted-foreground/50":"bg-rose-500")}),null!==(a=o[e.kind])&&void 0!==a?a:e.kind,e.ended_at?"":(0,t.jsx)("span",{className:"ml-1 text-[11px] text-rose-700",children:"ongoing"})]}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:null!==(s=e.node)&&void 0!==s?s:"â"}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:D(e.started_at)}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px]",children:"control_restart"===e.kind?"â":c(e.duration_s)}),(0,t.jsx)(f.pj,{className:"text-[12px] text-muted-foreground",children:null!==(l=e.detail)&&void 0!==l?l:""})]},e.id)})]})]})})]})}let A=e=>e.toISOString().slice(0,10);function E(e){var a,s,r,i;let{ops:d,metered:c}=e,[o,u]=(0,l.useState)(30),[x,m]=(0,l.useState)(null),[p,h]=(0,l.useState)(null),[j,N]=(0,l.useState)(null),[y,w]=(0,l.useState)(!1),[_,k]=(0,l.useState)(!1),C=A(new Date),S=A(new Date(Date.now()-864e5*o)),z=(0,l.useCallback)(async()=>{try{let[e,a]=await Promise.all([b.statement(S,C),d?b.reconciliation(o):Promise.resolve(null)]);m(e),h(a),N(null)}catch(e){N((0,v.getErrorMessage)(e,"Could not load usage"))}},[S,C,o,d]);(0,l.useEffect)(()=>{z();let e=setInterval(()=>{z()},12e4);return()=>clearInterval(e)},[z]);let M=async()=>{w(!0);try{var e,a,s,t;let l=await b.reconcileNow(3);n.A.success(l.ok?"Reconciled: ".concat(null!==(a=l.carrier_rows)&&void 0!==a?a:0," carrier records, ").concat(null!==(s=null===(e=l.mediation)||void 0===e?void 0:e.carrier_only_metered)&&void 0!==s?s:0," recovered"):"Run failed: ".concat(null!==(t=l.error)&&void 0!==t?t:"unknown")),await z()}catch(e){n.A.error((0,v.getErrorMessage)(e,"Reconciliation failed"))}finally{w(!1)}},R=e=>null==e?"â":e>=60?"".concat(Math.floor(e/60),"m ").concat(e%60,"s"):"".concat(e,"s"),E=e=>e?new Date(e).toLocaleString("en-IN",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit",hour12:!1}):"â",L=null==p?void 0:null===(a=p.days)||void 0===a?void 0:a[0],D=null!==(r=null==p?void 0:null===(s=p.days)||void 0===s?void 0:s.filter(e=>"ok"!==e.status).length)&&void 0!==r?r:0,I=e=>"ok"===e?"bg-emerald-500":"drift"===e?"bg-amber-500":"bg-rose-500",P={carrier_confirmed:"carrier confirmed",carrier_only:"recovered from carrier",drift:"duration drift",short_answered:"answered under 3 s",over_cap:"over the 12-min cap",no_carrier_record:"no carrier record after 48 h"},F=null!==(i=null==x?void 0:x.rows)&&void 0!==i?i:[],T=_?F:F.slice(0,25);return(0,t.jsxs)("div",{className:"rounded-xl border bg-card",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b px-3 py-2 text-[12.5px]",children:[(0,t.jsx)("span",{className:"font-medium",children:"Usage & audit"}),(0,t.jsx)("div",{className:"ml-2 flex overflow-hidden rounded-md border text-[11.5px]",children:[7,30,90].map(e=>(0,t.jsxs)("button",{type:"button",onClick:()=>u(e),className:"px-2 py-0.5 ".concat(o===e?"bg-foreground text-background":"bg-card hover:bg-muted"),children:[e," d"]},e))}),x&&(0,t.jsxs)("span",{className:"text-muted-foreground",children:[x.calls," billed calls \xb7 ",(0,t.jsx)("b",{className:"tabular-nums text-foreground",children:R(x.billed_seconds)})," connected \xb7 ",(0,t.jsx)("b",{className:"tabular-nums text-foreground",children:x.minutes.toLocaleStr
1ing("en-IN",{maximumFractionDigits:1})})," min",c?"":" (unmetered account)"]}),(0,t.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[d&&(0,t.jsx)(g.z,{size:"sm",variant:"outline",onClick:()=>void M(),disabled:y,children:y?"Reconcilingâ¦":"Reconcile now"}),(0,t.jsx)(g.z,{size:"sm",variant:"outline",onClick:()=>void b.statementXlsx(S,C).catch(e=>n.A.error((0,v.getErrorMessage)(e,"Export failed"))),children:"Statement .xlsx"})]})]}),j&&(0,t.jsx)("div",{className:"px-3 py-2 text-[12px] text-rose-700",children:j}),d&&p&&(0,t.jsxs)("div",{className:"border-b px-3 py-2",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1 text-[12px]",children:[(0,t.jsx)("span",{className:"font-medium",children:"Ledger vs carrier"}),(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] font-medium ".concat(0===D?"bg-emerald-50 text-emerald-700":"bg-rose-50 text-rose-700"),children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full ".concat(0===D?"bg-emerald-500":"bg-rose-500")}),0===D?"all ".concat(p.days.length," day(s) match"):"".concat(D," day(s) unmatched")]}),L&&(0,t.jsxs)("span",{className:"text-muted-foreground",children:["latest day ",L.day,": ",L.matched," matched \xb7 ",L.ours_only," ours-only \xb7 ",L.carrier_only," carrier-only \xb7 ",L.drift," drift (>",p.tolerance_s,"s) \xb7 ledger ",R(L.ledger_seconds)," vs carrier ",R(L.carrier_seconds)]}),(0,t.jsx)("span",{className:"ml-auto text-muted-foreground",children:p.last_run?(0,t.jsxs)(t.Fragment,{children:["last run ",E(p.last_run.started_at)," \xb7 ",!1===p.last_run.ok?(0,t.jsx)("span",{className:"text-rose-700",children:"failed"}):p.last_run.finished_at?"ok":"running"]}):"never run"})]}),p.days.length>0&&(0,t.jsx)("div",{className:"mt-2 flex items-end gap-[3px]",title:"one bar per day: ledger seconds; colour = reconciliation state",children:[...p.days].reverse().map(e=>{let a=Math.max(1,...p.days.map(e=>e.ledger_seconds)),s=Math.max(3,Math.round(28*e.ledger_seconds/a));return(0,t.jsx)("span",{className:"w-2 rounded-sm ".concat(I(e.status)),style:{height:s},title:"".concat(e.day,": ").concat(R(e.ledger_seconds)," ledger / ").concat(R(e.carrier_seconds)," carrier \xb7 ").concat(e.status)},e.day)})}),p.anomalies.length>0&&(0,t.jsxs)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[p.anomalies.slice(0,12).map(e=>(0,t.jsxs)("span",{className:"rounded-md border border-amber-200 bg-amber-50 px-1.5 py-0.5 text-[11px] text-amber-900",title:e.call_ref,children:[E(e.at)," \xb7 ",R(e.seconds)," \xb7 ",e.kinds.map(e=>{var a;return null!==(a=P[e])&&void 0!==a?a:e}).join(", ")]},e.call_ref+e.kinds.join())),p.anomalies.length>12&&(0,t.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:["+",p.anomalies.length-12," more"]})]})]}),(0,t.jsxs)("div",{className:"overflow-x-auto",children:[(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"Time"}),(0,t.jsx)(f.ss,{children:"Campaign"}),(0,t.jsx)(f.ss,{children:"Customer"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Billed"}),d&&(0,t.jsx)(f.ss,{className:"text-right",children:"Bridge"}),d&&(0,t.jsx)(f.ss,{className:"text-right",children:"Carrier"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Pulse"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Pulses"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Minutes"}),d&&(0,t.jsx)(f.ss,{children:"Source / flags"})]})}),(0,t.jsxs)(f.RM,{children:[0===F.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:d?10:7,className:"text-center text-[12px] text-muted-foreground",children:"No billed calls in this period"})}),T.map(e=>{var a,s,l,n;return(0,t.jsxs)(f.SC,{className:(null===(a=e.flags)||void 0===a?void 0:a.includes("carrier_only"))?"bg-amber-50/50":"",children:[(0,t.jsx)(f.pj,{className:"text-[12px] tabular-nums",children:E(e.at)}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:null!==(s=e.campaign)&&void 0!==s?s:(0,t.jsx)("span",{className:"text-muted-foreground",children:"â"})}),(0,t.jsxs)(f.pj,{className:"text-[12px]",children:[null!==(l=e.name)&&void 0!==l?l:""," ",(0,t.jsx)("span",{className:"tabular-nums text-muted-foreground",children:d?e.phone:e.phone_masked})]}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px]",children:R(e.billed_seconds)}),d&&(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px] text-muted-foreground",children:R(e.bridge_seconds)}),d&&(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px] ".concat(null==e.carrier_seconds?"text-rose-700":"text-muted-foreground"),children:null==e.carrier_seconds?"none":R(e.carrier_seconds)}),(0,t.jsxs)(f.pj,{className:"text-right tabular-nums text-[12px] text-muted-foreground",children:[e.pulse_seconds,"s"]}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px]",children:e.pulses}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px] font-medium",children:e.minutes.toFixed(1)}),d&&(0,t.jsxs)(f.pj,{className:"text-[11px] text-muted-foreground",children:[e.source,(null!==(n=e.flags)&&void 0!==n?n:[]).filter(e=>"carrier_confirmed"!==e).map(e=>{var a;return(0,t.jsx)("span",{className:"ml-1 rounded bg-amber-100 px-1 text-amber-900",children:null!==(a=P[e])&&void 0!==a?a:e},e)})]})]},e.call_ref)})]})]}),F.length>25&&(0,t.jsx)("div",{className:"border-t px-3 py-1.5 text-[12px]",children:(0,t.jsx)("button",{type:"button",className:"text-primary hover:underline",onClick:()=>k(e=>!e),children:_?"Show first 25":"Show all ".concat(F.length)})})]})]})}function L(){var e,a,s,r,i,d,c,o,u,x,m,p,h,j,N,y;let[_,S]=(0,l.useState)(null),[M,A]=(0,l.useState)(null),[L,I]=(0,l.useState)(!1),[P,F]=(0,l.useState)(null),T=(0,l.useCallback)(async()=>{try{S(await b.overview()),A(null)}catch(e){A((0,v.getErrorMessage)(e,"Could not load overview"))}},[]);(0,l.useEffect)(()=>{T();let e=setInterval(()=>{T()},1e4);return()=>clearInterval(e)},[T]);let Z=async()=>{let e=window.prompt("Add minutes to this workspace's plan (ops only):","0"),a=Number(e);if(e&&Number.isFinite(a)&&!(a<=0)){I(!0);try{await b.topup(a,void 0,"ops top-up from desk"),n.A.success("".concat(a," minutes added")),await T()}catch(e){n.A.error((0,v.getErrorMessage)(e,"Top-up failed"))}finally{I(!1)}}},O=async()=>{var e,a,s,t;let l=null==_?void 0:_.plan,r=window.prompt("Billing pulse in seconds for this plan (1, 6, 10, 15, 30 or 60). Current: ".concat(null!==(e=null==l?void 0:l.pulse_seconds)&&void 0!==e?e:"â","s. Applies from the next call; past calls keep their snapshot."),String(null!==(a=null==l?void 0:l.pulse_seconds)&&void 0!==a?a:60));if(null==r)return;let i=Number(r);
1if(![1,6,10,15,30,60].includes(i)){n.A.error("Pulse must be 1, 6, 10, 15, 30 or 60");return}let d=window.prompt("Calls at or under how many seconds are free? Current: ".concat(null!==(s=null==l?void 0:l.free_under_seconds)&&void 0!==s?s:"â","s"),String(null!==(t=null==l?void 0:l.free_under_seconds)&&void 0!==t?t:5));if(null==d)return;let c=Number(d);if(!Number.isFinite(c)||c<0){n.A.error("Enter 0 or more seconds");return}I(!0);try{await b.planTerms({pulse_seconds:i,free_under_seconds:c,note:"changed from desk"}),n.A.success("Pulse ".concat(i,"s \xb7 free under ").concat(c,"s")),await T()}catch(e){n.A.error((0,v.getErrorMessage)(e,"Could not change terms"))}finally{I(!1)}},B=async(e,a,s)=>{I(!0);try{let t=await a();n.A.success(s?s(t):e),await T()}catch(a){n.A.error((0,v.getErrorMessage)(a,"".concat(e," failed")))}finally{I(!1)}},q=async()=>{let e=window.prompt("STOP ALL CALLING for this workspace?\n\nEvery running campaign is paused and no new dial leaves, including client-API campaigns. Live calls finish on their own.\n\nReason (logged):","ops kill switch");null!=e&&await B("Kill switch",()=>b.kill(e),e=>"Halted â ".concat(e.campaigns_paused," campaign(s) paused, ").concat(e.live_calls_finishing," live call(s) finishing"))},U=async()=>{window.confirm("Lift the halt? Campaigns stay paused â resume them one by one.")&&await B("Halt lifted",()=>b.killClear())},H=async(e,a,s,t)=>{let l=window.prompt("".concat(s," (blank = no limit):"),null==t?"":String(t));if(null==l)return;let n=""===l.trim()?null:Number(l);(null==n||Number.isFinite(n))&&await B(s,()=>b.controls(e,{[a]:n}))};if(M)return(0,t.jsx)("div",{className:"rounded-xl border border-destructive/40 bg-destructive/5 p-3 text-[12.5px]",children:M});if(!_)return null;let V=_.queue_totals,W=_.plan,K=Math.min(100,Math.max(0,null!==(i=W.percent_used)&&void 0!==i?i:0)),X=e=>null==e?"â":e.toLocaleString("en-IN",{maximumFractionDigits:1});return(0,t.jsxs)("section",{className:"space-y-3",children:[W.metered&&(0,t.jsxs)("div",{className:"rounded-xl border bg-card px-4 py-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-end justify-between gap-2",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:["Prepaid minutes \xb7 ",W.sku," \xb7 ",(0,t.jsx)("span",{className:"active"===W.status?"text-emerald-700":"text-rose-700",children:W.status}),W.pulse_seconds?(0,t.jsxs)(t.Fragment,{children:[" \xb7 ",W.pulse_seconds,"-second pulse",W.free_under_seconds?" \xb7 free under ".concat(W.free_under_seconds," s"):"",null!=W.rate_per_min?" \xb7 â¹".concat(W.rate_per_min,"/min"):""]}):null]}),(0,t.jsxs)("div",{className:"text-[15px]",children:[(0,t.jsx)("b",{className:"text-xl font-semibold tabular-nums",children:X(W.minutes_consumed)}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:[" of ",X(W.minutes_purchased)," used \xb7 "]}),(0,t.jsx)("b",{className:"tabular-nums",children:X(W.minutes_remaining)}),(0,t.jsx)("span",{className:"text-muted-foreground",children:" remaining"})]})]}),(0,t.jsxs)("div",{className:"text-right text-[12px] text-muted-foreground",children:[(0,t.jsxs)("div",{children:[W.calls_metered," calls \xb7 avg ",null!==(d=W.avg_call_min)&&void 0!==d?d:"â"," min \xb7 today ",X(W.today_minutes)," min \xb7 burn ",X(W.burn_per_day_7d),"/day"]}),(0,t.jsxs)("div",{children:["validity ends ",D(null!==(c=W.validity_end)&&void 0!==c?c:null)," (",null!==(o=W.days_to_expiry)&&void 0!==o?o:"â"," days)",W.projected_exhaustion?" \xb7 projected exhaustion ".concat(W.projected_exhaustion):""]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[_.infra&&(0,t.jsx)(g.z,{size:"sm",variant:"outline",onClick:()=>void O(),disabled:L,children:"Terms"}),(0,t.jsx)(g.z,{size:"sm",variant:"outline",onClick:()=>void Z(),disabled:L,children:"Top up"})]})]}),(0,t.jsx)("div",{className:"mt-2 h-2 overflow-hidden rounded-full bg-muted",children:(0,t.jsx)("span",{className:"block h-full rounded-full bg-gradient-to-r ".concat(K>=90?"from-rose-400 to-rose-500":K>=75?"from-amber-400 to-orange-400":"from-emerald-400 to-teal-400"," transition-all duration-500"),style:{width:"".concat(K,"%")}})})]}),_.halted?(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-xl border-2 border-rose-400 bg-rose-50 px-4 py-3 text-[13px] text-rose-900",children:[(0,t.jsx)("span",{className:"text-lg",children:"â"}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsxs)("div",{className:"font-semibold",children:["CALLING HALTED â kill switch engaged ",D(_.halted.since),_.halted.by?" by ".concat(_.halted.by):""]}),(0,t.jsxs)("div",{className:"text-[12px]",children:[_.halted.reason||"no reason given"," \xb7 no dial leaves this workspace (client-API campaigns included) \xb7 ",_.live_calls," live call(s) finishing"]})]}),(0,t.jsx)(g.z,{size:"sm",variant:"outline",className:"border-rose-400 text-rose-900",onClick:()=>void U(),disabled:L,children:"Lift halt"})]}):(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-xl border bg-card px-4 py-2.5",children:[(0,t.jsx)("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Live queue"}),(0,t.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-4 gap-y-1 text-[12.5px]",children:[(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{className:"text-[17px] font-semibold tabular-nums ".concat(_.live_calls?"text-emerald-700":""),children:_.live_calls})," ",(0,t.jsxs)("span",{className:"text-muted-foreground",children:["on a call now / cap ",_.concurrency_cap]})]}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{className:"text-[17px] font-semibold tabular-nums",children:null!==(u=null==V?void 0:V.eligible)&&void 0!==u?u:0})," ",(0,t.jsx)("span",{className:"text-muted-foreground",children:"pending, dialable now"})]}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{className:"text-[17px] font-semibold tabular-nums",children:null!==(x=null==V?void 0:V.parked)&&void 0!==x?x:0})," ",(0,t.jsx)("span",{className:"text-muted-foreground",children:"parked for retry"})]}),(0,t.jsxs)("span",{children:[(0,t.jsx)("b",{className:"text-[17px] font-semibold tabular-nums",children:null!==(m=null==V?void 0:V.campaigns_running)&&void 0!==m?m:0})," ",(0,t.jsx)("span",{className:"text-muted-foreground",children:"campaigns running"})]})]}),(0,t.jsx)(g.z,{size:"sm",variant:"destructive",className:"ml-auto",onClick:()=>void q(),disabled:L,title:"Pause every campaign and refuse every new dial. Live calls finish.",children:"â Stop all calling"})]}),_.alerts.length>0&&(0,t.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-[12.5px] text-amber-800 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300",children:_.alerts.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsxs)("b",{children:[e.kind.replace("used_",""),"%"]})," \xb7 ",e.detail," \xb7 ",D(e.fired_at)]},e.kind+e.fired_at))}),_.stalled_campaigns.length>0&&(0,t.jsxs)("div",{className:"rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-[12.5px] text-rose-800",children:["Queue not draining (eligible rows waiting >
13 min with free capacity): ",_.stalled_campaigns.join(", ")]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4 lg:grid-cols-8",children:[(0,t.jsx)(C,{label:"Live calls",value:"".concat(_.live_calls," / ").concat(_.concurrency_cap),tone:_.live_calls?"text-emerald-700":""}),(0,t.jsx)(C,{label:"DID pool",value:_.did_pool.length}),(0,t.jsx)(C,{label:"Window",value:_.window.open_now?"open":"closed",tone:_.window.open_now?"text-emerald-700":"text-amber-700"}),(0,t.jsx)(C,{label:"Dials today",value:_.today.dials}),(0,t.jsx)(C,{label:"Connects today",value:_.today.connects}),(0,t.jsx)(C,{label:"Minutes today",value:X(_.today.minutes)}),(0,t.jsx)(C,{label:"Latency 24h",value:null!=_.latency_24h.median_s?"".concat(_.latency_24h.median_s.toFixed(1),"s \xb7 p90 ").concat(null===(e=_.latency_24h.p90_s)||void 0===e?void 0:e.toFixed(1),"s"):"â"}),(0,t.jsx)(C,{label:"Originate errors 1h",value:_.today.originate_errors_1h,tone:_.today.originate_errors_1h?"text-rose-700":""})]}),!_.window.open_now&&_.window.next_open&&(0,t.jsxs)("p",{className:"text-[12px] text-muted-foreground",children:["Calling window closed â next open ",D(_.window.next_open)," IST. Queued rows wait automatically."]}),_.infra&&(0,t.jsxs)("div",{className:"rounded-xl border bg-card",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 border-b px-3 py-2 text-[12.5px]",children:[(0,t.jsx)("span",{className:"font-medium",children:"Infrastructure"}),(null===(a=_.infra)||void 0===a?void 0:a.endpoint)&&(0,t.jsxs)("span",{className:"text-muted-foreground",children:["media endpoint ",(0,t.jsx)("code",{className:"rounded bg-muted px-1",children:_.infra.endpoint})]}),(null===(s=_.infra)||void 0===s?void 0:s.region)&&(0,t.jsx)("span",{className:"text-muted-foreground",children:_.infra.region}),(0,t.jsxs)("span",{className:"ml-auto text-muted-foreground",children:["active on media nodes ",null!==(p=null===(r=_.infra)||void 0===r?void 0:r.media_live)&&void 0!==p?p:0," \xb7 DIDs on a call: ",0===Object.keys(null!==(h=_.did_leases)&&void 0!==h?h:{}).length?"none":Object.entries(null!==(j=_.did_leases)&&void 0!==j?j:{}).map(e=>{let[a,s]=e;return"â¦".concat(a.slice(-4)," (").concat(s,")")}).join(", ")]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-2 p-2 sm:grid-cols-2 lg:grid-cols-3",children:[[..._.control_plane?[_.control_plane]:[],...null!==(N=_.nodes)&&void 0!==N?N:[]].map(e=>{let a=Date.now()/1e3-(e.ts||0)>20,s=null!=e.load1&&e.cpus?e.load1/e.cpus:null,l=null==e.mem_pct?"":e.mem_pct>85?"text-rose-700":e.mem_pct>70?"text-amber-700":"";return(0,t.jsxs)("div",{className:"rounded-lg border px-3 py-2 ".concat(e.draining?"border-amber-300 bg-amber-50/50":a?"border-rose-300 bg-rose-50/50":""),children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-[12.5px] font-medium",children:[(0,t.jsx)("span",{className:"h-2 w-2 rounded-full ".concat(e.draining?"bg-amber-500":a?"bg-rose-500":"bg-emerald-500")}),e.node,(0,t.jsx)("span",{className:"ml-auto text-[11px] font-normal text-muted-foreground",children:"control"===e.role?"API \xb7 queue \xb7 webhooks":"media \xb7 voice stream + AI"})]}),(0,t.jsxs)("div",{className:"mt-1 grid grid-cols-3 gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-[15px] font-semibold tabular-nums ".concat(e.live?"text-emerald-700":"text-foreground"),children:e.live}),"active calls"]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"text-[15px] font-semibold tabular-nums ".concat(null==s?"":s>.8?"text-rose-700":s>.5?"text-amber-700":"text-emerald-700"),children:[null!=e.load1?e.load1.toFixed(2):"â",(0,t.jsx)("span",{className:"text-[11px] font-normal",children:e.cpus?" / ".concat(e.cpus," cpu"):""})]}),"load 1m"]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"text-[15px] font-semibold tabular-nums ".concat(l),children:[null!=e.mem_pct?"".concat(e.mem_pct,"%"):"â",(0,t.jsx)("span",{className:"text-[11px] font-normal",children:e.mem_gb?" of ".concat(e.mem_gb," GB"):""})]}),"memory"]})]}),e.draining&&(0,t.jsx)("div",{className:"mt-1 text-[11px] text-amber-700",children:"draining â no new calls, live ones finish"}),a&&!e.draining&&(0,t.jsxs)("div",{className:"mt-1 text-[11px] text-rose-700",children:["no heartbeat for ",Math.round(Date.now()/1e3-(e.ts||0)),"s"]})]},e.node)}),!_.control_plane&&0===(null!==(y=_.nodes)&&void 0!==y?y:[]).length&&(0,t.jsx)("div",{className:"px-1 py-2 text-[12px] text-muted-foreground",children:"No heartbeat â single-box mode"})]}),(0,t.jsx)(R,{})]}),(0,t.jsx)(E,{ops:!!_.infra,metered:!!W.metered}),(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-3 xl:grid-cols-2",children:[(0,t.jsxs)("div",{className:"rounded-xl border bg-card",children:[(0,t.jsx)("div",{className:"border-b px-3 py-2 text-[12.5px] font-medium",children:"Queues"}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"Campaign"}),(0,t.jsx)(f.ss,{children:"State"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Eligible"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Parked"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Calling"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Done"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Total"}),(0,t.jsx)(f.ss,{children:"Controls"})]})}),(0,t.jsxs)(f.RM,{children:[0===_.campaigns.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:8,className:"text-center text-muted-foreground",children:"No active campaigns"})}),_.campaigns.map(e=>{var a,s;return(0,t.jsxs)(f.SC,{children:[(0,t.jsxs)(f.pj,{className:"text-[12.5px]",children:[e.name,e.paused_reason?(0,t.jsx)("div",{className:"text-[11px] text-amber-700",children:e.paused_reason}):null,(0,t.jsxs)("div",{className:"text-[11px] text-muted-foreground",children:["prio ",e.priority," \xb7 cap ",null!==(a=e.concurrency_cap)&&void 0!==a?a:"â"," \xb7 ",null!==(s=e.max_dials_per_minute)&&void 0!==s?s:"â","/m
1in",e.next_eligible?" \xb7 next retry ".concat(D(e.next_eligible)):""]})]}),(0,t.jsx)(f.pj,{children:(0,t.jsx)(w,{state:e.state})}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.eligible}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.parked}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.calling}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.completed+e.failed+e.skipped}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.total}),(0,t.jsx)(f.pj,{children:(0,t.jsxs)("div",{className:"flex flex-wrap gap-1",children:["running"===e.state?(0,t.jsx)(g.z,{size:"sm",variant:"outline",className:"h-6 px-2 text-[11px]",disabled:L,onClick:()=>void B("Paused",()=>b.pause(e.campaign_id,"paused from queue desk")),children:"Pause"}):"paused"===e.state||"draft"===e.state?(0,t.jsx)(g.z,{size:"sm",variant:"outline",className:"h-6 px-2 text-[11px]",disabled:L||!!_.halted,onClick:()=>void B("Running",()=>"draft"===e.state?b.start(e.campaign_id):b.resume(e.campaign_id)),children:"draft"===e.state?"Start":"Resume"}):null,(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L,title:"Higher priority dials first across campaigns",onClick:()=>void B("Priority",()=>{var a;return b.controls(e.campaign_id,{priority:(null!==(a=e.priority)&&void 0!==a?a:0)+1})}),children:"Prio +"}),(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L,onClick:()=>void B("Priority",()=>{var a;return b.controls(e.campaign_id,{priority:(null!==(a=e.priority)&&void 0!==a?a:0)-1})}),children:"Prio â"}),(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L,onClick:()=>void H(e.campaign_id,"concurrency_cap","Max simultaneous calls for this campaign",e.concurrency_cap),children:"Cap"}),(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L,onClick:()=>void H(e.campaign_id,"max_dials_per_minute","Max dials per minute for this campaign",e.max_dials_per_minute),children:"Pace"}),e.parked>0&&(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L,title:"Make every parked row dialable now",onClick:()=>void B("Retry now",()=>b.retryNow(e.campaign_id),e=>"".concat(e.released," row(s) released")),children:"Retry now"}),"running"===e.state&&e.eligible>0&&(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px]",disabled:L||!!_.halted,title:"Fill free slots immediately",onClick:()=>void B("Drain",()=>b.drain(e.campaign_id)),children:"Drain"}),"done"!==e.state&&(0,t.jsx)(g.z,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[11px] text-rose-700",disabled:L,onClick:()=>{window.confirm('Stop "'.concat(e.name,'" for good? ').concat(e.eligible+e.parked," pending row(s) will be skipped. Live calls finish."))&&B("Stopped",()=>b.stop(e.campaign_id,"stopped from queue desk"),e=>"Stopped â ".concat(e.skipped," row(s) skipped"))},children:"Stop"})]})})]},e.campaign_id)})]})]})})]}),(0,t.jsxs)("div",{className:"rounded-xl border bg-card",children:[(0,t.jsx)("div",{className:"border-b px-3 py-2 text-[12.5px] font-medium",children:"Recent calls"}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"When"}),(0,t.jsx)(f.ss,{children:"Lead"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Dur"}),(0,t.jsx)(f.ss,{children:"Outcome"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Latency"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Cost"}),(0,t.jsx)(f.ss,{children:"Rec"})]})}),(0,t.jsxs)(f.RM,{children:[0===_.recent_calls.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:7,className:"text-center text-muted-foreground",children:"No calls yet"})}),_.recent_calls.map(e=>{var a,s;return[(0,t.jsxs)(f.SC,{className:P===e.call_id?"bg-muted/40":"",children:[(0,t.jsx)(f.pj,{className:"text-[12px]",children:D(e.at)}),(0,t.jsx)(f.pj,{className:"text-[12.5px]",children:null!==(a=e.name)&&void 0!==a?a:"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:null!=e.duration_s?"".concat(Math.round(e.duration_s),"s"):"â"}),(0,t.jsx)(f.pj,{children:(0,t.jsx)(k,{d:null!==(s=e.disposition)&&void 0!==s?s:e.outcome})}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px]",children:null!=e.latency_median_s?"".concat(e.latency_median_s.toFixed(1),"s"):"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums text-[12px]",children:null!=e.cost_usd?"$".concat(e.cost_usd.toFixed(3)):"â"}),(0,t.jsx)(f.pj,{children:(0,t.jsx)(g.z,{size:"sm",variant:P===e.call_id?"secondary":"outline",className:"h-6 px-2 text-[11px]",onClick:()=>F(P===e.call_id?null:e.call_id),children:P===e.call_id?"Close":e.recording_url?"â¶ Play + transcript":"Transcript"})})]},e.call_id),P===e.call_id?(0,t.jsx)(f.SC,{className:"bg-muted/30 hover:bg-muted/30",children:(0,t.jsx)(f.pj,{colSpan:7,className:"p-0",children:(0,t.jsx)(z,{callId:e.call_id})})},e.call_id+":detail"):null]})]})]})})]})]})]})}let D=e=>
1e?new Date(e).toLocaleString("en-IN",{timeZone:"Asia/Kolkata",hour:"2-digit",minute:"2-digit",day:"2-digit",month:"short"}):"â";function I(){let[e,a]=(0,l.useState)(null);return((0,l.useEffect)(()=>{b.enabled().then(a)},[]),null===e)?(0,t.jsx)("div",{className:"flex items-center justify-center p-16 text-muted-foreground",children:(0,t.jsx)(d.Z,{className:"h-5 w-5 animate-spin"})}):e?(0,t.jsx)(P,{}):(0,t.jsx)("div",{className:"mx-auto max-w-xl p-8",children:(0,t.jsxs)("div",{className:"rounded-2xl border bg-card p-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-[15px] font-semibold",children:[(0,t.jsx)(i.Z,{className:"h-5 w-5 text-amber-600"})," Premium module"]}),(0,t.jsx)("p",{className:"mt-2 text-[13px] leading-relaxed text-muted-foreground",children:"Bulk AI calling for BFSI (campaigns, compliance gate, scripted flows, outcomes hand-back) is a premium module and is not enabled for this workspace. Contact your Bheemverse account manager to enable it."})]})})}function P(){var e,a,s,r,i,h,j,y,_,z,M,R,A,E,I,P,T,Z,O;let[B,q]=(0,l.useState)([]),[U,H]=(0,l.useState)(!0),[V,W]=(0,l.useState)(null),[K,X]=(0,l.useState)(null),[Q,G]=(0,l.useState)(null),[$,Y]=(0,l.useState)([]),[J,ee]=(0,l.useState)([]),[ea,es]=(0,l.useState)("rows"),[et,el]=(0,l.useState)(""),[en,er]=(0,l.useState)(null),[ei,ed]=(0,l.useState)(null),[ec,eo]=(0,l.useState)(!1),eu=(0,l.useRef)(null),ex=(0,l.useCallback)(async()=>{try{W(null);let e=await b.list();q(e),X(a=>{var s,t;return null!==(t=null!=a?a:null===(s=e[0])||void 0===s?void 0:s.id)&&void 0!==t?t:null})}catch(e){W((0,v.getErrorMessage)(e,"Could not load campaigns"))}finally{H(!1)}},[]),em=(0,l.useCallback)(async e=>{try{let[a,s]=await Promise.all([b.status(e),b.rows(e,et||void 0)]);G(a),Y(s)}catch(e){n.A.error((0,v.getErrorMessage)(e,"Could not load campaign"))}},[et]),ep=(0,l.useCallback)(async e=>{try{ee(await b.captures(e))}catch(e){n.A.error((0,v.getErrorMessage)(e,"Could not load outcomes"))}},[]);(0,l.useEffect)(()=>{ex()},[ex]),(0,l.useEffect)(()=>{K&&(ed(null),em(K),"outcomes"===ea&&ep(K))},[K,ea,em,ep]);let eh=(0,l.useMemo)(()=>{var e;return null!==(e=B.find(e=>e.id===K))&&void 0!==e?e:null},[B,K]),eg=null!==(i=null!==(r=null==Q?void 0:null===(e=Q.campaign)||void 0===e?void 0:e.state)&&void 0!==r?r:null==eh?void 0:eh.state)&&void 0!==i?i:"draft";(0,l.useEffect)(()=>(eu.current&&(clearInterval(eu.current),eu.current=null),K&&"running"===eg&&(eu.current=setInterval(()=>{em(K),ex()},5e3)),()=>{eu.current&&clearInterval(eu.current)}),[K,eg,em,ex]);let ej=async e=>{if(K){er(e),ed(null);try{"start"===e&&await b.start(K),"pause"===e&&await b.pause(K,"paused by operator"),"resume"===e&&await b.resume(K),n.A.success("pause"===e?"Campaign paused":"Campaign running â dialing inside the window and the gate"),await Promise.all([ex(),em(K)])}catch(s){let a=N(s);a?(ed(a),n.A.error("Not started â brand validation failed")):n.A.error((0,v.getErrorMessage)(s,"Could not ".concat(e)))}finally{er(null)}}},ef=async()=>{if(K&&eh){er("export");try{await b.exportXlsx(K,"".concat(eh.name.replace(/[^\w-]+/g,"_"),"_outcomes.xlsx"))}catch(e){n.A.error((0,v.getErrorMessage)(e,"Export failed"))}finally{er(null)}}},ev=(0,l.useMemo)(()=>B.reduce((e,a)=>({running:e.running+("running"===a.state?1:0),calling:e.calling+a.counts.calling,pending:e.pending+a.counts.pending,completed:e.completed+a.counts.completed}),{running:0,calling:0,pending:0,completed:0}),[B]),eb=null!==(h=null==Q?void 0:Q.statuses)&&void 0!==h?h:{},eN=Object.values(eb).reduce((e,a)=>e+a,0),ey=(null!==(j=eb.completed)&&void 0!==j?j:0)+(null!==(y=eb.failed)&&void 0!==y?y:0)+(null!==(_=eb.skipped)&&void 0!==_?_:0)+(null!==(z=eb.timeout)&&void 0!==z?z:0);return(0,t.jsxs)("div",{className:"mx-auto max-w-[1400px] space-y-4 p-4 md:p-5",children:[(0,t.jsxs)("header",{className:"flex flex-wrap items-end justify-between gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h1",{className:"text-xl font-semibold tracking-tight",children:"Call campaigns"}),(0,t.jsx)("p",{className:"mt-0.5 max-w-3xl text-[12.5px] leading-snug text-muted-foreground",children:"Upload a lead file, approve the validation report, start. Every dial passes the calling window and the consent gate; outcomes leave as one file."})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)(g.z,{variant:"outline",size:"sm",onClick:()=>void ex(),disabled:U,children:[U?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(c.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Refresh"})]}),(0,t.jsxs)(g.z,{size:"sm",onClick:()=>eo(!0),children:[(0,t.jsx)(o.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"New campaign"})]})]})]}),(0,t.jsxs)("section",{className:"flex flex-wrap items-center gap-x-5 gap-y-2 rounded-xl border bg-gradient-to-r from-sky-50/70 to-card px-4 py-2.5 dark:from-sky-950/25",children:[(0,t.jsxs)("span",{className:"text-[12.5px]",children:[(0,t.jsx)("b",{className:"text-lg font-semibold tabular-nums",children:ev.running})," running"]}),(0,t.jsxs)("span",{className:"text-[12.5px]",children:[(0,t.jsx)("b",{className:"text-lg font-semibold tabular-nums",children:ev.calling})," live calls"]}),(0,t.jsxs)("span",{className:"text-[12.5px]",children:[(0,t.jsx)("b",{className:"text-lg font-semibold tabular-nums",children:ev.pending})," waiting"]}),(0,t.jsxs)("span",{className:"text-[12.5px]",children:[(0,t.jsx)("b",{className:"text-lg font-semibold tabular-nums",children:ev.completed})," completed"]})]}),V&&(0,t.jsxs)("div",{className:"rounded-2xl border border-destructive/40 bg-destructive/5 p-5 text-sm",children:[V,(0,t.jsx)(g.z,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>void ex(),children:"Try again"})]}),(0,t.jsx)(L,{}),(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-[320px_minmax(0,1fr)]",children:[(0,t.jsxs)("aside",{className:"space-y-2",children:[0===B.length&&!U&&(0,t.jsx)("div",{className:"rounded-xl border border-dashed p-6 text-center text-[12.5px] text-muted-foreground",children:"No campaigns yet. Upload a lead file to create the first one."}),B.map(e=>{let a=e.counts.completed+e.counts.failed+e.counts.skipped,s=e.counts.total?Math.round(a/e.counts.total*100):0,l=e.id===K;return(0,t.jsxs)("button",{onClick:()=>{X(e.id),es("rows")},className:"relative w-full overflow-hidden rounded-xl border bg-card p-3 text-left transition hover:-translate-y-0.5 hover:shadow-md ".concat(l?"ring-2 ring-primary/40":""),children:[(0,t.jsx)("span",{className:"absolute inset-y-0 left-0 w-1 ".concat("running"===e.state?"bg-emerald-400":"paused"===e.state?"bg-amber-400":"bg-muted-foreground
1/30")}),(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2 pl-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"truncate text-[13.5px] font-medium",children:e.name}),(0,t.jsxs)("div",{className:"text-[11.5px] text-muted-foreground",children:[D(e.created_at)," \xb7 ",e.counts.total," leads"]})]}),(0,t.jsx)(w,{state:e.state})]}),(0,t.jsxs)("div",{className:"mt-2 flex items-center gap-2 pl-2",children:[(0,t.jsx)("span",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-muted",children:(0,t.jsx)("span",{className:"block h-full rounded-full bg-gradient-to-r from-emerald-400 to-teal-400 transition-all duration-500",style:{width:"".concat(s,"%")}})}),(0,t.jsxs)("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[s,"%"]})]})]},e.id)})]}),(0,t.jsx)("main",{className:"space-y-3",children:eh?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border bg-card px-4 py-3",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(u.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("h2",{className:"truncate text-[15px] font-semibold",children:eh.name}),(0,t.jsx)(w,{state:eg})]}),(null==Q?void 0:null===(a=Q.campaign)||void 0===a?void 0:a.paused_reason)&&"paused"===eg&&(0,t.jsx)("p",{className:"mt-0.5 text-[12px] text-amber-700",children:Q.campaign.paused_reason})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:["draft"===eg&&(0,t.jsxs)(g.z,{size:"sm",onClick:()=>void ej("start"),disabled:null!==en,children:["start"===en?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(x.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Start"})]}),"running"===eg&&(0,t.jsxs)(g.z,{size:"sm",variant:"outline",onClick:()=>void ej("pause"),disabled:null!==en,children:["pause"===en?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(m.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Pause"})]}),"paused"===eg&&(0,t.jsxs)(g.z,{size:"sm",onClick:()=>void ej("resume"),disabled:null!==en,children:["resume"===en?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(x.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Resume"})]}),(0,t.jsxs)(g.z,{size:"sm",variant:"outline",onClick:()=>void ef(),disabled:null!==en,children:["export"===en?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(p.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Export outcomes"})]})]})]}),ei&&(0,t.jsx)(S,{r:{ok:!1,failures:ei}}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6",children:[(0,t.jsx)(C,{label:"Progress",value:"".concat(eN?Math.round(ey/eN*100):0,"%")}),(0,t.jsx)(C,{label:"Live calls",value:null!==(M=eb.calling)&&void 0!==M?M:0,tone:"text-emerald-700"}),(0,t.jsx)(C,{label:"Waiting",value:null!==(R=eb.pending)&&void 0!==R?R:0}),(0,t.jsx)(C,{label:"Completed",value:null!==(A=eb.completed)&&void 0!==A?A:0}),(0,t.jsx)(C,{label:"Failed",value:(null!==(E=eb.failed)&&void 0!==E?E:0)+(null!==(I=eb.timeout)&&void 0!==I?I:0),tone:(null!==(P=eb.failed)&&void 0!==P?P:0)?"text-rose-700":""}),(0,t.jsx)(C,{label:"Skipped (gate)",value:null!==(T=eb.skipped)&&void 0!==T?T:0,tone:(null!==(Z=eb.skipped)&&void 0!==Z?Z:0)?"text-amber-700":""})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 text-[12px] text-muted-foreground",children:[(null==Q?void 0:null===(s=Q.retry_backlog)||void 0===s?void 0:s.parked)?(0,t.jsxs)("span",{className:"rounded-full bg-muted px-2 py-0.5",children:[Q.retry_backlog.parked," parked for retry \xb7 next ",D(Q.retry_backlog.next_eligible)]}):null,Object.entries(null!==(O=null==Q?void 0:Q.dispositions)&&void 0!==O?O:{}).map(e=>{let[a,s]=e;return(0,t.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,t.jsx)(k,{d:a}),(0,t.jsx)("span",{className:"tabular-nums",children:s})]},a)})]}),(0,t.jsxs)("div",{className:"rounded-xl border bg-card",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b px-3 py-2",children:[(0,t.jsx)("div",{className:"flex gap-1",children:["rows","outcomes"].map(e=>(0,t.jsx)("button",{onClick:()=>es(e),className:"rounded-md px-3 py-1 text-[12.5px] ".concat(ea===e?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-muted"),children:"rows"===e?"Dial queue":"Outcomes & captures"},e))}),"rows"===ea&&(0,t.jsxs)("select",{value:et,onChange:e=>el(e.target.value),className:"rounded-md border bg-background px-2 py-1 text-[12px]",children:[(0,t.jsx)("option",{value:"",children:"all statuses"}
1),["pending","calling","completed","failed","skipped","timeout"].map(e=>(0,t.jsx)("option",{value:e,children:e},e))]})]}),(0,t.jsx)("div",{className:"overflow-x-auto",children:"rows"===ea?(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"Lead"}),(0,t.jsx)(f.ss,{children:"Phone"}),(0,t.jsx)(f.ss,{children:"Status"}),(0,t.jsx)(f.ss,{children:"Disposition"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Attempts"}),(0,t.jsx)(f.ss,{children:"Next attempt"}),(0,t.jsx)(f.ss,{children:"Note"}),(0,t.jsx)(f.ss,{children:"Recording"})]})}),(0,t.jsxs)(f.RM,{children:[0===$.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:8,className:"text-center text-muted-foreground",children:"No rows"})}),$.map(e=>{var a;return(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.pj,{className:"text-[12.5px]",children:null!==(a=e.name)&&void 0!==a?a:"â"}),(0,t.jsx)(f.pj,{className:"font-mono text-[12px]",children:e.phone}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:e.status}),(0,t.jsx)(f.pj,{children:(0,t.jsx)(k,{d:e.disposition})}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:e.attempts}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:D(e.next_attempt_at)}),(0,t.jsx)(f.pj,{className:"max-w-[260px] truncate text-[11.5px] text-muted-foreground",title:e.note,children:e.note}),(0,t.jsx)(f.pj,{children:e.recording_url?(0,t.jsx)("a",{className:"text-sky-700 underline",href:e.recording_url,target:"_blank",rel:"noreferrer",children:"play"}):"â"})]},e.id)})]})]}):(0,t.jsxs)(f.iA,{children:[(0,t.jsx)(f.xD,{children:(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.ss,{children:"Lead"}),(0,t.jsx)(f.ss,{children:"Phone"}),(0,t.jsx)(f.ss,{children:"Outcome"}),(0,t.jsx)(f.ss,{children:"Interested"}),(0,t.jsx)(f.ss,{children:"Income source"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Monthly â¹"}),(0,t.jsx)(f.ss,{children:"Marital"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Spouse â¹"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Earners"}),(0,t.jsx)(f.ss,{className:"text-right",children:"Household â¹"})]})}),(0,t.jsxs)(f.RM,{children:[0===J.length&&(0,t.jsx)(f.SC,{children:(0,t.jsx)(f.pj,{colSpan:10,className:"text-center text-muted-foreground",children:"No captures yet â they appear as calls complete steps."})}),J.map(e=>{var a,s,l,n,r,i,d,c,o;return(0,t.jsxs)(f.SC,{children:[(0,t.jsx)(f.pj,{className:"text-[12.5px]",children:null!==(a=e.name)&&void 0!==a?a:"â"}),(0,t.jsx)(f.pj,{className:"font-mono text-[12px]",children:e.phone}),(0,t.jsx)(f.pj,{children:(0,t.jsx)(k,{d:null!==(s=e.disposition)&&void 0!==s?s:"completed"===e.status?"connected":null})}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:null!==(l=e.captures.interested)&&void 0!==l?l:"â"}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:null!==(n=e.captures.income_source)&&void 0!==n?n:"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:null!==(r=e.captures.monthly_income)&&void 0!==r?r:"â"}),(0,t.jsx)(f.pj,{className:"text-[12px]",children:null!==(i=e.captures.marital_status)&&void 0!==i?i:"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:null!==(d=e.captures.spouse_monthly_income)&&void 0!==d?d:"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:null!==(c=e.captures.other_earning_members)&&void 0!==c?c:"â"}),(0,t.jsx)(f.pj,{className:"text-right tabular-nums",children:null!==(o=e.household_income_total)&&void 0!==o?o:"â"})]},e.lead_id)})]})]})})]})]}):(0,t.jsx)("div",{className:"rounded-xl border border-dashed p-10 text-center text-[12.5px] text-muted-foreground",children:"Select a campaign to see its live board."})})]}),(0,t.jsx)(F,{open:ec,onClose:()=>eo(!1),onCreated:async(e,a)=>{eo(!1),await ex(),X(e.campaign_id),es("rows"),a&&n.A.success("Campaign running")}})]})}function F(e){let{open:a,onClose:s,onCreated:r}=e,[i,c]=(0,l.useState)([]),[u,m]=(0,l.useState)(""),[p,f]=(0,l.useState)(""),[y,w]=(0,l.useState)(null),[_,k]=(0,l.useState)(!1),[z,M]=(0,l.useState)(!1),[R,A]=(0,l.useState)(null),[E,L]=(0,l.useState)(null);(0,l.useEffect)(()=>{a&&(A(null),w(null),f(""),L(null),b.pipelines().then(e=>{c(e),e.length&&!u&&m(e[0].id)}).catch(e=>n.A.error((0,v.getErrorMessage)(e,"Could not load pipelines"))))},[a]);let D=async()=>
1{if(!y||!u){n.A.error("Choose a pipeline and a file");return}k(!0);try{let e=await b.upload(y,u,p||void 0);A(e),n.A.success("".concat(e.report.queued," leads queued as a draft"))}catch(l){var e,a,s;let t=null==l?void 0:null===(a=l.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail;(null==t?void 0:t.error)==="missing_phone_column"?n.A.error("No phone column. Columns seen: ".concat((null!==(s=t.columns_seen)&&void 0!==s?s:[]).join(", "))):n.A.error((0,v.getErrorMessage)(l,"Upload failed"))}finally{k(!1)}},I=async()=>{if(R){M(!0),L(null);try{await b.start(R.campaign_id),await r(R,!0)}catch(a){let e=N(a);e?L(e):n.A.error((0,v.getErrorMessage)(a,"Could not start"))}finally{M(!1)}}},P=i.find(e=>e.id===u),F=null==R?void 0:R.report;return(0,t.jsx)(j.Vq,{open:a,onOpenChange:e=>{e||s()},children:(0,t.jsxs)(j.cZ,{className:"max-w-2xl",children:[(0,t.jsxs)(j.fK,{children:[(0,t.jsx)(j.$N,{children:"New call campaign"}),(0,t.jsxs)(j.Be,{children:["Columns: ",(0,t.jsx)("code",{children:"phone"})," (required), name, language, product, branch, district, consent_source, consented_at. Rows without consent evidence are skipped by the gate on a promotional flow."]})]}),R?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[(0,t.jsx)(C,{label:"Rows",value:F.total_rows}),(0,t.jsx)(C,{label:"Queued",value:F.queued,tone:"text-emerald-700"}),(0,t.jsx)(C,{label:"Invalid phone",value:F.invalid_phone,tone:F.invalid_phone?"text-rose-700":""}),(0,t.jsx)(C,{label:"Duplicates",value:F.duplicates_in_file}),(0,t.jsx)(C,{label:"Consent recorded",value:F.consent_recorded}),(0,t.jsx)(C,{label:"Without consent",value:R.without_consent,tone:R.without_consent?"text-amber-700":""}),(0,t.jsx)(C,{label:"Suppressed (DNC)",value:F.suppressed,tone:F.suppressed?"text-rose-700":""}),(0,t.jsx)(C,{label:"Existing leads",value:F.existing_leads_reused})]}),(0,t.jsx)(S,{r:E?{ok:!1,failures:E}:R.brand_readiness})]}):(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("label",{className:"block text-[12.5px]",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Pipeline (flow, window, caller pool)"}),(0,t.jsx)("select",{value:u,onChange:e=>m(e.target.value),className:"mt-1 w-full rounded-md border bg-background px-2 py-1.5 text-sm",children:i.map(e=>{var a;return(0,t.jsxs)("option",{value:e.id,children:[e.name,e.has_settings?" \xb7 ".concat(e.calling_hours_start,"â").concat(e.calling_hours_end," \xb7 ").concat(null!==(a=e.agent_name)&&void 0!==a?a:""):" \xb7 no calling settings",e.flows?" \xb7 flow":""]},e.id)})})]}),P&&!P.has_settings&&(0,t.jsx)("p",{className:"text-[12px] text-amber-700",children:"This pipeline has no AI-calling settings â start will be refused until they exist."}),(0,t.jsxs)("label",{className:"block text-[12.5px]",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Campaign name (optional)"}),(0,t.jsx)("input",{value:p,onChange:e=>f(e.target.value),placeholder:"e.g. IL leads â Ernakulam batch 1",className:"mt-1 w-full rounded-md border bg-background px-2 py-1.5 text-sm"})]}),(0,t.jsxs)("label",{className:"flex cursor-pointer items-center gap-3 rounded-xl border border-dashed p-4 text-[12.5px] hover:bg-muted/40",children:[(0,t.jsx)(h.Z,{className:"h-5 w-5 text-muted-foreground"}),(0,t.jsx)("span",{className:"flex-1",children:y?"".concat(y.name," \xb7 ").concat((y.size/1024).toFixed(0)," KB"):"Choose a .xlsx or .csv lead file"}),(0,t.jsx)("input",{type:"file",accept:".xlsx,.xls,.csv",className:"hidden",onChange:e=>{var a,s;return w(null!==(s=null===(a=e.target.files)||void 0===a?void 0:a[0])&&void 0!==s?s:null)}})]})]}),(0,t.jsx)(j.cN,{children:R?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(g.z,{variant:"outline",onClick:()=>void r(R,!1),children:"Keep as draft"}),(0,t.jsxs)(g.z,{onClick:()=>void I(),disabled:z||!R.brand_readiness.ok||!(null==F?void 0:F.queued),children:[z?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(x.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Start dialing"})]})]}):(0,t.jsxs)(g.z,{onClick:()=>void D(),disabled:_||!y||!u,children:[_?(0,t.jsx)(d.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(o.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"ml-2",children:"Upload & validate"})]})})]})})}},12381:function(e,a,s){s.d(a,{d:function(){return d},z:function(){return c}});var t=s(57437),l=s(2265),n=s(37053),r=s(90535),i=s(93448);let d=(0,r.j)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-[4px] text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-[4px] px-3 text-xs",lg:"h-10 rounded-[4px] px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),c=l.forwardRef((e,a)=>{let{className:s,variant:l,size:r,asChild:c=!1,...o}=e,u=c?n.g7:"button";return(0,t.jsx)(u,{className:(0,i.cn)(d({variant:l,size:r,className:s})),ref:a,...o})});c.displayName="Button"},74291:function(e,a,s){s.d(a,{$N:function(){return h},Be:function(){return g},Vq:function(){return d},cN:function(){return p},cZ:function(){return x},fK:function(){return m},hg:function(){return c}});var t=s(57437),l=s(2265),n=s(49027),r=s(93448),i=s(20653);let d=n.fC,c=n.xz,o=n.h_;n.x8;let u=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(n.aV,{ref:a,className:(0,r.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...l})});u.displayName=n.aV.displayName;let x=l.forwardRef((e,a)=>{let{className:s,children:l,overlayClassName:d,...c}=e;return(0,t.jsxs)(o,{children:[(0,t.jsx)(u,{className:d}),(0,t.jsxs)(n.VY,{ref:a,className:(0,r.cn)("fixed left-[50%] top-[50%] z-50 translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200","w-[calc(100%-1rem)] xs:w-[calc(100%-2rem)] sm:w-full max-w-lg","p-4 sm:p-6","max-h-[90vh] sm:max-h-[85vh]","rounded-lg sm:rounded-lg","flex flex-col","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",s),...c,children:[l,(0,t.jsxs)(n.x8,{className:"absolute right-3 top-3 sm:right-4 sm:top-4 z-50 rounded-full opacity-70 ring-offset-background transition-all hover:opacity-100 hover:bg-gray-100 dark:hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground bg-white dark:bg-gray-900 shadow-md border border-gray-200 dark:border-gray-700 p-1.5",children:[(0,t.jsx)(i.Pxu,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});x.displayName=n.VY.displayName;let m=e=>{let{className:a,...s}=e;return(0,t.jsx)("div",{className:(0,r.cn)("flex flex-col space-y-1.5 text-center sm:text-left flex-shrink-0",a),...s})};m.displayName="DialogHeader";let p=e=>{let{className:a,...s}=e;return(0,t.jsx)("div",{className:(0,r.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 flex-shrink-0 mt-4",a),...s})};p.displayName="DialogFooter";let h=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(n.Dx,{ref:a,className:(0,r.cn)("font-display text-lg font-semibold leading-none tracking-tight",s),...l})});h.displayName=n.Dx.displayName;let g=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(n.dk,{ref:a,className:(0,r.cn)("text-sm text-muted-foreground",s),...l})});g.displayName=n.dk.displayName},33804:function(e,a,s){s.d(a,{RM:function(){return d},SC:function(){return c},iA:function(){return r},pj:function(){return u},ss:function(){return o},xD:function(){return i}});var t=s(57437),l=s(2265),n=s(93448);let r=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("div",{className:"relative w-full overflow-auto",children:(0,t.jsx)("table",{ref:a,className:(0,n.cn)("w-full caption-bottom text-sm",s),...l})})});r.displayName="Table";let i=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("thead",{ref:a,className:(0,n.cn)("[&_tr]:border-b",s),...l})});i.displayName="TableHeader";let d=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("tbody",{ref:a,className:(0,n.cn)("[&_tr:last-child]:border-0",s),...l})});d.displayName="TableBody",l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("tfoot",{ref:a,className:(0,n.cn)("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...l})}).displayName="TableFooter";let c=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("tr",{ref:a,className:(0,n.cn)("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...l})});c.displayName="TableRow";let o=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("th",{ref:a,className:(0,n.cn)("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s),...l})});o.displayName="TableHead";let u=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("td",{ref:a,className:(0,n.cn)("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...l})});u.displayName="TableCell",l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)("caption",{ref:a,className:(0,n.cn)("mt-4 text-sm text-muted-foreground",s),...l})}).displayName="TableCaption"},93448:function(e,a,s){s.d(a,{cn:function(){return n}});var t=s(61994),l=s(53335);function n(){for(var e=arguments.length,a=Array(e),s=0;s<e;s++)a[s]=arguments[s];return(0,l.m6)((0,t.W)(a))}}}]);
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.