PageSourceSearch

https://www.skyringai.com/assets/AdminLeads-CFWtCIhP.js

js skyringai.com collected 2026-10-07 03:08:30 UTC 43,905 bytes, 24 lines download raw bytes

1import{j as e}from"./vendor-ui-Bxj8wnBw.js";import{r as i}from"./vendor-react-BKm_nskA.js";import{u as fs}from"./useQuery-CGZ3Uohl.js";import{c as Ae,Y as _s,J as W,au as Me,Q as f,L as Ve,ar as ie,as as oe,at as ce,P as vs,X as Ie,a3 as w,Z as we,_ as ye,$ as Ce,a0 as ke,O as S,a6 as Se,a5 as Be,A as Ns,E as bs,K as ws,w as K}from"./index-B6y-6NMh.js";import{u as ys}from"./useMutation-C9oja-Zd.js";import{f as Cs}from"./recordingUrl-DcfeQLZ5.js";import{C as Q,a as Y,b as ks,c as Ss}from"./card-TCtUEEWn.js";import{B as de}from"./badge-D34NJrSA.js";import{S as V,a as I,b as B,c as q,d as h}from"./select-P6IcSvO8.js";import{C as Ms}from"./checkbox-Dn3Bg_g_.js";import{T as Ds,a as Rs,b as As,c as ae,d as Ps,e as O}from"./table-VLOLW4b3.js";import{T as Ls}from"./textarea-BTwRgUvI.js";import{S as F}from"./skeleton-B5RDaehc.js";import{S as qe}from"./scroll-area-G2el8_2B.js";import{S as Ts}from"./separator-C4rIprU1.js";import{D as Es,a as Fs,b as Os,c as re,d as zs}from"./dropdown-menu-CqnJmmm0.js";import{C as $s}from"./CallDetailModal-B3IhGViT.js";import{A as Us,a as Hs}from"./AdminStatStrip-DYJJjJhc.js";import{g as Vs}from"./getRoundingMethod-iQOF5t0h.js";import{a as Is,f as G}from"./format-C6Is-XON.js";import{d as Bs,f as Xe}from"./formatDistanceToNow-XUe5b9Cm.js";import{D as qs}from"./download-Dx4kCnQZ.js";import{R as Qs}from"./refresh-cw-qQgEtwR0.js";import{C as Ys}from"./calendar-BYTeeeEO.js";import{U as Je}from"./user-Dwkrmwvr.js";import{C as Qe}from"./clock-etltSATp.js";import{S as Ze}from"./star-v9-rl_Cd.js";import{A as Gs}from"./activity-j0hBP2_7.js";import{S as Ks}from"./search-BchNNWfg.js";import{C as De}from"./circle-check-big-_BKkKbRT.js";import{C as es}from"./circle-x-DwT7C_0T.js";import{P as Pe}from"./phone-bKAAdIzK.js";import{S as ss}from"./square-pen-CHJc35V_.js";import{C as Ws}from"./circle-alert-D2m_pFJ1.js";import{E as ts}from"./eye-D2aUhwc_.js";import{P as Xs}from"./phone-off-W2anvaCW.js";import{B as Js}from"./bot-hDsNcLMN.js";import{P as Zs}from"./phone-outgoing-B5ynbFk7.js";import{M as et}from"./message-square-DoTHa3LN.js";import{U as st}from"./users-yEFeK3F2.js";import{C as Ye}from"./copy-BrrH8IH-.js";import{P as Ge}from"./phone-call-knlF98Vw.js";import{E as tt}from"./ellipsis-CQWjxyXh.js";import{P as at}from"./pause-BfFq0rws.js";import{P as rt}from"./play-CCQXDzSu.js";import{V as lt}from"./volume-2-CRkOFn7r.js";import{C as nt}from"./index-DhMU-bfg.js";import{C as it}from"./chevron-down-DVCcfrm1.js";import{s as ot}from"./subDays-zfsdsliS.js";import{i as ct,a as dt}from"./isYesterday-xy20jGZY.js";import"./vendor-supabase-eX84kb_r.js";import"./vendor-charts-oAE8AkWo.js";import"./index-Pu3V9z69.js";import"./chevron-right-Djj0jpjl.js";import"./circle-BJYkuPit.js";import"./alert-dialog-D3sI1FWo.js";import"./index-CEYHIFQp.js";import"./slider-BSayR477.js";import"./CustomerAuthContext-DnFs-0Ik.js";import"./phoneUtils-eXBj7Pa4.js";import"./chevron-left-DiKFtxk2.js";import"./arrow-left-D6KtzfbU.js";import"./user-plus-CDRrkbR5.js";import"./sparkles-D1WMwIMr.js";import"./save-BC0wI7se.js";import"./constructFrom-rJN6zrQ_.js";import"./differenceInCalendarMonths-DdVU3xYm.js";import"./endOfMonth-CoG5-XNs.js";import"./isSameDay-CYrlpfit.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const mt=Ae("ArrowDownRight",[["path",{d:"m7 7 10 10",key:"1fmybs"}],["path",{d:"M17 7v10H7",key:"6fjiku"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const xt=Ae("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const ut=Ae("Voicemail",[["circle",{cx:"6",cy:"12",r:"4",key:"1ehtga"}],["circle",{cx:"18",cy:"12",r:"4",key:"4vafl8"}],["line",{x1:"6",x2:"18",y1:"16",y2:"16",key:"pmt8us"}]]);function ht(a,r,o){const d=Bs(a,r)/Is;return Vs(o?.roundingMethod)(d)}const Re={person:{icon:Je,label:"Person",color:"text-emerald-600 dark:text-emerald-400",bgColor:"bg-emerald-50 dark:bg-emerald-950/50 border-emerald-200 dark:border-emerald-800"},answering_service:{icon:xt,label:"Answering Service",color:"text-blue-600 dar
16k:text-blue-400",bgColor:"bg-blue-50 dark:bg-blue-950/50 border-blue-200 dark:border-blue-800"},voicemail:{icon:ut,label:"Voicemail",color:"text-violet-600 dark:text-violet-400",bgColor:"bg-violet-50 dark:bg-violet-950/50 border-violet-200 dark:border-violet-800"},bot:{icon:Js,label:"Bot/IVR",color:"text-amber-600 dark:text-amber-400",bgColor:"bg-amber-50 dark:bg-amber-950/50 border-amber-200 dark:border-amber-800"},no_answer:{icon:Zs,label:"No Answer",color:"text-slate-500 dark:text-slate-400",bgColor:"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"},busy:{icon:Pe,label:"Busy",color:"text-rose-600 dark:text-rose-400",bgColor:"bg-rose-50 dark:bg-rose-950/50 border-rose-200 dark:border-rose-800"},unknown:{icon:et,label:"Unknown",color:"text-slate-400 dark:text-slate-500",bgColor:"bg-slate-50 dark:bg-slate-900/50 border-slate-200 dark:border-slate-700"}},Ke={pending:{label:"Pending",color:"bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-300"},in_progress:{label:"In Progress",color:"bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-300"},completed:{label:"Completed",color:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300"},failed:{label:"Failed",color:"bg-rose-100 text-rose-700 dark:bg-rose-950 dark:text-rose-300"},no_answer:{label:"No Answer",color:"bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"},voicemail:{label:"Voicemail",color:"bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-300"}},pt=a=>{if(!a)return"";const r=a.replace(/\D/g,"");return r.length===10?`+1${r}`:r.length===11&&r.startsWith("1")?`+${r}`:r.startsWith("+")?a:`+${r}`},z=a=>{if(!a||a<=0)return"0s";if(a<60)return`${Math.round(a)}s`;const r=Math.floor(a/60),o=Math.round(a%60);if(r>=60){const d=Math.floor(r/60),_=r%60;return`${d}h ${_}m`}return o>0?`${r}m ${o}s`:`${r}m`},We=a=>{const r=new Date(a);return ct(r)?{primary:G(r,"h:mm a"),secondary:"Today"}:dt(r)?{primary:G(r,"h:mm a"),secondary:"Yesterday"}:{primary:G(r,"MMM d"),secondary:Xe(r,{addSuffix:!0})}},gt=(a,r)=>{const o=(a.result||"").toLowerCase(),d=(a.status||"").toLowerCase();return o.includes("voicemail")||d==="voicemail"?"voicemail":o.includes("answering")||o.includes("service")?"answering_service":o.includes("bot")||o.includes("automated")?"bot":d==="no_answer"?"no_answer":d==="busy"?"busy":d==="completed"&&(o.includes("scheduled")||o.includes("interested")||o.includes("spoke"))||r.length>0&&(r[0].duration_seconds||0)>30?"person":"unknown"},jt=a=>typeof a=="boolean"?a:typeof a=="string"?a.toLowerCase()==="true":!1,as=({outcome:a})=>{const r=Re[a],o=r.icon;return e.jsxs("span",{className:w("inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium border transition-colors",r.bgColor,r.color),children:[e.jsx(o,{className:"h-3 w-3"}),r.label]})},ft=({status:a})=>{const o=Ke[a||"pending"]||Ke.pending;return e.jsx("span",{className:w("inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",o.color),children:o.label})},ne=({rating:a,size:r="sm"})=>{if(!a)return e.jsx("span",{className:"text-muted-foreground text-xs italic",children:"Unrated"});const o=r==="sm"?"h-3 w-3":"h-4 w-4";return e.jsxs("div",{className:"flex items-center gap-0.5",children:[[1,2,3,4,5].map(d=>e.jsx(Ze,{className:w(o,"transition-colors",d<=a?"fill-amber-400 text-amber-400":"text-slate-200 dark:text-slate-700")},d)),r==="md"&&e.jsxs("span",{className:"ml-1.5 text-sm font-medium text-muted-foreground",children:[a,"/5"]})]})},le=({title:a,value:r,icon:o,description:d,trend:_,trendValue:g,highlight:L,className:N})=>e.jsx("div",{className:"animate-in fade-in slide-in-from-bottom-2 duration-300",children:e.jsx(Q,{className:w("relative overflow-hidden transition-all duration-300 hover:shadow-md",L&&"ring-2 ring-emerald-500/20 bg-gradient-to-br from-emerald-50/50 to-transparent dark:from-emerald-950/20",N),children:e.jsxs(Y,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:a}),e.jsx("p",{className:"text-2xl font-bold tracking-tight",children:r}),d&&e.jsx("p",{className:"text-xs text-muted-foreground",children:d})]}),e.jsx("div",{className:w("p-2 rounded-lg",L?"bg-emerald-100 text-emerald-600 dark:bg-emerald-900/50 dark:text-emerald-400":"bg-slate-100 text-slate-600 dar
16k:bg-slate-800 dark:text-slate-400"),children:e.jsx(o,{className:"h-4 w-4"})})]}),_&&g&&e.jsxs("div",{className:"mt-2 flex items-center gap-1 text-xs",children:[_==="up"?e.jsx(Ns,{className:"h-3 w-3 text-emerald-500"}):_==="down"?e.jsx(mt,{className:"h-3 w-3 text-rose-500"}):null,e.jsx("span",{className:w("font-medium",_==="up"&&"text-emerald-600 dark:text-emerald-400",_==="down"&&"text-rose-600 dark:text-rose-400",_==="neutral"&&"text-muted-foreground"),children:g})]})]})})}),_t=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid gap-4 md:grid-cols-4 lg:grid-cols-5",children:Array.from({length:5}).map((a,r)=>e.jsx(Q,{children:e.jsxs(Y,{className:"p-4",children:[e.jsx(F,{className:"h-4 w-20 mb-2"}),e.jsx(F,{className:"h-8 w-16 mb-1"}),e.jsx(F,{className:"h-3 w-24"})]})},r))}),e.jsx(Q,{children:e.jsx(Y,{className:"p-6",children:e.jsx("div",{className:"space-y-4",children:Array.from({length:5}).map((a,r)=>e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(F,{className:"h-10 w-10 rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(F,{className:"h-4 w-48"}),e.jsx(F,{className:"h-3 w-32"})]}),e.jsx(F,{className:"h-6 w-20"}),e.jsx(F,{className:"h-6 w-16"})]},r))})})})]}),vt=({hasFilters:a,onClearFilters:r})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center animate-in fade-in zoom-in-95 duration-300",children:[e.jsx("div",{className:"rounded-full bg-slate-100 dark:bg-slate-800 p-4 mb-4",children:e.jsx(st,{className:"h-8 w-8 text-slate-400"})}),e.jsx("h3",{className:"text-lg font-semibold mb-1",children:a?"No matching leads":"No leads yet"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-sm mb-4",children:a?"Try adjusting your filters to find what you're looking for.":"Create a campaign and add contacts to get started with lead nurturing."}),a&&e.jsx(f,{variant:"outline",size:"sm",onClick:r,children:"Clear all filters"})]}),Nt=({lead:a,onView:r,onEdit:o,onViewCalls:d})=>{const[_,g]=i.useState(!1),L=async()=>{await navigator.clipboard.writeText(a.phone_number),g(!0),setTimeout(()=>g(!1),2e3),W.success("Phone number copied")},N=a.is_dnc===!0;return e.jsxs("tr",{className:w("group transition-colors animate-in fade-in duration-200 cursor-pointer",N?"bg-red-50 hover:bg-red-100 dark:bg-red-950/30 dark:hover:bg-red-950/50":"hover:bg-muted/50"),onClick:r,children:[e.jsx(O,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:w("h-9 w-9 rounded-full flex items-center justify-center text-sm font-medium relative",N?"bg-gradient-to-br from-red-100 to-red-200 dark:from-red-900 dark:to-red-800 text-red-700 dark:text-red-300":"bg-gradient-to-br from-slate-100 to-slate-200 dark:from-slate-800 dark:to-slate-700 text-slate-600 dark:text-slate-300"),children:[a.name.charAt(0).toUpperCase(),N&&e.jsx("div",{className:"absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 flex items-center justify-center",children:e.jsx(es,{className:"h-3 w-3 text-white"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:w("font-medium text-sm",N&&"text-red-700 dark:text-red-400"),children:a.name}),N&&e.jsx(de,{variant:"destructive",className:"text-[10px] px-1.5 py-0 h-4",children:"DNC"})]}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:e.jsxs("button",{onClick:y=>{y.stopPropagation(),L()},className:"hover:text-foreground transition-colors flex items-center gap-1",children:[a.phone_number,_?e.jsx(bs,{className:"h-3 w-3 text-emerald-500"}):e.jsx(Ye,{className:"h-3 w-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}),a.email&&e.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-[180px]",children:a.email})]})]})}),e.jsx(O,{children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-sm font-medium truncate max-w-[150px]",children:a.campaign_name}),e.jsx("div",{className:"text-xs text-muted-foreground truncate max-w-[150px]",children:a.customer_name})]})}),e.jsx(O,{children:e.jsx(as,{outcome:a.contact_outcome||"unknown"})}),e.jsx(O,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{children:e.jsxs(ie,{children:[e.jsx(oe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Pe,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:a.attempts||0})]})}),e.jsx(ce,{children:e.jsxs("p",{children:[a.attempts||0," call attempts"]})})]})}),a.call_history&&a.call_history.length>0&&e.jsx(f,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:y=>{y.stopPropagation(),d()},children:e.jsx(Ge,{className:"h-3.5 w-3.5"})})]})}),e.jsx(O,{children:a.avg_call_duration?e.jsx(Me,{children:e.jsxs(ie,{children:[e.jsx(oe,{children:e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:z(Math.round(a.avg_call_duration))}),e.jsx("span",{className:"text-muted-foreground text-xs ml-1",children:"avg"})]})}),e.jsxs(ce,{children:[e.jsxs("p",{children:["Total: ",z(a.total_call_duration||0)]}),e.jsxs("p",{children:[a.call_history?.length||0," calls"]})]})]})}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"—"})}),e.jsx(O,{children:a.last_attempt_at?e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:We(a.last_attempt_at).primary}),e.jsx("div",{className:"text-xs text-muted-foreground",children:We(a.last_attempt_at).secondary})]}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"Never"})}),e.jsx(O,{children:e.jsx(ne,{rating:a.call_rating})}),e.jsx(O,{children:a.appointment_scheduled?e.jsxs(de,{className:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300 border-0 gap-1",children:[e.jsx(De,{className:"h-3 w-3"}),"Scheduled"]}):a.result?e.jsx("span",{className:"text-sm text-muted-foreground truncate max-w-[100px] block",children:a.result}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"—"})}),e.jsx(O,{className:"text-right",onClick:y=>y.stopPropagation(),children:e.jsxs(Es,{children:[e.jsx(Fs,{asChild:!0,children:e.jsx(f,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(tt,{className:"h-4 w-4"})})}),e.jsxs(Os,{align:"end",className:"w-48",children:[e.jsxs(re,{onClick:r,children:[e.jsx(ts,{className:"h-4 w-4 mr-2"}),"View Details"]}
16),e.jsxs(re,{onClick:o,children:[e.jsx(ss,{className:"h-4 w-4 mr-2"}),"Edit Lead"]}),a.call_history&&a.call_history.length>0&&e.jsxs(re,{onClick:d,children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Call History"]}),e.jsx(zs,{}),a.phone_number&&e.jsxs(re,{onClick:L,children:[e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Copy Phone"]}),a.email&&e.jsxs(re,{onClick:()=>window.open(`mailto:${a.email}`),children:[e.jsx(ws,{className:"h-4 w-4 mr-2"}),"Send Email"]})]})]})})]})},bt=({callId:a})=>{const[r,o]=i.useState(!1),[d,_]=i.useState(!1),g=i.useRef(null),L=i.useRef(null);i.useEffect(()=>()=>{g.current&&g.current.pause(),L.current&&URL.revokeObjectURL(L.current)},[]);const N=async()=>{try{if(!g.current){_(!0);const y=await Cs(a);L.current=y;const M=new Audio(y);M.onended=()=>o(!1),g.current=M,_(!1)}r?(g.current.pause(),o(!1)):(await g.current.play(),o(!0))}catch(y){_(!1),o(!1),W.error(y instanceof Error?y.message:"Recording unavailable")}};return e.jsxs(f,{size:"sm",variant:"outline",onClick:N,disabled:d,className:"gap-1.5",children:[r?e.jsx(at,{className:"h-3 w-3"}):e.jsx(rt,{className:"h-3 w-3"}),e.jsx(lt,{className:"h-3 w-3"})]})},za=()=>{const a=_s(),[r,o]=i.useState(""),[d,_]=i.useState("all"),[g,L]=i.useState("all"),[N,y]=i.useState("all"),[M,Le]=i.useState("all"),[$,Te]=i.useState("all"),[D,X]=i.useState(1),[T,rs]=i.useState(50),[J,ls]=i.useState("last_attempt_at"),[ge,Ee]=i.useState("desc"),[n,me]=i.useState(null),[ns,Z]=i.useState(!1),[is,xe]=i.useState(!1),[os,ee]=i.useState(!1),[Fe,je]=i.useState(null),[cs,fe]=i.useState(!1),[ds,_e]=i.useState(!1),[C,se]=i.useState({notes:"",contact_outcome:"",call_rating:"none",is_dnc:!1}),{data:v,isLoading:ms,refetch:xs,isFetching:Oe}=fs({queryKey:["admin-leads"],queryFn:async()=>{const{data:s,error:t}=await K.from("campaign_contacts").select(`
17          *,
18          outbound_campaigns!inner(
19            name,
20            customer_id,
21            customers(company_name)
22          )
23        `).order("last_attempt_at",{ascending:!1,nullsFirst:!1});if(t)throw t;const x=new Map;s?.forEach(l=>{if(l.phone_number){const u=pt(l.phone_number);u&&u.length>=10&&x.set(u,l.phone_number)}});const j=Array.from(x.keys()),{data:E}=await K.from("call_analytics").select("*").in("from_number",j.length>0?j:["__none__"]).order("call_date",{ascending:!1}),k=new Map,m=new Map,A=new Map;return E?.forEach(l=>{if(!l.from_number)return;const u=x.get(l.from_number)||l.from_number,U={id:l.id,call_date:l.call_date,from_number:l.from_number,to_number:l.to_number,duration_seconds:l.duration_seconds,call_status:l.call_status,call_summary:l.call_summary,ai_success_rating:l.ai_success_rating,ai_success_rating_auto:l.ai_success_rating_auto,transcript:l.transcript,recording_url:l.recording_url,call_type:l.call_type,follow_up_action:l.follow_up_action};k.has(u)||k.set(u,[]),k.get(u)?.push(U),m.has(u)||m.set(u,{rating:l.ai_success_rating||l.ai_success_rating_auto,summary:l.call_summary,status:l.call_status});const P=A.get(u)||{totalDuration:0,avgDuration:0,callCount:0};P.totalDuration+=l.duration_seconds||0,P.callCount+=1,P.avgDuration=P.totalDuration/P.callCount,A.set(u,P)}),s?.map(l=>{const u=m.get(l.phone_number),U=A.get(l.phone_number),P=k.get(l.phone_number)||[],he=l.outbound_campaigns,pe=l.custom_fields||{},Ne=l.result==="DNC requested"||P.some(be=>be.follow_up_action==="dnc_requested");return{id:l.id,campaign_id:l.campaign_id,name:l.name,phone_number:l.phone_number,email:l.email,status:l.status,result:l.result,attempts:l.attempts,last_attempt_at:l.last_attempt_at,appointment_scheduled:jt(l.appointment_scheduled),notes:l.notes,custom_fields:l.custom_fields,created_at:l.created_at,campaign_name:he?.name,customer_name:he?.customers?.company_name,contact_outcome:pe.contact_outcome||gt(l,P),call_rating:pe.call_rating||u?.rating||null,last_call_summary:u?.summary||null,total_call_duration:U?.totalDuration||0,avg_call_duration:U?.avgDuration||0,call_history:P,is_dnc:Ne}})||[]},staleTime:3e4}),us=i.useMemo(()=>{if(!v)return[];const s=new Map;return v.forEach(t=>{t.campaign_id&&t.campaign_name&&s.set(t.campaign_id,t.campaign_name)}),Array.from(s.entries()).map(([t,x])=>({id:t,name:x}))},[v]),c=i.useMemo(()=>
23{if(!v)return{total:0,contacted:0,scheduled:0,avgAttempts:0,personRate:0,avgCallDuration:0,highRatingCalls:0,recentActivity:0,conversionRate:0,voicemailRate:0,noAnswerRate:0,totalCallDuration:0};const s=v.length,t=v.filter(p=>p.attempts>0).length,x=v.filter(p=>p.appointment_scheduled).length,j=v.reduce((p,H)=>p+(H.attempts||0),0),E=t>0?Number((j/t).toFixed(1)):0,k=v.reduce((p,H)=>{const He=H.contact_outcome||"unknown";return p[He]=(p[He]||0)+1,p},{}),m=t>0?Math.round((k.person||0)/t*100):0,A=t>0?Math.round((k.voicemail||0)/t*100):0,l=t>0?Math.round((k.no_answer||0)/t*100):0,u=v.reduce((p,H)=>p+(H.total_call_duration||0),0),U=v.reduce((p,H)=>p+(H.call_history?.length||0),0),P=U>0?Math.round(u/U):0,he=v.filter(p=>p.call_rating&&p.call_rating>=4).length,pe=ot(new Date,7),Ne=v.filter(p=>p.last_attempt_at&&new Date(p.last_attempt_at)>pe).length,be=t>0?Math.round(x/t*100):0;return{total:s,contacted:t,scheduled:x,avgAttempts:E,personRate:m,avgCallDuration:P,highRatingCalls:he,recentActivity:Ne,conversionRate:be,voicemailRate:A,noAnswerRate:l,totalCallDuration:u}},[v]),b=i.useMemo(()=>{if(!v)return[];let s=v.filter(t=>{const x=!r||t.name.toLowerCase().includes(r.toLowerCase())||t.phone_number.includes(r)||t.email&&t.email.toLowerCase().includes(r.toLowerCase())||t.campaign_name&&t.campaign_name.toLowerCase().includes(r.toLowerCase()),j=d==="all"||t.contact_outcome===d,E=g==="all"||t.status===g,k=N==="all"||t.campaign_id===N,m=M==="all"||M==="high"&&t.call_rating&&t.call_rating>=4||M==="medium"&&t.call_rating&&t.call_rating===3||M==="low"&&t.call_rating&&t.call_rating<=2||M==="unrated"&&!t.call_rating;let A=!0;if($!=="all"&&t.last_attempt_at){const l=new Date(t.last_attempt_at),u=ht(new Date,l)/(60*24);$==="today"?A=u<1:$==="week"?A=u<7:$==="month"&&(A=u<30)}return x&&j&&E&&k&&m&&A});return s.sort((t,x)=>{let j=0;switch(J){case"name":j=t.name.localeCompare(x.name);break;case"last_attempt_at":j=new Date(t.last_attempt_at||0).getTime()-new Date(x.last_attempt_at||0).getTime();break;case"attempts":j=(t.attempts||0)-(x.attempts||0);break;case"call_rating":j=(t.call_rating||0)-(x.call_rating||0);break;case"avg_call_duration":j=(t.avg_call_duration||0)-(x.avg_call_duration||0);break}return ge==="asc"?j:-j}),s},[v,r,d,g,N,M,$,J,ge]),hs=i.useMemo(()=>{if(T===-1)return b;const s=(D-1)*T;return b.slice(s,s+T)},[b,D,T]),R=T===-1?1:Math.ceil(b.length/T);i.useEffect(()=>{X(1)},[r,d,g,N,M,$]);const ve=!!r||d!=="all"||g!=="all"||N!=="all"||M!=="all"||$!=="all",ze=i.useCallback(()=>{o(""),_("all"),L("all"),y("all"),Le("all"),Te("all")},[]),ue=ys({mutationFn:async({id:s,updates:t})=>{const{error:x}=await K.from("campaign_contacts").update({notes:t.notes,result:t.is_dnc?"DNC requested":n?.result==="DNC requested"?null:n?.result,custom_fields:{...n?.custom_fields||{},contact_outcome:t.contact_outcome,call_rating:t.call_rating}}).eq("id",s);if(x)throw x;if(t.is_dnc&&n?.phone_number){const{data:j}=await K.from("blocked_numbers").select("id").eq("phone_number",n.phone_number).maybeSingle();if(!j){const{data:E}=await K.from("outbound_campaigns").select("customer_id").eq("id",n.campaign_id).single();E?.customer_id&&await K.from("blocked_numbers").insert({customer_id:E.customer_id,phone_number:n.phone_number,reason:"Manually marked as DNC from leads page",source:"admin_manual"})}}},onSuccess:()=>{W.success("Lead updated successfully"),a.invalidateQueries({queryKey:["admin-leads"]}),xe(!1),me(null)},onError:s=>{W.error("Failed to update lead",{description:s.message})}}),$e=i.useCallback(s=>{me(s),se({notes:s.notes||"",contact_outcome:s.custom_fields?.contact_outcome||s.contact_outcome||"",call_rating:s.custom_fields?.call_rating?.toString()||s.call_rating?.toString()||"none",is_dnc:s.is_dnc||!1}),xe(!0)},[]),ps=i.useCallback(()=>{n&&ue.mutate({id:n.id,updates:{notes:C.notes,contact_outcome:C.contact_outcome,call_rating:C.call_rating&&C.call_rating!=="none"?parseInt(C.call_rating):void 0,is_dnc:C.is_dnc}})},[n,C,ue]),Ue=i.useCallback(s=>{me(s),ee(!0)},[]),gs=i.useCallback(()=>{if(!b.length){W.error("No data to export");return}const s=b.map(m=>({Name:m.name,Phone:m.phone_number,Email:m.email||"",Campaign:m.campaign_name||"",Customer:m.customer_name||"",Outcome:m.contact_outcome||"",Status:m.status||"",Attempts:m.attempts||0,"Last Contact":m.last_attempt_at?G(new Date(m.last_attempt_at),"yyyy-MM-dd HH:mm"):"","Call Rating":m.call_rating||"","Avg Call Duration (s)":Math.round(m.avg_call_duration||0),"Total Calls":m.call_history?.length||0,"Appointment Scheduled":m.appointment_scheduled?"Yes":"No",Result:m.result||"",Notes:m.notes||""})),t=Object.keys(s[0]),x=[t.join(","),...s.map(m=>t.map(A=>`"${String(m[A]).replace(/"/g,'""')}"`).join(","))].join(`
24`),j=new Blob([x],{type:"text/csv;charset=utf-8;"}),E=URL.createObjectURL(j),k=document.createElement("a");k.href=E,k.download=`leads-export-${G(new Date,"yyyy-MM-dd-HHmm")}.csv`,k.click(),URL.revokeObjectURL(E),W.success(`Exported ${b.length} leads`)},[b]),js=i.useCallback(s=>{J===s?Ee(t=>t==="asc"?"desc":"asc"):(ls(s),Ee("desc"))},[J]),te=({field:s,children:t})=>e.jsx(ae,{className:"cursor-pointer select-none hover:bg-muted/50 transition-colors",onClick:()=>js(s),children:e.jsxs("div",{className:"flex items-center gap-1",children:[t,J===s&&(ge==="asc"?e.jsx(nt,{className:"h-3 w-3"}):e.jsx(it,{className:"h-3 w-3"}))]})});return ms?e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx(F,{className:"h-8 w-64 mb-2"}),e.jsx(F,{className:"h-4 w-96"})]})}),e.jsx(_t,{})]}):e.jsx(Me,{children:e.jsxs("div",{className:"admin-page space-y-6 p-6",children:[e.jsxs(Us,{kicker:"The outbound line",title:"Leads",lede:"Campaign contacts with call analytics and conversion insight.",children:[e.jsxs(f,{onClick:gs,variant:"outline",size:"sm",disabled:!b.length,children:[e.jsx(qs,{className:"h-4 w-4 mr-2"}),"Export"]}),e.jsxs(f,{onClick:()=>xs(),variant:"outline",size:"sm",disabled:Oe,children:[Oe?e.jsx(Ve,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Qs,{className:"h-4 w-4 mr-2"}),"Refresh"]})]}),e.jsx(Hs,{stats:[{id:"total",label:"Total leads",value:c.total},{id:"contacted",label:"Contacted",value:c.contacted},{id:"scheduled",label:"Appointments",value:c.scheduled},{id:"conv",label:"Conversion",value:`${c.conversionRate}%`},{id:"recent",label:"Last 7 days",value:c.recentActivity}]}),e.jsxs("div",{className:"grid gap-3 grid-cols-2 md:grid-cols-3 lg:grid-cols-5",children:[e.jsx(le,{title:"Ap
24pointments",value:c.scheduled,icon:Ys,description:`${c.conversionRate}% conversion`,highlight:c.scheduled>0,trend:c.conversionRate>10?"up":"neutral",trendValue:`${c.conversionRate}%`}),e.jsx(le,{title:"Person Rate",value:`${c.personRate}%`,icon:Je,description:"Reached decision maker",trend:c.personRate>30?"up":c.personRate<15?"down":"neutral"}),e.jsx(le,{title:"Avg Duration",value:z(c.avgCallDuration),icon:Qe,description:"Per conversation"}),e.jsx(le,{title:"High Ratings",value:c.highRatingCalls,icon:Ze,description:"4-5 star calls",trend:c.highRatingCalls>5?"up":"neutral"}),e.jsx(le,{title:"Recent Activity",value:c.recentActivity,icon:Gs,description:"Last 7 days"})]}),c.contacted>0&&e.jsx(Q,{children:e.jsxs(Y,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-medium",children:"Outcome Distribution"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[c.contacted," contacted"]})]}),e.jsxs("div",{className:"flex gap-1 h-2 rounded-full overflow-hidden bg-muted",children:[c.personRate>0&&e.jsxs(ie,{children:[e.jsx(oe,{asChild:!0,children:e.jsx("div",{className:"bg-emerald-500 transition-all",style:{width:`${c.personRate}%`}})}),e.jsxs(ce,{children:["Person: ",c.personRate,"%"]})]}),c.voicemailRate>0&&e.jsxs(ie,{children:[e.jsx(oe,{asChild:!0,children:e.jsx("div",{className:"bg-violet-500 transition-all",style:{width:`${c.voicemailRate}%`}})}),e.jsxs(ce,{children:["Voicemail: ",c.voicemailRate,"%"]})]}),c.noAnswerRate>0&&e.jsxs(ie,{children:[e.jsx(oe,{asChild:!0,children:e.jsx("div",{className:"bg-slate-400 transition-all",style:{width:`${c.noAnswerRate}%`}})}),e.jsxs(ce,{children:["No Answer: ",c.noAnswerRate,"%"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-emerald-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Person"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-violet-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Voicemail"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-slate-400"}),e.jsx("span",{className:"text-muted-foreground",children:"No Answer"})]})]})]})}),e.jsx(Q,{children:e.jsx(Y,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col lg:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(Ks,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(vs,{placeholder:"Search by name, phone, email, or campaign...",value:r,onChange:s=>o(s.target.value),className:"pl-9"}),r&&e.jsx(f,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 p-0",onClick:()=>o(""),children:e.jsx(Ie,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(V,{value:N,onValueChange:y,children:[e.jsx(I,{className:"w-[160px]",children:e.jsx(B,{placeholder:"Campaign"})}),e.jsxs(q,{children:[e.jsx(h,{value:"all",children:"All Campaigns"}),us.map(s=>e.jsx(h,{value:s.id,children:s.name},s.id))]})]}),e.jsxs(V,{value:d,onValueChange:_,children:[e.jsx(I,{className:"w-[160px]",children:e.jsx(B,{placeholder:"Outcome"})}),e.jsxs(q,{children:[e.jsx(h,{value:"all",children:"All Outcomes"}),Object.entries(Re).map(([s,t])=>e.jsx(h,{value:s,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.icon,{className:w("h-3 w-3",t.color)}),t.label]})},s))]})]}),e.jsxs(V,{value:M,onValueChange:Le,children:[e.jsx(I,{className:"w-[140px]",children:e.jsx(B,{placeholder:"Rating"})}),e.jsxs(q,{children:[e.jsx(h,{value:"all",children:"All Ratings"}),e.jsx(h,{value:"high",children:"High (4-5★)"}),e.jsx(h,{value:"medium",children:"Medium (3★)"}),e.jsx(h,{value:"low",children:"Low (1-2★)"}),e.jsx(h,{value:"unrated",children:"Unrated"})]})]}),e.jsxs(V,{value:$,onValueChange:Te,children:[e.jsx(I,{className:"w-[130px]",children:e.jsx(B,{placeholder:"Period"})}),e.jsxs(q,{children:[e.jsx(h,{value:"all",children:"All Time"}),e.jsx(h,{value:"today",children:"Today"}),e.jsx(h,{value:"week",children:"Last 7 Days"}),e.jsx(h,{value:"month",children:"Last 30 Days"})]})]}),ve&&e.jsxs(f,{variant:"ghost",size:"sm",onClick:ze,className:"text-muted-foreground",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"}),"Clear"]})]})]})})}),e.jsxs(Q,{children:[e.jsx(ks,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsx(Ss,{className:"text-lg",children:ve?`Filtered Results (${b.length})`:`All Leads (${b.length})`}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Show:"}),e.jsxs(V,{value:T.toString(),onValueChange:s=>{rs(parseInt(s)),X(1)},children:[e.jsx(I,{className:"w-[130px] h-8",children:e.jsx(B,{})}),e.jsxs(q,{children:[e.jsx(h,{value:"25",children:"25 per page"}),e.jsx(h,{value:"50",children:"50 per page"}),e.jsx(h,{value:"100",children:"100 per page"}),e.jsx(h,{value:"-1",children:"Show all"})]})]})]})]})}),e.jsx(Y,{className:"p-0",children:b.length===0?e.jsx(vt,{hasFilters:ve,onClearFilters:ze}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto max-w-full",children:e.jsxs(Ds,{children:[e.jsx(Rs,{children:e.jsxs(As,{className:"hover:bg-transparent",children:[e.jsx(te,{field:"name",children:"Contact"}),e.jsx(ae,{children:"Campaign"}),e.jsx(ae,{children:"Outcome"}),e.jsx(te,{field:"attempts",children:"Calls"}),e.jsx(te,{field:"avg_call_duration",children:"Duration"}),e.jsx(te,{field:"last_attempt_at",children:"Last Contact"}),e.jsx(te,{field:"call_rating",children:"Rating"}),e.jsx(ae,{children:"Result"}),e.jsx(ae,{className:"w-[50px]"})]})}),e.jsx(Ps,{children:hs.map(s=>e.jsx(Nt,{lead:s,onView:()=>{me(s),Z(!0)},onEdit:()=>$e(s),onViewCalls:()=>Ue(s)},s.id))})]})}),T!==-1&&R>1&&e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 px-4 py-3 border-t",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Showing ",(D-1)*T+1,"–",Math.min(D*T,b.length)," of ",b.length]}),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap min-w-0",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>X(s=>Math.max(1,s-1)),disabled:D===1,children:"Previous"}),(()=>{const s=[];if(R<=7)for(let t=1;t<=R;t++)s.push(t);else D<=3?s.push(1,2,3,4,"...",R):D>=R-2?s.push(1,"...",R-3,R-2,R-1,R):s.push(1,"...",D-1,D,D+1,"...",R);return s.map((t,x)=>t==="..."?e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${x}`):e.jsx(f,{variant:D===t?"default":"outline",size:"sm",className:"w-8 h-8 p-0",onClick:()=>X(t),children:t},t))})(),e.jsx(f,{variant:"outline",size:"sm",onClick:()=>X(s=>Math.min(R,s+1)),disabled:D===R,children:"Next"})]})]}),T===-1&&e.jsxs("div",{className:"px-4 py-3 border-t text-sm text-muted-foreground",children:["Showing all ",b.length," leads"]})]})})]}),e.jsx(we,{open:ns,onOpenChange:Z,children:e.jsxs(ye,{className:"max-w-2xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsx(Ce,{children:e.jsxs(ke,{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("h-10 w-10 rounded-full flex items-center justify-center text-lg font-semibold","bg-gradient-to-br from-slate-100 to-slate-200 dark:from-slate-800 dark:to-slate-700"),
24children:n?.name.charAt(0).toUpperCase()}),e.jsxs("div",{children:[e.jsx("span",{children:n?.name}),e.jsx("p",{className:"text-sm font-normal text-muted-foreground",children:n?.phone_number})]})]})}),e.jsx(qe,{className:"flex-1 -mx-6 px-6",children:n&&e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Email"}),e.jsx("p",{className:"text-sm font-medium",children:n.email||"—"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Campaign"}),e.jsx("p",{className:"text-sm font-medium",children:n.campaign_name})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Customer"}),e.jsx("p",{className:"text-sm font-medium",children:n.customer_name})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Status"}),e.jsx(ft,{status:n.status})]})]}),e.jsx(Ts,{}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",children:"Call Analytics"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:n.attempts||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Attempts"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:n.call_history?.length||0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Calls"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:z(Math.round(n.avg_call_duration||0))}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Avg Duration"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold",children:z(n.total_call_duration||0)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Time"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Outcome"}),e.jsx("div",{className:"mt-1",children:e.jsx(as,{outcome:n.contact_outcome||"unknown"})})]}),e.jsxs("div",{children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Rating"}),e.jsx("div",{className:"mt-1",children:e.jsx(ne,{rating:n.call_rating,size:"md"})})]}),e.jsxs("div",{children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Appointment"}),e.jsx("div",{className:"mt-1",children:n.appointment_scheduled?e.jsxs(de,{className:"bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-300 gap-1",children:[e.jsx(De,{className:"h-3 w-3"}),"Scheduled"]}):e.jsxs(de,{variant:"outline",className:"gap-1",children:[e.jsx(es,{className:"h-3 w-3"}),"Not Scheduled"]})})]})]}),n.last_call_summary&&e.jsxs("div",{children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Last Call Summary"}),e.jsx("p",{className:"mt-1 text-sm bg-muted/50 p-3 rounded-lg",children:n.last_call_summary})]}),n.notes&&e.jsxs("div",{children:[e.jsx(S,{className:"text-xs text-muted-foreground",children:"Notes"}),e.jsx("p",{className:"mt-1 text-sm bg-muted/50 p-3 rounded-lg",children:n.notes})]}),n.call_history&&n.call_history.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Recent Calls"}),e.jsxs(f,{variant:"ghost",size:"sm",onClick:()=>{Z(!1),Ue(n)},children:["View All (",n.call_history.length,")"]})]}),e.jsx("div",{className:"space-y-2",children:n.call_history.slice(0,3).map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted/50 rounded-lg text-sm",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{children:G(new Date(s.call_date),"MMM d, h:mm a")}),e.jsx("span",{className:"text-muted-foreground",children:"•"}),e.jsx("span",{children:z(s.duration_seconds||0)})]}),e.jsx(ne,{rating:s.ai_success_rating||s.ai_success_rating_auto})]},s.id))})]})]})}),e.jsxs(Se,{className:"border-t pt-4",children:[e.jsx(f,{variant:"outline",onClick:()=>Z(!1),children:"Close"}),e.jsxs(f,{onClick:()=>{Z(!1),n&&$e(n)},children:[e.jsx(ss,{className:"h-4 w-4 mr-2"}),"Edit Lead"]})]})]})}),e.jsx(we,{open:os,onOpenChange:ee,children:e.jsxs(ye,{className:"max-w-3xl max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs(Ce,{children:[e.jsx(ke,{children:"Call History"}),e.jsxs(Be,{children:[n?.name," • ",n?.phone_number]})]}),n&&n.call_history&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-4 gap-3 py-3 border-y",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl font-bold",children:n.call_history.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Calls"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl font-bold",children:z(n.total_call_duration||0)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Total"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl font-bold",children:z(Math.round(n.avg_call_duration||0))}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Average"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-xl font-bold",children:n.call_rating||"—"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Rating"})]})]}),e.jsx(qe,{className:"flex-1 -mx-6 px-6",children:e.jsx("div",{className:"space-y-3 py-4",children:n.call_history.map((s,t)=>e.jsx(Q,{className:"hover:bg-muted/30 transition-colors",children:e.jsx(Y,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(de,{variant:"outline",className:"font-mono text-xs",children:["#",n.call_history.length-t]}),e.jsx("span",{className:"text-sm font-medium",children:G(new Date(s.call_date),"MMM d, yyyy h:mm a")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:Xe(new Date(s.call_date),{addSuffix:!0})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3 w-3"}),z(s.duration_seconds||0)]}),e.jsxs("div",{className:"flex items-center gap-1",children:[s.call_status==="completed"?e.jsx(De,{className:"h-3 w-3 text-emerald-500"}):e.jsx(Ws,{className:"h-3 w-3 text-amber-500"}),e.jsx("span",{className:"capitalize",children:s.call_status})]}),e.jsx(ne,{rating:s.ai_success_rating||s.ai_success_rating_auto})]}),s.call_summary&&e.jsx("p",{className:"mt-2 text-sm text-muted-foreground line-clamp-2",children:s.call_summary})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[s.recording_url&&e.jsx(bt,{callId:s.id}),e.jsx(f,{size:"sm",variant:"ghost",onClick:()=>{je(s),_e(!0),ee(!1),fe(!0)},children:e.jsx(ts,{className:"h-4 w-4"})})]})]})})},s.id))})})]}),e.jsx(Se,{className:"border-t pt-4",children:e.jsx(f,{onClick:()=>ee(!1),children:"Close"})})]})}),e.jsx(we,{open:is,onOpenChange:xe,children:e.jsxs(ye,{children:[e.jsxs(Ce,{children:[e.jsx(ke,{children:"Edit Lead"}),e.jsxs(Be,{children:["Update tracking information for ",n?.name]})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Contact Outcome"}),e.jsxs(V,{value:C.contact_outcome,onValueChange:s=>se(t=>({...t,contact_outcome:s})),children:[e.jsx(I,{children:e.jsx(B,{placeholder:"Select outcome"})}),e.jsx(q,{children:Object.entries(Re).map(([s,t])=>e.jsx(h,{value:s,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.icon,{className:w("h-4 w-4",t.color)}),t.label]})}
24,s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Call Rating"}),e.jsxs(V,{value:C.call_rating,onValueChange:s=>se(t=>({...t,call_rating:s})),children:[e.jsx(I,{children:e.jsx(B,{placeholder:"Select rating"})}),e.jsxs(q,{children:[e.jsx(h,{value:"none",children:"No Rating"}),[1,2,3,4,5].map(s=>e.jsx(h,{value:s.toString(),children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(ne,{rating:s})})},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Notes"}),e.jsx(Ls,{value:C.notes,onChange:s=>se(t=>({...t,notes:s.target.value})),placeholder:"Add notes about this lead...",rows:4})]}),e.jsxs("div",{className:w("flex items-center space-x-3 p-3 rounded-lg border",C.is_dnc?"bg-red-50 border-red-200 dark:bg-red-950/30 dark:border-red-800":"border-border"),children:[e.jsx(Ms,{id:"edit-dnc",checked:C.is_dnc,onCheckedChange:s=>se(t=>({...t,is_dnc:s===!0}))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xs,{className:w("h-4 w-4",C.is_dnc?"text-red-600":"text-muted-foreground")}),e.jsx(S,{htmlFor:"edit-dnc",className:w("font-medium cursor-pointer",C.is_dnc&&"text-red-700 dark:text-red-400"),children:"Do Not Call (DNC)"})]})]})]}),e.jsxs(Se,{children:[e.jsx(f,{variant:"outline",onClick:()=>xe(!1),children:"Cancel"}),e.jsx(f,{onClick:ps,disabled:ue.isPending,children:ue.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save Changes"})]})]})}),Fe&&e.jsx($s,{call:Fe,isOpen:cs,onClose:()=>{fe(!1),je(null),_e(!1)},onBack:ds?()=>{fe(!1),je(null),_e(!1),ee(!0)}:void 0})]})})};export{za 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.