1import{u as S,d as F,aa as H,J as k,ab as D,j as e,C as m,k as x,f,g as y,da as R,e as w,aV as V,aW as O,aX as A,aY as N,aZ as Y,a_ as b,H as U,B as T,r as v,db as z,D as J,q as W,a2 as Q,ap as G,aq as X,ar as Z,as as I,at as P,ak as q,E as ee,I as L,bq as se,t as ae,v as te,w as _,ay as ne,am as oe,x as C}from"./index-X4aSNaeS.js";import{u as le,s as ie}from"./useOutboundOrganization-B0RBMuG-.js";import{O as re}from"./OutboundOrgSelector-BG4OzvwX.js";import{o as p}from"./outboundApi-C56H_947.js";import{T as de}from"./trash-2-c6Wan5m4.js";import ce from"./OutboundConversations-DZprxJRd.js";import{U as M}from"./upload-DrQl997X.js";import{S as ue}from"./switch-CfX6Yh26.js";import{S as me}from"./save-Bk0-XIgS.js";import"./useOrganizationPartners-DG2j9JXd.js";const xe=({selectedOrgId:a})=>{var n;const{t:s}=S(),{toast:r}=F(),j=H(),{data:t,isLoading:h,error:c}=k({queryKey:["outbound-playbooks",a],queryFn:()=>p.getPlaybooks(a),enabled:!!a}),g=D({mutationFn:l=>p.deletePlaybook(l,a),onSuccess:()=>{r({title:s("outbound.playbookDeleted","Playbook deleted")}),j.invalidateQueries({queryKey:["outbound-playbooks",a]})},onError:l=>r({title:s("outbound.deleteError","Delete failed"),description:l.message,variant:"destructive"})});return a?e.jsxs(m,{children:[e.jsx(f,{children:e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),s("outbound.playbooks","Playbooks")]})}),e.jsx(x,{children:h?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(w,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):c?e.jsx("p",{className:"text-center py-12 text-destructive",children:s("outbound.loadError","Failed to load data. Check your API configuration.")}):e.jsxs(V,{children:[e.jsx(O,{children:e.jsxs(A,{children:[e.jsx(N,{children:s("outbound.name","Name")}),e.jsx(N,{children:s("outbound.tone","Tone")}),e.jsx(N,{children:s("outbound.questions","Questions")}),e.jsx(N,{children:s("outbound.maxAttempts","Max Attempts")}),e.jsx(N,{children:s("outbound.created","Created")}),e.jsx(N,{className:"text-right",children:s("outbound.actions","Actions")})]})}),e.jsx(Y,{children:(n=t==null?void 0:t.playbooks)!=null&&n.length?t.playbooks.map(l=>{var u,o;return e.jsxs(A,{children:[e.jsx(b,{className:"font-medium",children:l.name}),e.jsx(b,{children:e.jsx(U,{variant:"outline",children:l.tone||"default"})}),e.jsx(b,{children:(((u=l.mandatory_questions)==null?void 0:u.length)||0)+(((o=l.optional_questions)==null?void 0:o.length)||0)}),e.jsx(b,{children:l.default_max_attempts??"â"}),e.jsx(b,{children:new Date(l.created_at).toLocaleDateString()}),e.jsx(b,{className:"text-right",children:e.jsx(T,{size:"icon",variant:"ghost",onClick:()=>g.mutate(l.id),children:e.jsx(de,{className:"h-4 w-4"})})})]},l.id)}):e.jsx(A,{children:e.jsx(b,{colSpan:6,className:"text-center py-12 text-muted-foreground",children:s("outbound.noPlaybooks","No playbooks found")})})})]})})]}):e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-muted-foreground",children:s("outbound.selectOrgPrompt","Select an organization to view outbound data")})})},he=({selectedOrgId:a})=>{const{t:s}=S(),[r,j]=v.useState("30"),{data:t,isLoading:h,error:c}=k({queryKey:["outbound-analytics",a,r],queryFn:()=>p.getAnalytics(a,Number(r)),enabled:!!a}),g=[{label:s("outbound.totalCalls","Total Calls"),value:(t==null?void 0:t.total_calls)??"â",icon:z},{label:s("outbound.successRate","Success Rate"),value:t?`${Math.round(t.success_rate*100)}%`:"â",icon:J},{label:s("outbound.goalAchieved","Goal Achieved"),value:(t==null?void 0:t.goal_achieved_count)??"â",icon:W},{label:s("outbound.avgDuration","Avg Duration"),value:t?`${Math.round(t.avg_duration_seconds)}s`:"â",icon:Q}],n=t==null?void 0:t.sentiment_distribution,l=n?n.positive+n.neutral+n.negative:0;return a?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs(G,{value:r,onValueChange:j,children:[e.jsx(X,{className:"w-[120px]",children:e.jsx(Z,{})}),e.jsxs(I,{children:[e.jsxs(P,{value:"7",children:["7 ",s("outbound.days","days")]}),e.jsxs(P,{value:"30",children:["30 ",s("outbound.days","days")]}),e.jsxs(P,{value:"90",children:["90 ",s("outbound.days","days")]})]})]})}),h?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(w,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):c?e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-destructive",children:s("outbound.loadError","Failed to load data. Check your API configuration.")})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:g.map(u=>e.jsxs(m,{children:[e.jsxs(f,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:u.label}),e.jsx(u.icon,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(x,{children:e.jsx("div",{className:"text-2xl font-bold",children:u.value})})]},u.label))}),e.jsxs(m,{children:[e.jsx(f,{children:e.jsx(y,{children:s("outbound.sentimentDistribution","Sentiment Distribution")})}),e.jsx(x,{children:n&&l>0?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex h-4 rounded-full overflow-hidden bg-muted",children:[e.jsx("div",{className:"bg-green-500",style:{width:`${n.positive/l*100}%`}}),e.jsx("div",{className:"bg-yellow-500",style:{width:`${n.neutral/l*100}%`}}),e.jsx("div",{className:"bg-red-500",style:{width:`${n.negative/l*100}%`}})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-3 w-3 rounded-full bg-green-500"}),s("outbound.positive","Positive")," (",n.positive,")"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-3 w-3 rounded-full bg-yellow-500"}),s("outbound.neutral","Neutral")," (",n.neutral,")"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-3 w-3 rounded-full bg-red-500"}),s("outbound.negative","Negative")," (",n.negative,")"]})]})]}):e.jsx("p",{className:"text-center py-6 text-muted-foreground",children:s("outbound.noSentimentData","No sentiment data available")})})]})]})]}):e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-muted-foreground",children:s("outbound.selectOrgPrompt","Select an organization to view outbound data")})})},je=({selectedOrgId:a})=>{const{t:s}=S(),{toast:r}=F(),j=v.useRef(null),[t,h]=v.useState([]),[c,g]=v.useState(null),n=D({mutationFn:async o=>{const i=await o.arrayBuffer(),d=btoa(String.fromCharCode(...new Uint8Array(i)));return p.uploadDocument({file_base64:d,file_name:o.name,content_type:o.type},a)},onSuccess:o=>{h(i=>[...i,o.document_url]),r({title:s("outbound.uploadSuccess","Document uploaded"),description:o.file_name})},onError:o=>r({title:s("outbound.uploadError","Upload failed"),description:o.message,variant:"destructive"})}),l=D({mutationFn:()=>p.extractFromDocument(t,a),onSuccess:o=>
1{g(o),r({title:s("outbound.extractionComplete","Extraction complete")})},onError:o=>r({title:s("outbound.extractionError","Extraction failed"),description:o.message,variant:"destructive"})}),u=o=>{var d;const i=(d=o.target.files)==null?void 0:d[0];i&&n.mutate(i)};return a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-end",children:[e.jsx("input",{ref:j,type:"file",accept:".pdf,.png,.jpg,.jpeg",className:"hidden",onChange:u}),e.jsxs(T,{disabled:n.isPending,onClick:()=>{var o;return(o=j.current)==null?void 0:o.click()},children:[n.isPending?e.jsx(w,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(M,{className:"h-4 w-4 mr-2"}),s("outbound.uploadDocument","Upload Document")]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(m,{children:[e.jsx(f,{children:e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-5 w-5"}),s("outbound.uploadedDocuments","Uploaded Documents")]})}),e.jsx(x,{children:t.length?e.jsxs("div",{className:"space-y-2",children:[t.map((o,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-sm p-2 rounded bg-muted",children:[e.jsx(q,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:o.split("/").pop()})]},i)),e.jsxs(T,{className:"w-full mt-3",onClick:()=>l.mutate(),disabled:l.isPending,children:[l.isPending?e.jsx(w,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ee,{className:"h-4 w-4 mr-2"}),s("outbound.extractData","Extract Data with AI")]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:s("outbound.noDocuments","No documents uploaded yet. Upload PDF or image files (up to 10 MB).")})})]}),e.jsxs(m,{children:[e.jsx(f,{children:e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),s("outbound.aiExtraction","AI Extraction Results")]})}),e.jsx(x,{children:c?e.jsx("pre",{className:"text-xs overflow-auto whitespace-pre-wrap max-h-[400px] text-muted-foreground",children:JSON.stringify(c,null,2)}):e.jsx("p",{className:"text-sm text-muted-foreground",children:s("outbound.noExtractionYet","Upload documents and click 'Extract Data' to see AI-powered results.")})})]})]})]}):e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-muted-foreground",children:s("outbound.selectOrgPrompt","Select an organization to view outbound data")})})},B=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],pe=({selectedOrgId:a})=>{const{t:s}=S(),{toast:r}=F(),j=H(),[t,h]=v.useState([]),{data:c,isLoading:g}=k({queryKey:["outbound-hours",a],queryFn:()=>p.getBusinessHours(a),enabled:!!a}),{data:n,isLoading:l}=k({queryKey:["outbound-usage",a],queryFn:()=>p.getUsage(a),enabled:!!a});v.useEffect(()=>{c!=null&&c.business_hours?h(c.business_hours):h(B.map((i,d)=>({day_of_week:d,open_time:"08:00",close_time:"18:00",is_active:d>0&&d<6})))},[c]);const u=D({mutationFn:()=>p.updateBusinessHours(t,a),onSuccess:()=>{r({title:s("outbound.hoursSaved","Business hours saved")}),j.invalidateQueries({queryKey:["outbound-hours",a]})},onError:i=>r({title:s("outbound.saveError","Save failed"),description:i.message,variant:"destructive"})}),o=(i,d,K)=>{h($=>$.map(E=>E.day_of_week===i?{...E,[d]:K}:E))};return a?e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(m,{children:[e.jsxs(f,{className:"flex flex-row items-center justify-between",children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"h-5 w-5"}),s("outbound.businessHours","Business Hours")]}),e.jsxs(T,{size:"sm",onClick:()=>u.mutate(),disabled:u.isPending,children:[e.jsx(me,{className:"h-4 w-4 mr-1"}),s("outbound.save","Save")]})]}),e.jsx(x,{children:g?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(w,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-2",children:t.map(i=>e.jsxs("div",{className:"flex items-center gap-2 py-1",children:[e.jsx(ue,{checked:i.is_active,onCheckedChange:d=>o(i.day_of_week,"is_active",d)}),e.jsx("span",{className:"w-24 text-sm font-medium",children:B[i.day_of_week]}),i.is_active?e.jsxs(e.Fragment,{children:[e.jsx(L,{type:"time",value:i.open_time,onChange:d=>o(i.day_of_week,"open_time",d.target.value),className:"w-28 h-8 text-xs"}),e.jsx("span",{className:"text-muted-foreground",children:"â"}),e.jsx(L,{type:"time",value:i.close_time,onChange:d=>o(i.day_of_week,"close_time",d.target.value),className:"w-28 h-8 text-xs"})]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("outbound.closed","Closed")})]},i.day_of_week))})})]}),e.jsxs(m,{children:[e.jsx(f,{children:e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-5 w-5"}),s("outbound.usageQuotas","Usage & Quotas")]})}),e.jsx(x,{children:l?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(w,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n!=null&&n.tenant?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-sm",children:s("outbound.plan","Plan")}),e.jsx(U,{variant:"outline",children:n.tenant.subscription_plan})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:s("outbound.callsUsed","Calls Used")}),e.jsxs("span",{children:[n.tenant.trial_calls_used," / ",n.tenant.trial_calls_limit]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:"bg-primary rounded-full h-2 transition-all",style:{width:`${Math.min(n.tenant.trial_calls_used/n.tenant.trial_calls_limit*100,100)}%`}})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:s("outbound.noUsageData","No usage data available")})})]})]}):e.jsx(m,{children:e.jsx(x,{className:"py-12 text-center text-muted-foreground",children:s("outbound.selectOrgPrompt","Select an organization to view outbound data")})})},ke=()=>{const{t:a}=S(),{organizations:s,selectedOrgId:r,setSelectedOrgId:j,selectedOrg:t,isLoading:h}=le();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:a("outbound.agents","Outbound Agents")}),e.jsx("p",{className:"text-muted-foreground",children:a("outbound.agentsDesc","Configure and manage outbound AI agents â playbooks, conversations, analytics, and settings")})]}),t&&e.jsx(U,{variant:"outline",className:"text-xs",children:ie(t.segment)})]}),e.jsx(re,{organizations:s,selectedOrgId:r,onSelect:j,isLoading:h})]}),e.jsxs(ae,{defaultValue:"playbooks",className:"space-y-4",children:[e.jsxs(te,{className:"grid w-full grid-cols-5",children:[e.jsxs(_,{value:"playbooks",className:"flex items-center gap-1.5",children:[e.jsx(R,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:a("outbound.playbooks","Playbooks")})]}),e.jsxs(_,{value:"conversations",className:"flex items-center gap-1.5",children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:a("outbound.conversations","Conversations")})]}),e.jsxs(_,{value:"analytics",className:"flex items-center gap-1.5",children:[e.jsx(z,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:a("outbound.analytics","Analytics")})]}),e.jsxs(_,{value:"documents",className:"flex items-center gap-1.5",children:[e.jsx(q,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:a("outbound.documents","Documents")})]}),e.jsxs(_,{value:"settings",className:"flex items-center gap-1.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:a("outbound.settings","Settings")})]})]}),e.jsx(C,{value:"playbooks",children:e.jsx(xe,{selectedOrgId:r})}),e.jsx(C,{value:"conversations",children:e.jsx(ce,{selectedOrgId:r})}),e.jsx(C,{value:"analytics",children:e.jsx(he,{selectedOrgId:r})}),e.jsx(C,{value:"documents",children:e.jsx(je,{selectedOrgId:r})}),e.jsx(C,{value:"settings",children:e.jsx(pe,{selectedOrgId:r})})]})]})};export{ke 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.