PageSourceSearch

https://client-progress-os-meliving.base44.app/assets/CallList-DN569ve_.js

js client-progress-os-meliving.base44.app collected 2026-10-03 03:15:42 UTC 41,948 bytes, 1 lines download raw bytes

1import{s as ae,j as e,z as T,aV as B,i as Ae,r as o,p as y,b3 as te,b6 as se,b4 as he,b5 as pe,aQ as Te,bw as De,bx as Re,X as Ne,a1 as Ee,Y as Me,bv as Oe,by as ze,bz as Pe,bA as Qe,bB as _e,q as ye,u as ge,bl as qe,aa as Fe,T as ve,L as we,S as ke,R as Ce,y as Se,a$ as Ue,aS as Ve,f as be,m as je,a as Be}from"./index-j6sLDzf7.js";import{d as He,e as Ge}from"./twilioDeviceManager-CHvnIIKy.js";import{P as We}from"./phone-missed-BK5_NtR4.js";import{i as Ye}from"./isToday-CpzDAoJM.js";import{c as Ke}from"./constructNow-T1DMWgyJ.js";import{i as Xe}from"./isSameDay-DsJ2_VwL.js";import{a as Je}from"./addDays-D-e9JkJC.js";import{T as Ze}from"./trash-2-B6y6ZthY.js";import{P as et}from"./plus-CeMyqkqg.js";import{p as tt}from"./parseISO-D7U8QK0K.js";import{d as st}from"./differenceInDays-B8Mp7N70.js";import{f as at}from"./format-CnaHGush.js";import"./events-DQ172AOg.js";import"./constructFrom-DWjd9ymD.js";import"./differenceInCalendarDays-CzTee4Yq.js";import"./getTimezoneOffsetInMilliseconds-CHy3_ZYB.js";import"./en-US-ClfMaaVW.js";function rt(s,c){return Je(s,-1)}function nt(s){return Xe(s,rt(Ke(s)))}function lt({client:s}){const{toast:c}=ae();if(!(s!=null&&s.phone))return e.jsxs(T,{disabled:!0,className:"gap-2 text-xs",children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"No phone number"]});const v=()=>{window.dispatchEvent(new CustomEvent("open_phone_sidebar",{detail:{force:!0,tab:"dial",clientId:s.id,clientPhone:s.phone}})),c({title:"CPOS managed call opened",description:"Recording + live AI scribe will turn on automatically when the client’s required recording/AI-documentation permissions are verified."})};return e.jsxs(T,{onClick:v,className:"gap-2 text-xs bg-green-600 hover:bg-green-700",title:"CPOS-managed staff call: authoritative CallLog + permission-gated recording, live transcription and AI documentation",children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"Call Client",e.jsx(Ae,{className:"w-3.5 h-3.5 opacity-80"})]})}function ot(){const[s,c]=o.useState([]),[v,w]=o.useState(null),[P,L]=o.useState(null),[z,f]=o.useState(0),[U,u]=o.useState(0),[N,D]=o.useState(!1),[$,C]=o.useState(!0),[O,g]=o.useState(null),k=o.useRef(null),b=o.useRef(null),_=o.useRef(null),i=o.useRef(null),j=o.useRef(null),R=o.useRef(!1),E=o.useRef(0),M=o.useRef(5e3);o.useEffect(()=>{try{sessionStorage.removeItem("active_call_badge_state"),sessionStorage.removeItem("stuck_call_state"),localStorage.removeItem("voip_frozen_state")}catch{}return Q(),()=>{var l;if(R.current=!1,(l=j.current)==null||l.abort(),clearInterval(k.current),clearInterval(b.current),i.current){console.warn("AutoCallQueueWidget unmounted during a live call — preserving provider media leg.");return}}},[]);const Q=async()=>{var h;if(!(R.current||Date.now()-E.current<1e4)){R.current=!0,j.current=new AbortController;try{C(!0),g(null);const S=await y.functions.invoke("getCallQueueForStaff",{});E.current=Date.now(),M.current=5e3,c(((h=S.data)==null?void 0:h.queue)||[])}catch(S){S.name!=="AbortError"&&(console.error("Queue load error:",S),c([]),g(null),M.current=Math.min(M.current*2,6e4))}finally{R.current=!1,C(!1)}}},V=()=>{var l;(l=j.current)==null||l.abort(),C(!1),g("Queue load cancelled.")},H=async()=>{if(i.current){try{i.current.disconnect()}catch{}i.current=null}He(),_.current=null,clearInterval(k.current),clearInterval(b.current);try{await y.functions.invoke("forceEndAllCalls",{})}catch(l){console.error("Force end all calls failed:",l)}w(null),L(null),f(0),u(0),g(null),c([]),C(!1)},A=async()=>{try{const l=await Ge({requestMic:!0});return _.current=l,L(l),l}catch(l){return console.error("Shared Twilio Device init error:",l),g((l==null?void 0:l.message)||"Phone initialization failed"),null}},q=async l=>{try{g(null),w(l),f(0),u(0),D(!1),await De(),Re(`${l.first_name} ${l.last_name}`,l.phone);const h=await y.auth.me();await y.entities.CallLog.create({call_sid:`web_queue_${Date.now()}`,direction:"outbound",staff_email:(h==null?void 0:h.email)||"unknown",client_id:l.id,to_phone:l.phone,call_status:"initiated",started_at:new Date().toISOString(),outcome:"in_progress"});let S=_.current||P;if(!S&&(S=await A(),!S))return;k.current=setInterval(()=>{f(n=>n+1)},1e3),b.current=setInterval(()=>{u(n=>Math.min(n+1,999))},1e3);const I=String(l.phone||"").replace(/\D/g,""),X=I.length===10?`+1${I}`:I.length===11&&I.startsWith("1")?`+${I}`:l.phone,t=await S.connect({params:{To:X}});i.current=t;let r=!1,m=!1;t.on("accept",()=>{r=!0,D(!0),u(0),clearInterval(b.current),b.current=null});const x=async()=>{m||(m=!0,clearInterval(k.current),clearInterval(b.current),k.current=null,b.current=null,i.current=null,D(!1),r?(w(null),f(0),u(0),Q()):await G(l,{disconnectCall:!1}))};t.on("disconnect",x),t.on("cancel",x),t.on("reject",x)}catch(h){console.error("Start call error:",h),g(h.message),w(null),clearInterval(k.current),clearInterval(b.current)}},G=async(l,{disconnectCall:h=!0}={})=>{var S;clearInterval(k.current),clearInterval(b.current),k.current=null,b.current=null,D(!1),h&&i.current&&i.current.disconnect();try{await y.functions.invoke("logCallToCallLog",{client_id:l.id,client_phone:l.phone,call_type:"follow_up",direction:"outbound",call_duration_minutes:0,summary:"Auto-attempt: No answer",is_billable:!1,status:"missed"});const I=await y.functions.invoke("handleCallNoAnswer",{currentClientId:l.id,callStatus:"no_answer"});(S=I.data)!=null&&S.nextClient?(w(null),setTimeout(()=>q(I.data.nextClient),2e3)):(w(null),await Q())}catch(I){console.error("No answer error:",I),g(I.message),w(null)}},K=async()=>
1{if(clearInterval(k.current),clearInterval(b.current),k.current=null,b.current=null,i.current){try{i.current.disconnect()}catch(h){console.error("Disconnect error:",h)}i.current=null}if(_.current){try{_.current.destroy()}catch(h){console.error("Device destroy error:",h)}_.current=null,L(null)}const l=v;w(null),f(0),u(0),g(null);try{const h=await y.auth.me();await y.entities.CallLog.create({call_sid:`web_queue_end_${Date.now()}`,direction:"outbound",staff_email:(h==null?void 0:h.email)||"unknown",client_id:l.id,to_phone:l.phone,call_status:"completed",duration_seconds:z,started_at:new Date().toISOString(),completed_at:new Date().toISOString(),outcome:"completed"})}catch(h){console.error("Call log error:",h)}c([]),C(!1)};return $?e.jsx(te,{className:"w-full max-w-md",children:e.jsxs(se,{className:"pt-4 space-y-3",children:[e.jsx("div",{className:"text-center text-sm text-muted-foreground animate-pulse",children:"Loading call queue..."}),e.jsx(T,{onClick:V,variant:"outline",size:"sm",className:"w-full",children:"Cancel"})]})}):v?e.jsxs(te,{className:"w-full max-w-md",children:[e.jsx(he,{className:"bg-blue-50 border-b",children:e.jsxs(pe,{className:"text-lg flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5 text-blue-600"}),"Active Call"]})}),e.jsxs(se,{className:"pt-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Client"}),e.jsxs("p",{className:"text-lg font-semibold",children:[v.first_name," ",v.last_name]}),e.jsx("p",{className:"text-sm",children:v.phone})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Duration"}),e.jsxs("p",{className:"text-lg font-mono",children:[Math.floor(z/60),":",String(z%60).padStart(2,"0")]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:`text-xs ${N?"text-emerald-600":"text-orange-600"}`,children:N?"Connected":"Ringing"}),e.jsx("p",{className:`text-lg font-mono ${N?"text-emerald-600":"text-orange-600"}`,children:N?"LIVE":`${U}s`})]})]}),O&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded p-2 flex gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-red-600 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-xs text-red-700",children:O})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{onClick:async()=>{await K(),await Q()},className:"w-full bg-red-600 hover:bg-red-700 gap-2",children:[e.jsx(We,{className:"w-4 h-4"}),"End Call"]}),e.jsx(T,{onClick:H,variant:"destructive",size:"sm",className:"w-full",children:"Force Stop All"})]})]})]}):e.jsxs(te,{className:"w-full max-w-md h-64 flex flex-col",children:[e.jsx(he,{className:"bg-green-50 border-b flex-shrink-0",children:e.jsxs(pe,{className:"text-lg flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5 text-green-600"}),"Call Queue ",`(${s.length})`]})}),e.jsxs(se,{className:"pt-3 flex-1 overflow-y-auto flex flex-col space-y-2",children:[s.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-4",children:"No calls available"}):e.jsx(e.Fragment,{children:s.map((l,h)=>e.jsx("div",{className:"border rounded p-2 hover:bg-accent text-xs",children:e.jsx("div",{className:"flex justify-between items-start gap-2",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-semibold text-xs",children:[h+1,". ",l.first_name," ",l.last_name]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:l.phone}),e.jsxs("div",{className:"flex gap-1 mt-1",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-orange-100 text-orange-700 rounded-full",children:l.urgency_level}),h===0&&e.jsxs(T,{onClick:()=>q(l),size:"sm",className:"h-auto py-0.5 px-1.5 text-[10px] bg-green-600 hover:bg-green-700",children:[e.jsx(B,{className:"w-2.5 h-2.5 mr-0.5"}),"Call"]})]})]})})},l.id))}),e.jsx(T,{onClick:Q,disabled:$||R.current,size:"sm",variant:"outline",className:"w-full mt-auto text-xs flex-shrink-0",children:$?"Refreshing...":"Refresh Queue"})]})]})}function it({isActive:s,onEndCall:c,phoneNumber:v="",duration:w="0:00"}){const[P,L]=o.useState({x:20,y:20}),[z,f]=o.useState(!1),[U,u]=o.useState({x:0,y:0}
1),[N,D]=o.useState(!1),[$,C]=o.useState(!1),[O,g]=o.useState(!1),k=o.useRef(null);o.useEffect(()=>{const i=async j=>{j.key==="Escape"&&s&&await b()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s]);const b=async()=>{try{await y.functions.invoke("forceEndCall",{clientId:null,callSid:null})}catch(i){console.error("Force hangup error:",i)}c()},_=i=>{i.target.closest("button")||(f(!0),u({x:i.clientX-P.x,y:i.clientY-P.y}))};return o.useEffect(()=>{const i=R=>{z&&L({x:R.clientX-U.x,y:R.clientY-U.y})},j=()=>{f(!1)};return z&&(window.addEventListener("mousemove",i),window.addEventListener("mouseup",j)),()=>{window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",j)}},[z,U]),s?e.jsxs("div",{ref:k,style:{position:"fixed",left:`${P.x}px`,top:`${P.y}px`,zIndex:50},className:"w-72 bg-gradient-to-b from-slate-900 to-slate-800 rounded-2xl shadow-2xl border border-slate-700 overflow-hidden select-none",children:[e.jsxs("div",{onMouseDown:_,className:"bg-gradient-to-r from-slate-800 to-slate-900 px-4 py-3 flex items-center justify-between cursor-move hover:from-slate-700 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{className:"text-xs font-semibold text-slate-300 uppercase tracking-wider",children:"Active Call"})]}),e.jsx("button",{onClick:c,className:"p-1 rounded-lg hover:bg-red-600/20 transition-colors",children:e.jsx(Ne,{className:"w-4 h-4 text-slate-400 hover:text-red-500"})})]}),e.jsxs("div",{className:"bg-gradient-to-b from-slate-950 to-slate-900 px-6 py-8 space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-4xl font-light text-white font-mono tracking-wider mb-2",children:v||"..."}),e.jsx("div",{className:"text-sm text-green-400 font-medium",children:"Connected"}),e.jsx("div",{className:"text-xs text-slate-400 mt-1",children:w})]}),e.jsxs("div",{className:"flex justify-center gap-2 pt-2",children:[N&&e.jsx("span",{className:"text-[10px] bg-red-600/30 text-red-300 px-2 py-0.5 rounded-full border border-red-600/50",children:"MUTED"}),$&&e.jsx("span",{className:"text-[10px] bg-amber-600/30 text-amber-300 px-2 py-0.5 rounded-full border border-amber-600/50",children:"ON HOLD"}),O&&e.jsx("span",{className:"text-[10px] bg-blue-600/30 text-blue-300 px-2 py-0.5 rounded-full border border-blue-600/50",children:"SPEAKER"})]})]}),e.jsxs("div",{className:"px-4 py-4 space-y-3 bg-slate-900/50",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("button",{onClick:()=>D(!N),className:`flex items-center justify-center gap-1.5 py-2.5 rounded-lg font-medium text-xs transition-all ${N?"bg-red-600 text-white":"bg-slate-700 hover:bg-slate-600 text-slate-200"}`,children:[N?e.jsx(Ee,{className:"w-4 h-4"}):e.jsx(Me,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Mute"})]}),e.jsxs("button",{onClick:()=>C(!$),className:`flex items-center justify-center gap-1.5 py-2.5 rounded-lg font-medium text-xs transition-all ${$?"bg-amber-600 text-white":"bg-slate-700 hover:bg-slate-600 text-slate-200"}`,children:[$?e.jsx(Oe,{className:"w-4 h-4"}):e.jsx(ze,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Hold"})]}),e.jsxs("button",{onClick:()=>g(!O),className:`flex items-center justify-center gap-1.5 py-2.5 rounded-lg font-medium text-xs transition-all ${O?"bg-blue-600 text-white":"bg-slate-700 hover:bg-slate-600 text-slate-200"}`,children:[O?e.jsx(Pe,{className:"w-4 h-4"}):e.jsx(Qe,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Speaker"})]})]}),e.jsxs("button",{onClick:b,className:"w-full flex flex-col items-center justify-center gap-1.5 py-4 px-3 bg-red-600 hover:bg-red-700 text-white rounded-xl font-bold transition-all text-lg shadow-lg",children:[e.jsx(_e,{className:"w-6 h-6"}),e.jsx("span",{children:"HANG UP"}),e.jsx("span",{className:"text-xs opacity-75",children:"or press ESC"})]})]}),e.jsx("div",{className:"absolute bottom-1 right-1 w-3 h-3 bg-slate-700/50 rounded-full cursor-se-resize opacity-0 hover:opacity-100 transition-opacity"})]}):null}function $e(s){if(!s)return null;const c=tt(s);if(Ye(c))return"Today";if(nt(c))return"Yesterday";const v=st(new Date,c);return v<7?`${v}d ago`:at(c,"MMM d")}const Y=new Date().toISOString().split("T")[0];function Ie(s){const c=[];return s.risk_level==="critical"&&c.push({label:"Critical Risk",color:"bg-red-100 text-red-700"}),s.risk_level==="high"&&c.push({label:"High Risk",color:"bg-orange-100 text-orange-700"}),s.intake_status==="not_started"&&c.push({label:"Intake Not Started",color:"bg-blue-100 text-blue-700"}),s.intake_status==="sent"&&c.push({label:"Intake Sent — Follow Up",color:"bg-
1amber-100 text-amber-700"}),s.intake_status==="in_progress"&&c.push({label:"Intake In Progress",color:"bg-sky-100 text-sky-700"}),s.stage==="stabilization"&&c.push({label:"Stabilization Check-In",color:"bg-violet-100 text-violet-700"}),s.stage==="assessment"&&c.push({label:"Assessment Stage",color:"bg-indigo-100 text-indigo-700"}),s.insurance_status==="checking"&&c.push({label:"Insurance Check Pending",color:"bg-purple-100 text-purple-700"}),s.appointment_status==="scheduled"&&c.push({label:"Appointment Scheduled",color:"bg-green-100 text-green-700"}),s.appointment_status==="no_show"&&c.push({label:"No Show — Follow Up",color:"bg-red-100 text-red-700"}),s.blocked_modules_count>0&&c.push({label:`${s.blocked_modules_count} Blocked Module${s.blocked_modules_count>1?"s":""}`,color:"bg-red-100 text-red-700"}),s.next_best_action&&c.push({label:s.next_best_action,color:"bg-muted text-muted-foreground"}),c.length===0&&c.push({label:"Routine Check-In",color:"bg-gray-100 text-gray-600"}),c}function dt({client:s,allLogs:c,lastContactMap:v,onClose:w,onLogged:P,onCallStart:L,onCallEnd:z,activeCall:f,onTransfer:U,onQueue:u,onCancelPending:N}){var t,r,m,x,n;const{toast:D}=ae(),$=ye(),[C,O]=o.useState("reached"),[g,k]=o.useState(""),[b,_]=o.useState(!1),[i,j]=o.useState(null),[R,E]=o.useState(null),[M,Q]=o.useState(null),[V,H]=o.useState(!1),[A,q]=o.useState([]),[G,K]=o.useState("");o.useEffect(()=>{y.auth.me().then(a=>Q(a)).catch(()=>Q(null))},[]);const l=[s.id,...s.is_minor&&s.parent_guardian_id?[s.parent_guardian_id]:[],...c.filter(a=>{var d;return((d=a.notes)==null?void 0:d.includes("[CALL_LOG]"))&&a.client_id===s.id}).map(a=>a.client_id)],h=c.filter(a=>{var d;return!((d=a.notes)!=null&&d.includes("[CALL_LOG]"))||!a.client_id?!1:s.family_id&&a.family_id===s.family_id?!0:l.includes(a.client_id)}).sort((a,d)=>(d.created_date||d.completed_date||"").localeCompare(a.created_date||a.completed_date||"")),S=async()=>{_(!0);const d=new Date().toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit",hour12:!1}),p=(M==null?void 0:M.email)||"unknown@system",F=s.is_minor&&s.parent_guardian_id?s.parent_guardian_id:s.id,J=s.is_minor&&s.parent_guardian_id?` [re: minor=${s.first_name} ${s.last_name}]`:"";if(await y.entities.StaffTask.create({client_id:F,family_id:s.family_id||"",universal_client_id:s.universal_client_id||"",title:`Call log — ${C==="reached"?"Reached":C==="voicemail"?"Left Voicemail":"No Answer"}${J}`,description:g,owner_email:p,status:"completed",completed_date:Y,notes:`[CALL_LOG] outcome=${C} date=${Y} time=${d} staff=${p} family_id=${s.family_id||""} regarding_client_id=${s.id} notes=${g}`,urgency:"medium"}),V&&A.length>0)for(const Z of A)await y.entities.StaffTask.create({client_id:Z.id,family_id:s.family_id||"",title:"Communication note — discussed during parent call",description:G,owner_email:p,status:"completed",completed_date:Y,notes:`[MINOR_CALL_NOTE] parent_client_id=${F} parent_name=${s.first_name} ${s.last_name} date=${Y} time=${d} staff=${p} notes=${G}`,urgency:"medium"});$.invalidateQueries({queryKey:["call-logs"]}),D({title:V&&A.length>0?`Call logged for parent + ${A.length} minor(s)`:"Call logged successfully"}),_(!1),k(""),K(""),q([]),H(!1),P(s.id,C)},I=async()=>{_(!0),await y.entities.StaffTask.update(i.id,{title:`Call log — ${i.outcome==="reached"?"Reached":i.outcome==="voicemail"?"Left Voicemail":"No Answer"}`,description:i.notes,notes:`[CALL_LOG] outcome=${i.outcome} date=${i.date} time=${i.time||""} staff=${i.staff||""} notes=${i.notes}`}),$.invalidateQueries({queryKey:["call-logs"]}),D({title:"Call log updated"}),_(!1),j(null)},X=async a=>{E(a),await y.entities.StaffTask.delete(a),$.invalidateQueries({queryKey:["call-logs"]}),D({title:"Call log deleted"}),E(null)};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-muted-foreground mb-0.5",children:s._familySize>1?`Family Unit · ${s._familySize} members`:"Log Call"}),e.jsxs("h3",{className:"text-base font-semibold text-foreground",children:[s.first_name," ",s.last_name]}),((t=s._minors)==null?void 0:t.length)>0&&e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:["Includes: ",s._minors.map(a=>
1a.first_name).join(", ")]})]}),e.jsx("button",{onClick:w,className:"p-1.5 rounded-lg hover:bg-muted transition-colors",children:e.jsx(Ne,{className:"w-4 h-4 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4 space-y-5",children:[e.jsxs("div",{className:"bg-muted/30 rounded-xl p-4 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(Ue,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[13px] font-semibold",children:[s.first_name," ",s.last_name]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s.client_code||"—"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-0.5",children:"Phone"}),e.jsxs("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("open_phone_sidebar",{detail:{force:!0,tab:"dial",clientId:s.id,clientPhone:s.phone}})),className:"text-[13px] font-medium text-primary hover:underline flex items-center gap-1 text-left",title:"Open CPOS managed call",children:[e.jsx(B,{className:"w-3 h-3"})," ",s.phone||"—"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-0.5",children:"Stage"}),e.jsx(ke,{stage:s.stage})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-0.5",children:"Risk"}),e.jsx(Ce,{risk:s.risk_level})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-0.5",children:"Program"}),e.jsx("p",{className:"text-[12px] capitalize",children:((r=s.program)==null?void 0:r.replace(/_/g," "))||"—"})]})]}),s.assigned_case_manager&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-0.5",children:"Case Manager"}),e.jsx("p",{className:"text-[12px]",children:s.assigned_case_manager})]})]}),v[s.id]&&e.jsxs("div",{className:"flex items-center gap-2 bg-muted/30 rounded-lg px-3 py-2",children:[e.jsx(Se,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Last contact: "}),e.jsx("span",{className:"text-[11px] font-semibold text-foreground",children:$e(v[s.id].date)}),e.jsxs("span",{className:"text-[11px] text-muted-foreground ml-1 capitalize",children:["(",(m=v[s.id].outcome)==null?void 0:m.replace(/_/g," "),")"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:"Why call today"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ie(s).map((a,d)=>e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full font-medium ${a.color}`,children:a.label},d))}),s.next_best_action&&e.jsxs("p",{className:"text-[12px] text-primary font-medium mt-2",children:["→ ",s.next_best_action]}),s.blocker_summary&&e.jsxs("div",{className:"flex items-start gap-1.5 mt-2 bg-red-50 border border-red-200 rounded-lg px-2.5 py-2",children:[e.jsx(ve,{className:"w-3.5 h-3.5 text-red-500 mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-[11px] text-red-700",children:s.blocker_summary})]})]}),h.length>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:["Call History (",h.length,")"]}),e.jsx("div",{className:"space-y-2",children:h.map(a=>{var re,ne,le,oe,ie,de,ce,ue,me,xe,fe;const d=((ne=(re=a.notes)==null?void 0:re.match(/outcome=(\w+)/))==null?void 0:ne[1])||"reached",p=((oe=(le=a.notes)==null?void 0:le.match(/date=([\d-]+)/))==null?void 0:oe[1])||a.completed_date||"",F=((de=(ie=a.notes)==null?void 0:ie.match(/time=([\d:]+)/))==null?void 0:de[1])||"",J=((ue=(ce=a.notes)==null?void 0:ce.match(/staff=([^\s]+)/))==null?void 0:ue[1])||a.owner_email||"",Z=((fe=(xe=(me=a.notes)==null?void 0:me.match(/notes=(.*)/s))==null?void 0:xe[1])==null?void 0:fe.trim())||a.description||"",Le=(i==null?void 0:i.id)===a.id;return e.jsx("div",{className:`border rounded-xl px-3 py-2.5 ${d==="reached"?"border-green-200 bg-green-50":d==="voicemail"?"border-amber-200 bg-amber-50":"border-gray-200 bg-gray-50"}`,children:Le?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:[{value:"reached",label:"Reached",color:"border-green-400 bg-green-100 text-green-700"},{value:"voicemail",label:"Voicemail",color:"border-amber-400 bg-amber-100 text-amber-700"},{value:"no_answer",label:"No Answer",color:"border-gray-400 bg-gray-100 text-gray-600"}].map(W=>e.jsx("button",{onClick:()=>j(ee=>({...ee,outcome:W.value})),className:`text-[10px] font-semibold py-1 rounded-lg border-2 transition-all ${i.outcome===W.value?W.color:"border-border bg-white text-muted-foreground"}`,children:W.label},W.value))}),e.jsx("textarea",{className:"w-full px-2 py-1.5 border border-border rounded-lg text-[12px] bg-white resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:2,value:i.notes,onChange:W=>j(ee=>({...ee,notes:W.target.value}))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{size:"sm",className:"flex-1 h-7 text-[11px]",onClick:I,disabled:b,children:"Save"}),e.jsx(T,{size:"sm",variant:"outline",className:"h-7 text-[11px]",onClick:()=>j(null),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:`text-[10px] font-bold uppercase ${d==="reached"?"text-green-700":d==="voicemail"?"text-amber-700":"text-gray-600"}`,children:d==="reached"?"✓ Reached":d==="voicemail"?"📱 Voicemail":"✗ No Answer"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:p===Y?"Today":p}),F&&e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:F}),J&&J!=="—"&&e.jsx("span",{className:"text-[10px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:J})]}),Z&&e.jsx("p",{className:"text-[11px] text-foreground mt-1 leading-snug",children:Z})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>j({id:a.id,outcome:d,notes:Z,date:p,time:F,staff:J}),className:"p-1 rounded hover:bg-white/70 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(Ve,{className:"w-3 h-3"})}),e.jsx("button",{onClick:()=>X(a.id),disabled:R===a.id,className:"p-1 rounded hover:bg-red-100 text-muted-foreground hover:text-red-600 transition-colors",children:R===a.id?e.jsx(be,{className:"w-3 h-3 animate-spin"}):e.jsx(Ze,{className:"w-3 h-3"})})]})]})},a.id)})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:h.length>0?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(et,{className:"w-3 h-3"})," Log Another Call"]}):"Call Outcome"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{value:"reached",label:"Reached",icon:e.jsx(je,{className:"w-4 h-4"}),color:"border-green-300 bg-green-50 text-green-700"},{value:"voicemail",label:"Voicemail",icon:e.jsx(B,{className:"w-4 h-4"}),color:"border-amber-300 bg-amber-50 text-amber-700"},{value:"no_answer",label:"No Answer",icon:e.jsx(_e,{className:"w-4 h-4"}),color:"border-gray-300 bg-gray-50 text-gray-600"}].map(a=>e.jsxs("button",{onClick:()=>
1O(a.value),className:`flex flex-col items-center gap-1 py-2.5 rounded-xl border-2 text-[11px] font-semibold transition-all ${C===a.value?a.color+" shadow-sm":"border-border bg-muted/20 text-muted-foreground"}`,children:[a.icon,a.label]},a.value))})]}),((x=s._minors)==null?void 0:x.length)>0&&e.jsxs("div",{className:"border border-blue-200 bg-blue-50 rounded-xl p-3",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:V,onChange:a=>H(a.target.checked),className:"w-4 h-4 rounded accent-primary"}),e.jsx("span",{className:"text-[12px] font-semibold text-foreground",children:"Discussed a minor during this call?"})]}),V&&e.jsxs("div",{className:"space-y-2 mt-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase text-muted-foreground mb-1.5 block",children:"Select Minors Discussed (multi-select)"}),e.jsx("div",{className:"space-y-1.5",children:(n=s._minors)==null?void 0:n.map(a=>{const d=A.some(p=>p.id===a.id);return e.jsxs("label",{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-lg border cursor-pointer transition-colors ${d?"bg-blue-100 border-blue-300":"bg-white border-border hover:bg-muted/40"}`,children:[e.jsx("input",{type:"checkbox",checked:d,onChange:()=>{q(p=>d?p.filter(F=>F.id!==a.id):[...p,a])},className:"w-3.5 h-3.5 accent-primary"}),e.jsxs("span",{className:"text-[12px] font-medium text-foreground",children:["👶 ",a.first_name," ",a.last_name]})]},a.id)})}),A.length>0&&e.jsxs("p",{className:"text-[10px] text-blue-600 mt-1",children:[A.length," minor(s) selected — a note will be saved to each profile"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-semibold uppercase text-muted-foreground mb-1 block",children:"Notes for Minor"}),e.jsx("textarea",{className:"w-full px-3 py-2 border border-border rounded-lg text-[12px] text-foreground bg-background resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:2,placeholder:"What was discussed with or about this minor?",value:G,onChange:a=>K(a.target.value)})]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground mb-2",children:"Notes"}),e.jsx("textarea",{className:"w-full px-3 py-2 border border-border rounded-xl text-[13px] text-foreground bg-background resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:4,placeholder:"What was discussed? Any follow-up needed?",value:g,onChange:a=>k(a.target.value)})]})]}),e.jsxs("div",{className:"px-5 py-4 border-t border-border space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(T,{className:"flex-1",disabled:b,onClick:S,children:[b?e.jsx(be,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(je,{className:"w-4 h-4 mr-2"}),"Log Call"]}),e.jsx(lt,{client:s,staffUser:M}),e.jsx(we,{to:`/clients/${s.id}`,children:e.jsx(T,{variant:"outline",className:"px-3",title:"Open client profile",children:e.jsx(Be,{className:"w-4 h-4"})})})]}),(f==null?void 0:f.conferenceName)&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{size:"sm",variant:"outline",onClick:()=>U(s,"staff_1"),disabled:f==null?void 0:f.transferring,className:"flex-1 text-xs",title:"Transfer to staff",children:f!=null&&f.transferring?"⏳ Transferring...":"↪️ Transfer"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>u(s),disabled:f==null?void 0:f.queueing,className:"flex-1 text-xs",title:"Send to queue",children:f!=null&&f.queueing?"⏳ Queuing...":"📞 Queue"}),((f==null?void 0:f.transferring)||(f==null?void 0:f.queueing))&&e.jsx(T,{size:"sm",variant:"destructive",onClick:N,className:"text-xs",title:"Cancel pending calls",children:"✕ Cancel"})]})]})]})}function St(){var S,I,X;const{toast:s}=ae(),[c,v]=o.useState(""),[w,P]=o.useState("all"),[L,z]=o.useState(null),[f,U]=o.useState({}),[u,N]=o.useState(null);ye();const{data:D=[],isLoading:$}=ge({queryKey:["clients"],queryFn:()=>y.entities.Client.list("-risk_level",500),staleTime:3e4,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),{data:C=[]}=ge({queryKey:["call-logs"],queryFn:()=>y.entities.StaffTask.filter({},"-completed_date",1e3),staleTime:15e3,refetchInterval:!1}),O={},g={};for(const t of C){if(!((S=t.notes)!=null&&S.includes("[CALL_LOG]"))||!t.client_id)continue;const r=t.notes.match(/outcome=(\w+)/),m=(r==null?void 0:r[1])||"reached",x=t.notes.match(/date=([\d-]+)/),n=(x==null?void 0:x[1])||t.completed_date;
1n===Y&&(O[t.client_id]={outcome:m,note:t.description}),(!g[t.client_id]||n>g[t.client_id].date)&&(g[t.client_id]={date:n,outcome:m})}const k=D.filter(t=>{if(t.is_active===!1||t.stage==="inactive"||t.stage==="graduated"||t.is_dependent===!0&&t.parent_client_id||t.is_minor===!0&&t.parent_client_id)return!1;if(t.date_of_birth){const r=new Date(t.date_of_birth);if((new Date-r)/(1e3*60*60*24*365.25)<18)return!1}return!0}),b={};for(const t of D)b[t.id]=t;const _={},i=[],j={},R={};for(const t of k)t.family_id?(_[t.family_id]||(_[t.family_id]=[]),_[t.family_id].push(t)):(t.is_minor||t.is_dependent)&&t.parent_guardian_id?(j[t.parent_guardian_id]||(j[t.parent_guardian_id]=[]),j[t.parent_guardian_id].push(t)):(!t.is_minor&&!t.is_dependent&&(R[t.id]=t),(t.is_minor||t.is_dependent)&&!t.parent_guardian_id&&(t._isOrphanMinor=!0),i.push(t));const E=[...i];for(const[,t]of Object.entries(_)){const r=t.find(n=>n.is_head_of_household)||t.find(n=>!n.is_minor&&t.some(a=>a.parent_guardian_id===n.id))||t.find(n=>!n.is_minor)||t[0],m=t.filter(n=>n.id!==r.id&&n.is_minor),x=t.filter(n=>n.id!==r.id&&!n.is_minor);E.push({...r,_familyMembers:t.filter(n=>n.id!==r.id),_minors:m,_otherAdults:x,_familySize:t.length})}for(const t of E)if(j[t.id]){const r=j[t.id];t._minors=[...t._minors||[],...r],t._familyMembers=[...t._familyMembers||[],...r],t._familySize=(t._familySize||1)+r.length}const M={...O,...f};for(const t of C){if(!((I=t.notes)!=null&&I.includes("[CALL_LOG]"))||!t.client_id)continue;const r=t.notes.match(/date=([\d-]+)/);if(((r==null?void 0:r[1])||t.completed_date)!==Y)continue;const x=t.family_id||((X=t.notes.match(/family_id=([^\s]+)/))==null?void 0:X[1]);if(x&&_[x]){const n=E.find(a=>a.family_id===x&&!a.is_minor);if(n){const a=t.notes.match(/outcome=(\w+)/);M[n.id]={outcome:(a==null?void 0:a[1])||"reached",note:t.description}}}}const Q=E.filter(t=>{const r=(t._familyMembers||[]).map(d=>`${d.first_name} ${d.last_name}`).join(" "),m=`${t.first_name} ${t.last_name} ${t.client_code||""} ${r}`.toLowerCase(),x=!c||m.includes(c.toLowerCase()),n=!!M[t.id];return x&&(w==="all"||w==="called"&&n||w==="not_called"&&!n)}),V={critical:0,high:1,moderate:2,low:3,stable:4},H=[...Q].sort((t,r)=>{const m=V[t.risk_level]??5,x=V[r.risk_level]??5;return m!==x?m-x:`${t.first_name} ${t.last_name}`.localeCompare(`${r.first_name} ${r.last_name}`)}),A=E.filter(t=>
1M[t.id]).length,q=E.length,G=(t,r)=>{U(m=>{var a;const x={...m,[t]:{outcome:r}},n=E.find(d=>d.id===t);return((a=n==null?void 0:n._minors)==null?void 0:a.length)>0&&n._minors.forEach(d=>{x[d.id]={outcome:r}}),x})},K=async(t,r)=>{var m,x;if(!(u!=null&&u.conferenceName)){s({title:"No active call",variant:"destructive"});return}try{const n=await y.functions.invoke("transferCallToStaff",{conferenceName:u.conferenceName,staffIdentity:r,timeout:30});(m=n.data)!=null&&m.success?(N(a=>({...a,transferCallSid:n.data.transferCallSid,transferring:!0})),s({title:"Transfer initiated"})):s({title:"Transfer failed",description:(x=n.data)==null?void 0:x.error,variant:"destructive"})}catch(n){s({title:"Error",description:n.message,variant:"destructive"})}},l=async t=>{var r,m,x;if(!(u!=null&&u.conferenceName)){s({title:"No active call",variant:"destructive"});return}try{const n=await y.functions.invoke("sendToQueue",{conferenceName:u.conferenceName,queueName:"general"});if((r=n.data)!=null&&r.success){const a=((m=n.data.ringCalls)==null?void 0:m.map(d=>d.callSid))||[];N(d=>({...d,ringCallSids:a,queueing:!0})),s({title:`Queue: ${n.data.totalStaffRinged||0} staff ringing`})}else s({title:"Queue failed",description:(x=n.data)==null?void 0:x.error,variant:"destructive"})}catch(n){s({title:"Error",description:n.message,variant:"destructive"})}},h=async()=>{var r;const t=[u==null?void 0:u.transferCallSid,...(u==null?void 0:u.ringCallSids)||[]].filter(Boolean);if(t.length!==0)try{const m=await y.functions.invoke("cancelQueueRings",{callSids:t});(r=m.data)!=null&&r.success&&(N(x=>({...x,transferCallSid:null,ringCallSids:[],transferring:!1,queueing:!1})),s({title:`Cancelled ${m.data.successCount} ring calls`}))}catch(m){s({title:"Error",description:m.message,variant:"destructive"})}};return o.useEffect(()=>{if(!u)return;const t=setInterval(()=>{const r=Math.floor((Date.now()-u.startTime)/1e3),m=String(Math.floor(r/60)).padStart(2,"0"),x=String(r%60).padStart(2,"0");N(n=>({...n,duration:`${m}:${x}`}))},1e3);return()=>clearInterval(t)},[u]),e.jsxs("div",{className:"flex h-[calc(100vh-64px)] -mx-6 -mt-6 overflow-hidden relative",children:[e.jsx(it,{isActive:!!u,phoneNumber:u==null?void 0:u.phoneNumber,duration:(u==null?void 0:u.duration)||"0:00",onEndCall:()=>{N(null)}}),!L&&e.jsx("div",{className:"absolute top-4 right-4 z-40 w-80",children:e.jsx(ot,{})}),e.jsxs("div",{className:`flex flex-col border-r border-border bg-card transition-all ${L?"w-96 flex-shrink-0":"flex-1"}`,children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-muted-foreground mb-0.5",children:"Today's"}),e.jsx("h1",{className:"text-xl font-semibold text-foreground",children:"Call List"})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:[A,e.jsxs("span",{className:"text-base font-normal text-muted-foreground",children:["/",q]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"called today"})]})]}),e.jsx("div",{className:"w-full h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-green-500 rounded-full transition-all",style:{width:`${q?A/q*100:0}%`}})}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx(Fe,{placeholder:"Search clients…",value:c,onChange:t=>v(t.target.value),className:"pl-9 h-8 text-[13px]"})]}),e.jsx("div",{className:"flex gap-1 bg-muted/50 rounded-lg p-1",children:[{key:"all",label:`All (${k.length})`},{key:"not_called",label:`To Call (${q-A})`},{key:"called",label:`Called (${A})`}].map(t=>e.jsx("button",{onClick:()=>P(t.key),className:`flex-1 text-[11px] font-medium py-1 rounded-md transition-all ${w===t.key?"bg-card shadow-sm text-foreground":"text-muted-foreground hover:text-foreground"}`,children:t.label},t.key))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto divide-y divide-border",children:[$&&e.jsx("div",{className:"text-center py-8 text-[13px] text-muted-foreground animate-pulse",children:"Loading clients…"}),!$&&H.map(t=>{var n,a,d;const r=M[t.id],m=Ie(t),x=(L==null?void 0:L.id)===t.id;return e.jsx("button",{onClick:()=>z(t),className:`w-full text-left px-4 py-3 transition-colors hover:bg-muted/40 ${x?"bg-primary/5 border-l-2 border-l-primary":""} ${r?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`mt-1 w-2.5 h-2.5 rounded-full flex-shrink-0 ${r?r.outcome==="reached"?"bg-green-500":r.outcome==="voicemail"?"bg-amber-400":"bg-gray-400":"bg-red-400 animate-pulse"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground truncate",children:[t.first_name," ",t.last_name]}),(t.is_minor||t.is_dependent)&&e.jsx("span",{className:"flex-shrink-0 text-[9px] font-bold px-1.5 py-0.5 rounded-full bg-orange-100 text-orange-700 border border-orange-200 uppercase tracking-wide",children:"Minor"})]}),r?e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full flex-shrink-0 font-medium ${r.outcome==="reached"?"bg-green-100 text-green-700":r.outcome==="voicemail"?"bg-amber-100 text-amber-700":"bg-gray-100 text-gray-600"}`,children:r.outcome==="reached"?"✓ Reached":r.outcome==="voicemail"?"📱 VM":"✗ No Answer"}):e.jsx(B,{className:"w-3.5 h-3.5 text-red-400 flex-shrink-0"})]}),t._isOrphanMinor&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5 text-[10px] text-orange-600 bg-orange-50 border border-orange-200 rounded-lg px-2 py-1",children:[e.jsx(ve,{className:"w-3 h-3 flex-shrink-0"}),"Minor record — no primary guardian linked."," ",t.parent_client_id&&b[t.parent_client_id]&&e.jsx(we,{to:`/clients/${t.parent_client_id}`,onClick:p=>p.stopPropagation(),className:"underline font-semibold",children:"View Primary →"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[e.jsx(ke,{stage:t.stage}),e.jsx(Ce,{risk:t.risk_level})]}),e.jsxs("div",{className:"flex gap-1 mt-1.5 flex-wrap",children:[m.slice(0,2).map((p,F)=>e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${p.color}`,children:p.label},F)),m.length>2&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",m.length-2]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[t.phone&&e.jsx("p",{className:"text-[11px] text-muted-foreground font-mono",children:t.phone}
1),g[t.id]&&!r&&e.jsxs("p",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(Se,{className:"w-2.5 h-2.5"})," Last: ",$e(g[t.id].date)]})]}),((n=t._familyMembers)==null?void 0:n.length)>0&&e.jsxs("div",{className:"mt-1.5 flex flex-wrap gap-1",children:[(a=t._minors)==null?void 0:a.map(p=>e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-blue-50 text-blue-600 border border-blue-100",children:["👶 ",p.first_name]},p.id)),(d=t._otherAdults)==null?void 0:d.map(p=>e.jsxs("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-gray-50 text-gray-500 border border-gray-100",children:["👤 ",p.first_name]},p.id))]})]})]})},t.id)}),!$&&H.length===0&&e.jsx("div",{className:"text-center py-12 text-[13px] text-muted-foreground",children:w==="called"?"No calls logged yet today":"No clients to call"})]})]}),L?e.jsx("div",{className:"flex-1 min-w-0 bg-background overflow-hidden flex flex-col",children:e.jsx(dt,{client:L,allLogs:C,lastContactMap:g,onClose:()=>z(null),onLogged:G,onCallStart:t=>N({phoneNumber:t,duration:"0:00",startTime:Date.now()}),onCallEnd:()=>N(null),activeCall:u,onTransfer:K,onQueue:l,onCancelPending:h})}):e.jsxs("div",{className:"flex-1 hidden lg:flex flex-col items-center justify-center text-center px-8 bg-muted/10",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-primary/10 flex items-center justify-center mb-4",children:e.jsx(B,{className:"w-7 h-7 text-primary"})}),e.jsx("h3",{className:"text-base font-semibold text-foreground mb-1",children:"Select a client to log a call"}),e.jsx("p",{className:"text-[13px] text-muted-foreground max-w-xs",children:"Clients are sorted by risk level. Uncalled clients are highlighted. Track outcomes and notes for each call."})]})]})}export{St 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.