1import{a7 as Dt,g as Ft,e as Lt,V as Kt,r as u,i as Rt,f as Ut,k as N,W as h,d as m,j as e,Y as Z,aO as Qt,B as l,$ as Ot,a0 as Bt,a1 as Gt,a2 as _t,aP as Vt,H as Ke,as as Yt,Q as Ht,v as Re,aQ as Wt,P as ee,a4 as te,L as b,M as Ue,l as se,Z as Jt,q as Xt,m as Zt,K as I,aR as E,aS as q,N as M,A as ae,aJ as ie,w as re,x as ne,y as le,z as ce,E as oe,a6 as de,F as me,C as es,X as Qe,h as Oe,R as ts,a8 as ss,aC as Be}from"./index-DBkfqdJO.js";import{T as ue}from"./textarea-Cx8Vc1C_.js";import{T as as,a as is,b as he,c as xe}from"./tabs-BTXZVVnv.js";import{A as rs}from"./agent-consent-dialog-oGRUsmbe.js";import{k as pe,a as ns,b as Ge,A as _e}from"./agent-scopes-DTWqcp9r.js";import{S as Ve}from"./switch-C5yVWbKs.js";import{A as ls}from"./agent-audit-list-DageaanI.js";import{f as cs}from"./my-agents-DoosaV1X.js";import{A as os}from"./arrow-left-CnKT2g2k.js";import{C as ge}from"./check-Bwmdmnj-.js";import{U as ds}from"./user-minus-BXKPRdhe.js";import{U as fe}from"./user-plus-Baf_mu_d.js";import{B as Ye}from"./ban-DxTyf_Wb.js";import{C as He}from"./clock-BejK2pMx.js";import{C as ms}from"./chevron-down-BkPkC3EN.js";import{B as us}from"./brain-DOv0wVyr.js";import{P as hs}from"./plus-BnnhYguj.js";import{P as We}from"./pencil-CLRWHqiO.js";import{T as Je}from"./trash-2-DW-jBLxI.js";import{D as xs}from"./database-RJ63UY_R.js";import{L as ps}from"./list-DE5moYPz.js";import{P as Xe}from"./phone-missed-Aj3Mik2u.js";import{P as Ze,a as et}from"./phone-outgoing-Cj7L0v8E.js";import"./index-BXYadDV1.js";import"./checkbox-45Pbvt93.js";import"./index-CiEuKCoS.js";import"./index-CiOIYZjn.js";import"./dialog-CdvtIQqm.js";import"./useInfiniteQuery-8YEWEmUy.js";import"./formatDistanceToNow-fKExwOYA.js";const gs=["000-000-000","999-999-999","900-900-900"];function Ws(){const[fs,tt]=Dt("/user/:id"),[bs,x]=Ft(),{user:st}=Lt(),be=Kt()?.startCall,i=tt?.id,[P,at]=u.useState("overview"),[it,rt]=u.useState(new Set),[ye,$]=u.useState(!1),{toast:d}=Rt(),o=Ut(),p=st?.id===i,{data:C,isLoading:nt,error:lt}=N({queryKey:["/api/users",i],queryFn:async()=>(await m("GET",`/api/users/${i}`)).json(),enabled:!!i}),je=h({mutationFn:async t=>(await m("PATCH",`/api/contacts/${i}/agent-grant`,{autoExecute:t})).json(),onSuccess:()=>o.invalidateQueries({queryKey:["/api/users",i]}),onError:t=>d({title:"Couldn't save",description:t?.message||"Try again",variant:"destructive"})}),we=h({mutationFn:async t=>(await m("PATCH",`/api/contacts/${i}/agent-grant`,{initiation:t})).json(),onSuccess:()=>o.invalidateQueries({queryKey:["/api/users",i]}),onError:t=>d({title:"Couldn't save",description:t?.message||"Try again",variant:"destructive"})}),[ct,D]=u.useState(!1),k=h({mutationFn:async t=>(await m("POST","/api/contacts/request",{toUserId:i,...t?{scopes:t}:{}})).json(),onSuccess:t=>{D(!1),t?.status==="accepted"?(d({title:"Agent added",description:"It's now in your contacts."}),o.invalidateQueries({queryKey:["/api/contacts"]})):d({title:"Request sent!",description:"Connection request has been sent."}),o.invalidateQueries({queryKey:["/api/users",i]}),o.invalidateQueries({queryKey:["/api/contacts/requests/sent"]})},onError:t=>{d({title:"Error",description:t.message||"Failed to send request",variant:"destructive"})}}),F=h({mutationFn:async()=>(await m("POST",`/api/contacts/requests/${C?.incomingRequestId}/accept`)).json(),onSuccess:()=>{d({title:"Request accepted!",description:"You are now connected."}),o.invalidateQueries({queryKey:["/api/users",i]}),o.invalidateQueries({queryKey:["/api/contacts/requests"]}),o.invalidateQueries({queryKey:["/api/contacts"]})},onError:t=>{d({title:"Error",description:t.message||"Failed to accept request",variant:"destructive"})}}),L=h({mutationFn:async()=>(await m("POST","/api/chats",{participantId:i})).json(),onSuccess:t=>{x(`/chat/${t.id}`)},onError:t=>{d({title:"Error",description:t.message||"Failed to start chat",variant:"destructive"})}}),K=h({mutationFn:async()=>(await m("DELETE",`/api/contacts/${i}`)).json(),onSuccess:()=>{d({title:"Contact removed",description:"This contact has been removed."}),o.invalidateQueries({queryKey:["/api/users",i]}),o.invalidateQueries({queryKey:["/api/contacts"]}),o.invalidateQueries({queryKey:["/api/chats"]})},onError:t=>{d({title:"Error",description:t.message||"Failed to remove contact",variant:"destructive"})}}),{data:R}=N({queryKey:["/api/users",i,"blocked"],queryFn:async()=>(await m("GET",`/api/users/${i}/blocked`)).json(),enabled:!!i&&!p}),ve=()=>{o.invalidateQueries({queryKey:["/api/users",i,"blocked"]}),o.invalidateQueries({queryKey:[`/api/users/${i}/blocked`]}),o.invalidateQueries({queryKey:["/api/chats"]}),o.invalidateQueries({queryKey:["/api/feed"]}),o.invalidateQueries({queryKey:["/api/contacts"]}),o.invalidateQueries({queryKey:["/api/contacts/requests"]}),o.invalidateQueries({queryKey:["/api/contacts/requests/sent"]}),o.invalidateQueries({queryKey:["/api/users",i]}),o.invalidateQueries({queryKey:["/api/contacts",i,"activity"]})},Ne=h({mutationFn:async()=>(await m("POST",`/api/users/${i}/block`)).json(),onSuccess:()=>{d({title:"User blocked",description:"This user has been blocked."}),ve()},onError:t=>{d({title:"Error",description:t.message||"Failed to block user",variant:"destructive"})}}),U=h({mutationFn:async()=>(await m("DELETE",`/api/users/${i}/block`)).json(),onSuccess:()=>{d({title:"User unblocked",description:"This user has been unblocked."}),ve()},onError:t=>{d({title:"Error",description:t.message||"Failed to unblock user",variant:"destructive"})}}),Q=R?.isBlocked??!1,O=R?.blockedByMe??!1;R?.blockedByThem;const{data:ot,isLoading:dt,isFetching:mt,refetch:ut}=N({queryKey:["/api/ai/insights",i],queryFn:async()=>(await m("GET",`/api/ai/insights/${i}`)).json(),enabled:!!i&&!p&&P==="data"}),Ce=ot?.insights||[],[ht,ke]=u.useState(!1),B=ht||mt,xt=async()=>
1{if(!(!i||B)){ke(!0);try{await m("POST",`/api/ai/contacts/${i}/catch-up`)}catch{}finally{ke(!1)}await ut()}},{data:Te}=N({queryKey:["/api/agents/installed"],queryFn:async()=>(await m("GET","/api/agents/installed")).json(),enabled:!!i&&!p}),$e=u.useMemo(()=>(Te?.installs??[]).some(t=>t.agentId==="relationship-memory"&&t.enabled),[Te]),{data:pt,isLoading:gt}=N({queryKey:["/api/agents/relationship-memory/memories",i],queryFn:async()=>(await m("GET",`/api/agents/relationship-memory/memories?contactId=${encodeURIComponent(i)}`)).json(),enabled:!!i&&!p&&P==="data"&&$e}),Se=pt?.memories??[],[G,Ae]=u.useState(""),[ft,_]=u.useState(null),[V,S]=u.useState(""),Y=()=>{o.invalidateQueries({queryKey:["/api/agents/relationship-memory/memories",i]})},H=h({mutationFn:async t=>(await m("POST","/api/agents/relationship-memory/memories",{contactId:i,content:t})).json(),onSuccess:()=>{Ae(""),Y()},onError:t=>d({title:"Couldn't save",description:t.message||"Try again",variant:"destructive"})}),ze=h({mutationFn:async({id:t,content:r})=>(await m("PATCH",`/api/agents/relationship-memory/memories/${t}`,{content:r})).json(),onSuccess:()=>{_(null),S(""),Y()},onError:t=>d({title:"Couldn't update",description:t.message||"Try again",variant:"destructive"})}),Ie=h({mutationFn:async t=>(await m("DELETE",`/api/agents/relationship-memory/memories/${t}`)).json(),onSuccess:()=>Y(),onError:t=>d({title:"Couldn't delete",description:t.message||"Try again",variant:"destructive"})}),[bt,W]=u.useState(null),[J,A]=u.useState(""),[Ee,qe]=u.useState(null),Me=()=>{o.invalidateQueries({queryKey:["/api/ai/insights",i]})},Pe=h({mutationFn:async({id:t,content:r})=>(await m("PATCH",`/api/ai/insights/${t}`,{content:r})).json(),onSuccess:()=>{W(null),A(""),Me()},onError:t=>d({title:"Couldn't update",description:t.message||"Try again",variant:"destructive"})}),De=h({mutationFn:async t=>(await m("DELETE",`/api/ai/insights/${t}`)).json(),onSuccess:()=>Me(),onError:t=>d({title:"Couldn't delete",description:t.message||"Try again",variant:"destructive"})}),yt=async t=>{if(!Ee){qe(t);try{const r=await m("GET",`/api/ai/insights/${t}/source`),{source:a}=await r.json();a.kind==="message"?x(`/chat/${a.conversationId}?m=${a.messageId}`):a.kind==="email"?x(`/emails/${a.threadId}`):a.kind==="call"?x(`/calls/${a.callId}`):x(`/feed/user/${a.authorId}/${a.postId}`)}catch{d({title:"Source no longer available",description:"The message, call or post this came from can't be opened any more."})}finally{qe(null)}}},{data:jt,isLoading:wt}=N({queryKey:["/api/contacts",i,"activity"],queryFn:async()=>(await m("GET",`/api/contacts/${i}/activity`)).json(),enabled:!!i&&P==="activity"}),j=jt?.activities||[],vt=u.useMemo(()=>{if(j.length===0)return[];const t=[];let r={type:j[0].type,count:1,items:[j[0]],timestamp:j[0].timestamp};for(let a=1;a<j.length;a++){const c=j[a];c.type===r.type?(r.count++,r.items.push(c)):(t.push(r),r={type:c.type,count:1,items:[c],timestamp:c.timestamp})}return t.push(r),t},[j]),Fe=t=>{const r=new Date,a=new Date(t),c=Math.floor((r.getTime()-a.getTime())/1e3);if(c<60)return"just now";const f=Math.floor(c/60);if(f<60)return`${f}m ago`;const w=Math.floor(f/60);if(w<24)return`${w}h ago`;const v=Math.floor(w/24);return v<7?`${v}d ago`:a.toLocaleDateString("en-US",{month:"short",day:"numeric"})},Le=t=>{const r=Math.floor(t/60),a=t%60;return`${r}:${a.toString().padStart(2,"0")}`},s=C?.user,g=C?.isContact??!1,Nt=s?.userType==="agent"?e.jsx(rs,{agent:s,open:ct,onOpenChange:D,onConfirm:t=>k.mutate(t),pending:k.isPending}):null,Ct=C?.hasPendingRequest??!1,kt=C?.hasIncomingRequest??!1,z=s?.userType==="ai"?"AI":s?.userType==="agent"?"Agent":s?.userType==="business"?"Business":"Person";return nt?e.jsxs(Z,{className:"h-full bg-black text-white flex flex-col",children:[e.jsx("div",{className:"pt-safe-24 shrink-0"}),e.jsx(Qt,{})]}):lt||!s?e.jsxs(Z,{className:"h-full bg-black text-white flex flex-col items-center justify-center gap-4",children:[e.jsx("p",{className:"text-white/50",children:"User not found"}),e.jsx(l,{variant:"ghost",onClick:()=>window.history.back(),children:"Go Back"})]}):e.jsxs(Z,{className:"h-full bg-black text-white flex flex-col relative overflow-hidden",children:[Nt,e.jsx("div",{className:"fixed top-6 left-6 z-30 pt-safe",children:e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>window.history.back(),className:"-ml-2 text-white/70 hover:text-white hover:bg-white/10 rounded-full",children:e.jsx(os,{size:24})})}),e.jsxs("div",{className:"fixed inset-0 z-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute top-0 left-0 w-full h-[500px] bg-gradient-to-b from-blue-900/20 via-purple-900/10 to-transparent"}),e.jsx("div",{className:"absolute -top-[20%] -right-[20%] w-[500px] h-[500px] bg-blue-600/10 rounded-full blur-[100px]"}),e.jsx("div",{className:"absolute top-[10%] -left-[10%] w-[300px] h-[300px] bg-purple-600/10 rounded-full blur-[80px]"})]}),e.jsxs("div",{className:"relative z-10 flex-1 flex flex-col pb-32 overflow-y-auto ios-scroll",children:[e.jsx("div",{className:"pt-safe-24"}),Q&&!p&&e.jsx("div",{className:`mx-4 mb-2 px-4 py-3 rounded-xl border ${O?"bg-red-500/10 border-red-500/20":"bg-orange-500/10 border-orange-500/20"}`,children:e.jsx("p",{className:`text-sm text-center ${O?"text-red-400":"text-orange-400"}`,children:O?"You have blocked this user":"This user is unavailable"})}),e.jsxs("div",{className:"px-6 flex flex-col gap-8",children:[e.jsxs("div",{className:"flex flex-col items-center -mt-4",children:[e.jsxs("div",{className:"relative mb-4 group",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full blur-xl opacity-50 group-hover:opacity-75 transition-opacity"}),e.jsxs(Ot,{className:"h-32 w-32 border-4 border-black relative z-10 shadow-2xl",children:[e.jsx(Bt,{src:Gt(s.avatarUrl)||`https://api.dicebear.com/9.x/bottts-neutral/svg?seed=${s.nmbr}&eyes=bulging,dizzy,eva,frame1,frame2,glow,happy,robocop,round,roundFrame01,roundFrame02,sensor,shade01`}),e.jsx(_t,{children:s.displayName?.charAt(0)||"?"})]})]}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h1",{className:"text-3xl font-bold notranslate",dir:"auto",translate:"no",children:s.displayName}),e.jsx(Vt,{variant:"secondary",className:Ke("hover:bg-opacity-100 capitalize",z==="AI"?"bg-purple-500/20 text-purple-400 hover:bg-purple-500/20":z==="Agent"?"bg-teal-500/15 text-teal-300 hover:bg-teal-500/15":z==="Business"?"bg-yellow-500/10 text-yellow-500 hover:bg-yellow-500/10":"bg-orange-200/10 text-orange-200 hover:bg-orange-200/10"),
1children:z.toLowerCase()})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 sm:gap-3",children:[e.jsxs("div",{className:"pl-3 sm:pl-4 pr-2 py-1.5 rounded-full bg-white/5 border border-white/10 backdrop-blur-md flex items-center gap-2 sm:gap-3",children:[e.jsx("span",{className:"font-['Space_Grotesk'] text-base sm:text-lg text-white/90 tracking-wide whitespace-nowrap",children:(s.nmbr||"000-000-000").replace(/-/g," - ")}),e.jsx("div",{className:"h-4 w-px bg-white/10"}),e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full hover:bg-white/10 text-white/70 hover:text-white transition-colors",onClick:()=>{navigator.clipboard.writeText(s.nmbr||""),d({description:e.jsxs(e.Fragment,{children:[e.jsx(Ht,{})," copied to clipboard"]})})},children:e.jsx(Yt,{size:14})})]}),p&&e.jsx(Re,{href:`/qr-code/${s.id}`,children:e.jsx(l,{variant:"outline",size:"icon",className:"rounded-full border-white/10 bg-white/5 hover:bg-white/10 text-white h-11 w-11",children:e.jsx(Wt,{size:18})})})]}),!Q&&e.jsxs("div",{className:"flex gap-4 mt-6",children:[e.jsxs("div",{className:"relative",children:[e.jsxs(l,{variant:"outline",className:`rounded-full border-white/10 gap-2 h-10 px-6 ${g&&!p&&s?.nmbr!=="000-000-000"&&s?.userType!=="agent"?"hover:bg-green-500/10 hover:border-green-500/30 hover:text-green-400":"opacity-50 cursor-not-allowed"}`,disabled:!g||p||s?.nmbr==="000-000-000"||s?.userType==="agent",onClick:()=>$(!ye),"data-testid":"button-call-profile",children:[e.jsx(ee,{size:16})," Call"]}),ye&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>$(!1)}),e.jsxs("div",{className:"absolute left-0 top-full mt-2 z-50 bg-zinc-800 border border-white/10 rounded-xl p-1 min-w-[160px] shadow-xl",children:[e.jsxs("button",{onClick:()=>{$(!1),s&&be?.(s.id,s.displayName||"Unknown",s.avatarUrl||null,s.nmbr,"audio")},className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-white/5 transition-colors text-left","data-testid":"button-voice-call-profile",children:[e.jsx(ee,{size:16,className:"text-green-400"}),e.jsx("span",{className:"text-sm",children:"Voice Call"})]}),e.jsxs("button",{onClick:()=>{$(!1),s&&be?.(s.id,s.displayName||"Unknown",s.avatarUrl||null,s.nmbr,"video")},className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg hover:bg-white/5 transition-colors text-left","data-testid":"button-video-call-profile",children:[e.jsx(te,{size:16,className:"text-blue-400"}),e.jsx("span",{className:"text-sm",children:"Video Call"})]})]})]})]}),e.jsxs(l,{variant:"outline",className:"rounded-full border-white/10 hover:bg-white/5 gap-2 h-10 px-6",onClick:()=>L.mutate(),disabled:L.isPending||!g,children:[L.isPending?e.jsx(b,{size:16,className:"animate-spin"}):e.jsx(Ue,{size:16})," Chat"]}),e.jsxs(l,{variant:"outline",className:"rounded-full border-white/10 hover:bg-white/5 gap-2 h-10 px-6",onClick:()=>x(`/emails?compose=true&recipientId=${i}`),disabled:!g,children:[e.jsx(se,{size:16})," Email"]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-3",children:[e.jsxs(l,{variant:"ghost",size:"sm",onClick:()=>Xt(x),className:"text-purple-400 hover:text-purple-300 hover:bg-purple-500/10 gap-1 h-9 px-3","data-testid":"button-ask-nmbr-user-profile",children:[e.jsx(Jt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:"Ask nmbr"})]}),e.jsx(Re,{href:`/feed/user/${s?.id}`,children:e.jsxs(l,{variant:"ghost",size:"sm",className:"text-purple-400 hover:text-purple-300 hover:bg-purple-500/10 gap-1 h-9 px-3","data-testid":"button-user-feed",children:[e.jsx(Zt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:p?"My Feed":`${s?.firstName||s?.displayName?.split(" ")[0]||""}'s Feed`})]})})]})]}),e.jsxs(as,{defaultValue:"overview",className:"w-full",onValueChange:at,children:[e.jsx("div",{className:"w-full pb-2",children:e.jsxs(is,{className:"bg-white/5 border border-white/5 p-1 h-11 rounded-xl flex w-full",children:[e.jsx(he,{value:"overview",className:"flex-1 rounded-lg data-[state=active]:bg-purple-500/20 data-[state=active]:text-purple-300 text-white/50 text-sm h-full",children:"Overview"}),s?.userType!=="agent"&&e.jsx(he,{value:"data",className:"flex-1 rounded-lg data-[state=active]:bg-cyan-500/20 data-[state=active]:text-cyan-300 text-white/50 text-sm h-full",children:"Insights"}),e.jsx(he,{value:"activity",className:"flex-1 rounded-lg data-[state=active]:bg-amber-500/20 data-[state=active]:text-amber-300 text-white/50 text-sm h-full",children:"Activity"})]})}),e.jsxs(xe,{value:"overview",className:"space-y-6 mt-2",children:[e.jsxs(I,{className:"bg-white/5 border-white/5 border backdrop-blur-sm",children:[e.jsx(E,{children:e.jsx(q,{className:"text-sm font-medium text-white/50 uppercase tracking-wider",children:"Bio"})}),e.jsx(M,{className:"text-white/80 leading-relaxed",children:s.bio||"No bio available for this contact."})]}),s.userType==="agent"&&e.jsxs(I,{className:"bg-white/5 border-white/5 border backdrop-blur-sm","data-testid":"card-agent-access",children:[e.jsx(E,{children:e.jsx(q,{className:"text-sm font-medium text-white/50 uppercase tracking-wider",children:g?"Access you granted":"What it asks for"})}),e.jsxs(M,{className:"space-y-2",children:[(()=>{const t=g?pe(s.grantedScopes):pe(s.requestedScopes);if(t.length===0)return e.jsx("p",{className:"text-sm text-white/60",children:g?"Nothing â it can only be a contact.":"No access â it can only be added."});const r=Array.isArray(s.autoExecute)?s.autoExecute:[];return t.map(a=>{const c=g?ns[a]:void 0,f=!!c&&r.includes(c);return e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ge,{size:14,className:"text-teal-300 mt-1 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-white/90",children:Ge[a].name}),e.jsx("p",{className:"text-xs text-white/50",children:Ge[a].description}),c&&e.jsxs("label",{className:"flex items-center justify-between gap-3 mt-1.5 text-xs text-white/70","data-testid":`agent-auto-execute-${c}`,children:[e.jsx("span",{children:f?`Runs without asking â each ${_e[c].noun} still shows in the chat`:"Asks first (approval card)"}),e.jsx(Ve,{checked:f,disabled:je.isPending,onCheckedChange:w=>je.mutate(w?[...r.filter(v=>v!==c),c]:r.filter(v=>v!==c)),"aria-label":`Let it ${_e[c].verb}
1 without asking`})]})]})]},a)})})(),g&&pe(s.grantedScopes).includes("messages:write")&&(()=>{const t=s.initiation==="reply_only";return e.jsxs("label",{className:"flex items-center justify-between gap-3 pt-2 mt-1 border-t border-white/5 text-xs text-white/70","data-testid":"agent-initiation",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm text-white/90",children:"Replies only"}),t?"It can message you for 24 hours after you write to it, and can't start a conversation on its own":"Off: it can message you any time"]}),e.jsx(Ve,{checked:t,disabled:we.isPending,onCheckedChange:r=>we.mutate(r?"reply_only":"any"),"aria-label":"Only let it reply to you"})]})})(),g&&e.jsx("p",{className:"text-xs text-white/40 pt-1",children:"Removing the contact takes all of this back."})]})]}),s.userType==="agent"&&!p&&e.jsxs(I,{className:"bg-white/5 border-white/5 border backdrop-blur-sm","data-testid":"card-agent-activity",children:[e.jsx(E,{children:e.jsx(q,{className:"text-sm font-medium text-white/50 uppercase tracking-wider",children:"What it did on your account"})}),e.jsx(M,{children:e.jsx(ls,{queryKey:["/api/contacts",i,"agent-audit"],fetchPage:t=>cs(i,t),view:"person",emptyText:"Nothing yet. Its proposals, your decisions, anything nmbr created for it and any refused messages will show here."})})]}),e.jsxs("div",{className:"mt-6 flex justify-center",children:[s?.nmbr==="000-000-000"?null:g?e.jsxs(ae,{children:[e.jsx(ie,{asChild:!0,children:e.jsxs(l,{variant:"ghost",className:"text-red-500 hover:text-red-400 hover:bg-red-500/10 gap-2 h-10 px-6 rounded-full",children:[e.jsx(ds,{size:16})," Remove Contact"]})}),e.jsxs(re,{className:"bg-card border-white/10 rounded-2xl",children:[e.jsxs(ne,{children:[e.jsx(le,{className:"text-lg",children:"Remove this contact?"}),e.jsxs(ce,{className:"text-muted-foreground text-sm",children:["This will remove ",s?.displayName||s?.nmbr," from your contacts. You can always add them back later by sending a new contact request."]})]}),e.jsxs(oe,{className:"flex-col sm:flex-row gap-2 sm:gap-2",children:[e.jsx(de,{className:"w-full sm:w-auto text-white bg-white/10 border-white/20 hover:bg-white/20 rounded-full h-10 px-6",children:"Cancel"}),e.jsx(me,{onClick:()=>K.mutate(),disabled:K.isPending,className:"w-full sm:w-auto text-red-400 bg-red-500/10 border border-red-500/20 hover:bg-red-500/20 rounded-full h-10 px-6",children:K.isPending?e.jsx(b,{className:"w-4 h-4 animate-spin"}):"Remove Contact"})]})]})]}):Ct?e.jsxs(l,{disabled:!0,className:"bg-white/10 text-white/50 gap-2 h-10 px-6 rounded-full font-medium cursor-not-allowed",children:[e.jsx(fe,{size:16})," Request Pending"]}):kt?e.jsxs(l,{variant:"outline",className:"text-green-400 bg-green-500/10 border-green-500/20 hover:bg-green-500/20 gap-2 h-10 px-6 rounded-full font-medium",onClick:()=>F.mutate(),disabled:F.isPending,children:[F.isPending?e.jsx(b,{size:16,className:"animate-spin"}):e.jsx(fe,{size:16}),"Accept Request"]}):e.jsxs(l,{variant:"outline",className:"text-green-400 bg-green-500/10 border-green-500/20 hover:bg-green-500/20 gap-2 h-10 px-6 rounded-full font-medium",onClick:()=>s?.userType==="agent"?D(!0):k.mutate(void 0),disabled:k.isPending,"data-testid":"button-add-contact",children:[k.isPending?e.jsx(b,{size:16,className:"animate-spin"}):e.jsx(fe,{size:16}),s?.userType==="agent"?"Add Agent":"Add Contact"]}),!p&&!gs.includes(s?.nmbr||"")&&(Q?e.jsxs(l,{variant:"ghost",onClick:()=>U.mutate(),disabled:U.isPending,className:"gap-2 h-10 px-6 rounded-full text-green-400 hover:text-green-300 hover:bg-green-500/10","data-testid":"button-unblock-user",children:[U.isPending?e.jsx(b,{size:16,className:"animate-spin"}):e.jsx(Ye,{size:16}),"Unblock User"]}):e.jsxs(ae,{children:[e.jsx(ie,{asChild:!0,children:e.jsxs(l,{variant:"ghost",className:"gap-2 h-10 px-6 rounded-full text-red-400 hover:text-red-300 hover:bg-red-500/10","data-testid":"button-block-user",children:[e.jsx(Ye,{size:16})," Block User"]})}),e.jsxs(re,{className:"bg-card border-white/10 rounded-2xl",children:[e.jsxs(ne,{children:[e.jsx(le,{className:"text-lg",children:"Block this user?"}),e.jsx(ce,{className:"text-muted-foreground text-sm",children:"They won't be able to message you or see your profile. You can unblock them anytime."})]}),e.jsxs(oe,{className:"flex-col sm:flex-row gap-2 sm:gap-2",children:[e.jsx(de,{className:"w-full sm:w-auto text-white bg-white/10 border-white/20 hover:bg-white/20 rounded-full h-10 px-6",children:"Cancel"}),e.jsx(me,{onClick:()=>Ne.mutate(),className:"w-full sm:w-auto bg-transparent border border-red-500/50 text-red-400 hover:bg-red-500/20 rounded-full h-10 px-6",children:Ne.isPending?e.jsx(b,{className:"w-4 h-4 animate-spin"}):"Block User"})]})]})]}))]})]}
1),e.jsxs(xe,{value:"activity",className:"space-y-4 mt-2 animate-in fade-in slide-in-from-bottom-4 duration-300",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(He,{size:18,className:"text-amber-400"}),e.jsx("h3",{className:"text-white/80 font-medium text-sm",children:"Activity Timeline"})]}),wt?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(b,{className:"w-6 h-6 animate-spin text-amber-400"})}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"relative mb-4",children:e.jsx("div",{className:"w-16 h-16 rounded-full bg-gradient-to-br from-amber-500/20 to-amber-600/10 flex items-center justify-center",children:e.jsx(He,{size:28,className:"text-amber-400/60"})})}),e.jsx("p",{className:"text-white/60 font-medium mb-1",children:"No activity yet"}),e.jsx("p",{className:"text-white/40 text-sm max-w-[240px]",children:"Start chatting, calling, or emailing to see your interaction history here."})]}):e.jsx("div",{className:"space-y-1.5",children:vt.map((t,r)=>{const a=t.items[0],c=t.count>1,f=c&&(t.type==="call"||t.type==="email"),w=it.has(r),v=()=>t.type==="chat"?e.jsx(Ue,{className:"w-4 h-4 text-blue-400"}):t.type==="email"?e.jsx(se,{className:"w-4 h-4 text-purple-400"}):t.type==="call"?c?e.jsx(ee,{className:"w-4 h-4 text-green-400"}):a.callStatus==="missed"||a.callStatus==="declined"?e.jsx(Xe,{className:"w-4 h-4 text-red-400"}):a.callDirection==="outgoing"?e.jsx(Ze,{className:"w-4 h-4 text-white/70"}):e.jsx(et,{className:"w-4 h-4 text-green-400"}):null,Tt=!c&&t.type==="call"&&(a.callStatus==="missed"||a.callStatus==="declined"),$t=()=>{if(c){if(t.type==="chat")return`${t.count} messages`;if(t.type==="call")return`${t.count} calls`;if(t.type==="email")return`${t.count} emails`}if(t.type==="chat")return a.content||"Message";if(t.type==="email")return a.emailSubject||"No Subject";if(t.type==="call"){if(a.callStatus==="missed"||a.callStatus==="declined")return"Missed";const y=a.callDirection==="outgoing"?"Outgoing":"Incoming",T=a.callDuration&&a.callDuration>0?` · ${Le(a.callDuration)}`:"";return`${y}${T}`}return""},St=()=>{if(c||t.type!=="call")return null;const n=[];return a.callType==="video"&&n.push(e.jsx(te,{size:12,className:"text-white/40"},"video")),(a.hasTranscript||a.hasSummary)&&(n.push(e.jsx("span",{className:"text-white/40",children:"·"},"dot")),n.push(e.jsx("span",{className:"text-purple-400/60 text-[10px]",children:"View summary"},"summary"))),n.length>0?n:null},At=()=>t.type==="chat"?"bg-blue-500/20 text-blue-300":t.type==="email"?"bg-purple-500/20 text-purple-300":t.type==="call"?"bg-green-500/20 text-green-300":"",zt=()=>t.type==="chat"?"Chat":t.type==="email"?"Email":t.type==="call"?"Call":"",It=()=>{if(f){rt(n=>{const y=new Set(n);return y.has(r)?y.delete(r):y.add(r),y});return}t.type==="chat"&&a.conversationId?x(`/chat/${a.conversationId}`):t.type==="call"&&a.callId?x(`/calls/${a.callId}?from=profile&userId=${i}`):t.type==="email"&&a.threadId&&x(`/emails/${a.threadId}?from=profile&userId=${i}`)};return e.jsxs("div",{children:[e.jsxs("div",{onClick:It,className:"flex items-center gap-3 p-3 rounded-lg bg-white/[0.03] border border-white/[0.05] hover:bg-white/[0.06] cursor-pointer transition-colors","data-testid":`activity-item-${t.type}-${r}`,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/5 flex items-center justify-center shrink-0",children:v()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:`text-sm truncate ${Tt?"text-red-400":"text-white/80"}`,children:$t()}),St()]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${At()}`,children:zt()}),e.jsx("span",{className:"text-[10px] text-white/30",children:Fe(t.timestamp)})]})]}),f&&(w?e.jsx(ms,{className:"w-4 h-4 text-white/30 shrink-0"}):e.jsx(es,{className:"w-4 h-4 text-white/30 shrink-0"}))]}),f&&w&&e.jsx("div",{className:"pl-4 mt-1 space-y-1",children:t.items.map((n,y)=>{const T=n.type==="call"&&(n.callStatus==="missed"||n.callStatus==="declined"),Et=()=>n.type==="call"?T?e.jsx(Xe,{className:"w-3.5 h-3.5 text-red-400"}):n.callDirection==="outgoing"?e.jsx(Ze,{className:"w-3.5 h-3.5 text-white/70"}):e.jsx(et,{className:"w-3.5 h-3.5 text-green-400"}):e.jsx(se,{className:"w-3.5 h-3.5 text-purple-400"}),qt=()=>{if(n.type==="call"){if(T)return"Missed";const X=n.callDirection==="outgoing"?"Outgoing":"Incoming",Pt=n.callDuration&&n.callDuration>0?` · ${Le(n.callDuration)}`:"";return`${X}${Pt}`}return n.emailSubject||"No Subject"},Mt=X=>{X.stopPropagation(),n.type==="call"&&n.callId?x(`/calls/${n.callId}?from=profile&userId=${i}`):n.type==="email"&&n.threadId&&x(`/emails/${n.threadId}?from=profile&userId=${i}`)};return e.jsxs("div",{onClick:Mt,className:"flex items-center gap-2.5 p-2.5 rounded-lg bg-white/[0.02] border border-white/[0.03] hover:bg-white/[0.05] curs
1or-pointer transition-colors","data-testid":`activity-subitem-${n.type}-${r}-${y}`,children:[e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-white/5 flex items-center justify-center",children:Et()}),n.type==="call"&&n.callType==="video"&&e.jsx(te,{size:12,className:"text-white/40"})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:`text-xs truncate ${T?"text-red-400":"text-white/70"}`,children:qt()}),n.type==="call"&&(n.hasTranscript||n.hasSummary)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/40",children:"·"}),e.jsx("span",{className:"text-purple-400/60 text-[10px]",children:"View summary"})]})]})}),e.jsx("span",{className:"text-[10px] text-white/30 shrink-0",children:Fe(n.timestamp)})]},`${n.type}-${y}`)})})]},`${t.type}-${r}`)})})]}),e.jsxs(xe,{value:"data",className:"space-y-4 mt-2 animate-in fade-in slide-in-from-bottom-4 duration-300",children:[$e&&e.jsxs(I,{className:"bg-white/5 border-white/5 border backdrop-blur-sm",children:[e.jsxs(E,{className:"pb-3",children:[e.jsxs(q,{className:"flex items-center gap-2 text-sm font-medium text-white/70 uppercase tracking-wider",children:[e.jsx(us,{size:16,className:"text-cyan-400"}),"Things to remember"]}),e.jsxs("p",{className:"text-xs text-white/40 mt-1",children:["Tell Mira small facts about ",s?.displayName||"this contact"," (kid's name, coffee order, anniversary). She'll prefer these when nudging you."]})]}),e.jsxs(M,{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ue,{value:G,onChange:t=>Ae(t.target.value),placeholder:"e.g. Daughter Iris just started kindergarten",rows:2,maxLength:2e3,className:"bg-white/5 border-white/10 text-sm text-white placeholder:text-white/30 resize-none","data-testid":"input-mira-memory"}),e.jsx(l,{size:"sm",onClick:()=>H.mutate(G.trim()),disabled:!G.trim()||H.isPending,className:"self-end bg-cyan-500/20 hover:bg-cyan-500/30 text-cyan-200 border border-cyan-500/30","data-testid":"button-add-mira-memory",children:H.isPending?e.jsx(b,{size:14,className:"animate-spin"}):e.jsx(hs,{size:14})})]}),gt?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(b,{className:"w-5 h-5 animate-spin text-cyan-400"})}):Se.length===0?e.jsx("p",{className:"text-xs text-white/40 italic",children:"No memories yet. Add the first one above."}):e.jsx("div",{className:"space-y-1.5",children:Se.map(t=>e.jsx("div",{className:"group flex items-start gap-2 px-2.5 py-2 rounded-lg bg-cyan-500/5 border border-cyan-500/15","data-testid":`mira-memory-${t.id}`,children:ft===t.id?e.jsxs(e.Fragment,{children:[e.jsx(ue,{value:V,onChange:r=>S(r.target.value),rows:2,maxLength:2e3,className:"flex-1 bg-white/5 border-white/10 text-sm text-white resize-none","data-testid":`input-edit-mira-memory-${t.id}`}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>ze.mutate({id:t.id,content:V.trim()}),disabled:!V.trim()||ze.isPending,className:"h-7 w-7 p-0 text-cyan-300","data-testid":`button-save-mira-memory-${t.id}`,children:e.jsx(ge,{size:14})}),e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>{_(null),S("")},className:"h-7 w-7 p-0 text-white/50","data-testid":`button-cancel-mira-memory-${t.id}`,children:e.jsx(Qe,{size:14})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm text-white/90 leading-snug",children:t.content}),t.source==="agent"&&e.jsx("p",{className:"text-[10px] text-cyan-400/70 mt-0.5",children:"saved by Mira"})]}),e.jsxs("div",{className:"flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:[e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>{_(t.id),S(t.content)},className:"h-7 w-7 p-0 text-white/50 hover:text-white","data-testid":`button-edit-mira-memory-${t.id}`,children:e.jsx(We,{size:12})}),e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>Ie.mutate(t.id),disabled:Ie.isPending,className:"h-7 w-7 p-0 text-white/50 hover:text-red-300","data-testid":`button-delete-mira-memory-${t.id}`,children:e.jsx(Je,{size:12})})]})]})},t.id))})]})]}),e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{size:18,className:"text-cyan-400"}),e.jsx("span",{className:"text-sm text-white/70",children:"AI-extracted insights from chats, calls & feed"})]}),e.jsx(l,{variant:"ghost",size:"sm",onClick:xt,disabled:B,className:"text-white/50 hover:text-white",children:e.jsx(ts,{size:14,className:B?"animate-spin":""})})]}),dt?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(b,{className:"w-8 h-8 animate-spin text-cyan-400"})}):Ce.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsxs("div",{className:"relative mb-6",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-gradient-to-br from-cyan-500/20 to-cyan-600/10 flex items-center justify-center",children:e.jsx(ss,{size:36,className:"text-cyan-400"})}),e.jsx("div",{className:"absolute -top-2 -right-2 w-10 h-10 rounded-full bg-gradient-to-br from-cyan-500/30 to-cyan-600/20 flex items-center justify-center",children:e.jsx(Oe,{size:20,className:"text-cyan-400"})})]}),e.jsx("h2",{className:"text-xl font-bold mb-3 text-white",children:"No Data Yet"}),e.jsxs("p",{className:"text-white/50 max-w-xs mb-6",children:["Start chatting with ",s?.dis
1playName||"this contact"," and the AI will automatically extract and remember important facts."]}),e.jsxs("div",{className:"flex flex-col gap-3 text-left w-full max-w-xs",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-white/5 border border-white/5",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cyan-500/10 flex items-center justify-center",children:e.jsx(xs,{size:16,className:"text-cyan-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-white",children:"Smart Capture"}),e.jsx("p",{className:"text-xs text-white/50",children:"Auto-save shared info"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-white/5 border border-white/5",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-cyan-500/10 flex items-center justify-center",children:e.jsx(ps,{size:16,className:"text-cyan-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-white",children:"Organized Records"}),e.jsx("p",{className:"text-xs text-white/50",children:"Easy access to contact data"})]})]})]})]}):e.jsx("div",{className:"space-y-1.5",children:Ce.map(t=>e.jsxs("div",{className:"group flex flex-wrap items-center gap-2 px-2 py-1.5 rounded-lg bg-cyan-500/10 border border-cyan-500/20","data-testid":`insight-${t.id}`,children:[e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-cyan-500/20 text-cyan-300 shrink-0",children:t.category.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(" ")}),bt===t.id?e.jsxs(e.Fragment,{children:[e.jsx(ue,{value:J,onChange:r=>A(r.target.value),rows:2,maxLength:500,className:"flex-1 min-w-0 bg-white/5 border-white/10 text-sm text-white resize-none","data-testid":`input-edit-insight-${t.id}`}),e.jsxs("div",{className:"flex gap-0.5 shrink-0",children:[e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>Pe.mutate({id:t.id,content:J.trim()}),disabled:!J.trim()||Pe.isPending,className:"h-7 w-7 p-0 text-cyan-300","data-testid":`button-save-insight-${t.id}`,children:e.jsx(ge,{size:14})}),e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>{W(null),A("")},className:"h-7 w-7 p-0 text-white/50","data-testid":`button-cancel-insight-${t.id}`,children:e.jsx(Qe,{size:14})})]})]}):e.jsxs(e.Fragment,{children:[t.sourceId?e.jsx("button",{type:"button",onClick:()=>yt(t.id),disabled:Ee===t.id,title:"Open where this was learned",className:"text-sm text-white/80 flex-1 min-w-0 text-left hover:text-white hover:underline underline-offset-2 disabled:opacity-60","data-testid":`button-open-insight-source-${t.id}`,children:t.content}):e.jsx("span",{className:"text-sm text-white/80 flex-1 min-w-0",children:t.content}),t.sourceType&&e.jsx("span",{className:Ke("text-[10px] px-1.5 py-0.5 rounded-full shrink-0",{"bg-blue-500/20 text-blue-300":t.sourceType==="chat","bg-green-500/20 text-green-300":t.sourceType==="call","bg-purple-500/20 text-purple-300":t.sourceType==="feed"}),children:t.sourceType}),e.jsx("span",{className:"text-xs shrink-0 text-white/40",children:t.userEditedAt?"edited by you":t.confidence}),e.jsxs("div",{className:"flex gap-0.5 shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",children:[e.jsx(l,{size:"sm",variant:"ghost",onClick:()=>{W(t.id),A(t.content)},className:"h-7 w-7 p-0 text-white/50 hover:text-white","data-testid":`button-edit-insight-${t.id}`,children:e.jsx(We,{size:12})}),e.jsxs(ae,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(l,{size:"sm",variant:"ghost",disabled:De.isPending,className:"h-7 w-7 p-0 text-white/50 hover:text-red-300","data-testid":`button-delete-insight-${t.id}`,children:e.jsx(Je,{size:12})})}),e.jsxs(re,{className:"bg-card border-white/10 rounded-2xl",children:[e.jsxs(ne,{children:[e.jsx(le,{className:"text-lg",children:"Delete this insight?"}),e.jsxs(ce,{className:"text-muted-foreground text-sm",children:['"',t.content,`" will be removed, and nmbr AI won't add it again from future messages, calls or posts.`]})]}),e.jsxs(oe,{className:"flex-col sm:flex-row gap-2 sm:gap-2",children:[e.jsx(de,{className:"w-full sm:w-auto text-white bg-white/10 border-white/20 hover:bg-white/20 rounded-full h-10 px-6",children:"Cancel"}),e.jsx(me,{onClick:()=>De.mutate(t.id),className:"w-full sm:w-auto text-red-400 bg-red-500/10 border border-red-500/20 hover:bg-red-500/20 rounded-full h-10 px-6","data-testid":`button-confirm-delete-insight-${t.id}`,children:"Delete"})]})]})]})]})]}),Be(t.extractedAt,t.updatedAt)&&e.jsx("span",{className:"basis-full text-right text-[10px] text-white/30","data-testid":`text-insight-age-${t.id}`,children:Be(t.extractedAt,t.updatedAt)})]},t.id))})]})]})]})]})]})}export{Ws 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.