1import{r as x,_ as I,j as e,L as F,aa as B,$ as W,ar as z,a6 as O,a as V,c as H,B as A,a7 as C,a3 as q,m as c,D as J,M as G,P as K,e as Q,J as X,ab as Y,a5 as Z,V as R}from"./index-CZbe8K7G.js";import{B as v}from"./badge-CGfHTdwf.js";import{S as ee}from"./share-2-75eSpF22.js";import{g as se,d as ae,P as te,n as t,I as le,S as ie,m as ne,t as u,f as N,c as E,h as T,a as re,b as ce}from"./activityShared-DZyt_j92.js";import{C as P}from"./clock-DBDuGPpk.js";import{L as U}from"./log-in-BuslI5YA.js";import{H as oe}from"./hash-DKjdQiKa.js";import{C as de}from"./calendar-days-Cc4xsDjn.js";import{A as me}from"./activity-uOJPPv3s.js";import{R as xe}from"./repeat-DDo1RL9v.js";import{E as pe}from"./eye-BYyrkSR-.js";import"./chrome-MnI7Z-Yu.js";function ge({userId:i}){const[d,p]=x.useState(!0),[n,s]=x.useState(null);if(x.useEffect(()=>{let r=!1;return I.adminActivity.getUserUsage(i).then(g=>{!r&&(g!=null&&g.counts)&&s(g.counts)}).catch(()=>{}).finally(()=>{r||p(!1)}),()=>{r=!0}},[i]),d)return e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(F,{className:"h-5 w-5 animate-spin text-slate-400"})});if(!n)return null;const b=[{label:"Meta Campaigns",value:n.meta_campaigns,icon:B,color:"text-blue-600 bg-blue-100"},{label:"Social Posts",value:n.social_posts,icon:ee,color:"text-violet-600 bg-violet-100"},{label:"WA Templates",value:n.whatsapp_templates,icon:W,color:"text-emerald-600 bg-emerald-100"},{label:"WA Messages Sent",value:n.whatsapp_messages_sent,icon:z,color:"text-amber-600 bg-amber-100"}];return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800 mb-4",children:"Feature Usage"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:b.map(r=>e.jsxs("div",{className:"flex items-center gap-3 rounded-xl bg-slate-50 border border-slate-100 p-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${r.color}`,children:e.jsx(r.icon,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-bold text-slate-900 tabular-nums",children:r.value.toLocaleString()}),e.jsx("div",{className:"text-[11px] text-slate-500 font-medium",children:r.label})]})]},r.label))})]})}const M={hidden:{},show:{transition:{staggerChildren:.05,delayChildren:.02}}},m={hidden:{opacity:0,y:12},show:{opacity:1,y:0,transition:{type:"spring",stiffness:300,damping:26}}};function f({icon:i,label:d,value:p,sub:n,accent:s}){return e.jsxs(c.div,{variants:m,className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 mb-2",children:[e.jsx(i,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",children:d})]}),e.jsx("div",{className:R("text-2xl font-black tabular-nums leading-none",s?"text-primary":"text-slate-900"),children:p}),n&&e.jsx("div",{className:"mt-1.5 text-xs text-slate-500",children:n})]})}function h({icon:i,label:d,value:p}){return e.jsxs("div",{className:"flex items-center gap-3 py-2.5",children:[e.jsx("div",{className:"p-2 rounded-lg bg-slate-100 text-slate-500 shrink-0",children:e.jsx(i,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-400",children:d}),e.jsx("div",{className:"text-sm font-medium text-slate-800 truncate",children:p||"â"})]})]})}function Le(){var k,S;const{userId:i}=O(),d=V(),n=(k=H().state)==null?void 0:k.user,[s,b]=x.useState(n??se(i||"")??null),[r,g]=x.useState(!s),[_,w]=x.useState(null);x.useEffect(()=>{let a=!0;return(async()=>{var l;try{const o=await ae(!n);if(!a)return;const L=(l=o.users)==null?void 0:l.find(D=>String(D.id)===String(i));L?b(L):s||w("This user could not be found.")}catch(o){a&&!s&&w((o==null?void 0:o.message)||"Failed to load this user.")}finally{a&&g(!1)}})(),()=>{a=!1}},[i]);const y=x.useMemo(()=>{if(!s)return[];const a=new Set(s.linked_platforms||[]);return(s.workspaces||[]).forEach(l=>(l.linked_platforms||[]).forEach(o=>a.add(o))),te.filter(l=>a.has(l))},[s]);if(r&&!s)return e.jsxs("div",{className:"space-y-6 animate-in fade-in duration-300",children:[e.jsx("div",{className:"h-8 w-40 bg-slate-100 rounded-lg animate-pulse"}),e.jsx("div",{className:"h-32 bg-slate-100 rounded-2xl animate-pulse"}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:Array.from({length:4}).map((a,l)=>e.jsx("div",{className:"h-24 bg-slate-100 rounded-2xl animate-pulse"},l))})]});if(_||!s)return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(A,{variant:"ghost",onClick:()=>d("/admin/activity"),className:"gap-2 -ml-2 text-slate-600",children:[e.jsx(C,{className:"h-4 w-4"})," Back to Activity"]}),e.jsxs("div",{className:"flex flex-col items-center gap-2 text-slate-400 py-20",children:[e.jsx(q,{className:"h-8 w-8 text-amber-400"}),e.jsx("p",{className:"font-semibold text-slate-600",children:_||"User not found"})]})]});const j=!s.last_login_at,$=t(s.avg_session_seconds)||(t(s.session_count)?Math.round(t(s.total_active_seconds)/t(s.session_count)):0);return e.jsxs(c.div,{variants:M,initial:"hidden",animate:"show",className:"space-y-6 pb-10",children:[e.jsx(c.div,{variants:m,children:e.jsxs(A,{variant:"ghost",onClick:()=>d("/admin/activity"),className:"gap-2 -ml-2 text-slate-600 hover:text-slate-900",children:[e.jsx(C,{className:"h-4 w-4"})," Back to Activity"]})}),e.jsx(c.div,{variants:m,className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-6",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-5",children:[e.jsx(le,{user:s,size:"lg"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-2xl font-black text-slate-900 tracking-tight truncate",children:s.name||"Unnamed user"}),e.jsx("div",{className:"text-slate-500 truncate",children:s.email}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsx(v,{variant:"secondary",className:"text-[10px] font-semibold uppercase",children:s.plan||"â"}),e.jsx(ie,{status:s.status}),s.role&&e.jsx(v,{variant:"outline",className:"text-[10px] capitalize border-slate-200 text-slate-600",children:s.role}),e.jsxs("span",{className:"text-xs text-slate-400",children:["· member for ",ne(s.created_at)]})]})]})]})}),e.jsxs(c.div,{variants:M,className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(f,{icon:P,label:"Time on platform",value:N(s.total_active_seconds),sub:s.last_seen_at?`seen ${u(s.last_seen_at)}`:void 0,accent:t(s.total_active_seconds)>0}),e.jsx(f,{icon:U,label:"Logins",value:t(s.login_count).toLocaleStr
1ing(),sub:j?"never logged in":`last ${u(s.last_login_at)}`}),e.jsx(f,{icon:J,label:"Workspaces",value:t(s.workspace_count).toLocaleString(),sub:`${t(s.linked_workspace_count)} linked`}),e.jsx(f,{icon:B,label:"Campaigns",value:t(s.campaigns_created).toLocaleString(),sub:`${t(s.campaigns_running)} running`,accent:t(s.campaigns_running)>0})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs(c.div,{variants:m,className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-5 lg:col-span-1",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800 mb-2",children:"Profile & account"}),e.jsxs("div",{className:"divide-y divide-slate-100",children:[e.jsx(h,{icon:G,label:"Email",value:s.email}),e.jsx(h,{icon:K,label:"Phone",value:s.phone}),e.jsx(h,{icon:Q,label:"Business",value:s.business_name}),e.jsx(h,{icon:X,label:"Role",value:e.jsx("span",{className:"capitalize",children:s.role||"user"})}),e.jsx(h,{icon:oe,label:"User ID",value:String(s.id)}),e.jsx(h,{icon:de,label:"Signed up",value:`${E(s.created_at)} · ${u(s.created_at)}`})]})]}),e.jsxs(c.div,{variants:m,className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-5 lg:col-span-2",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10 text-primary",children:e.jsx(me,{className:"h-4 w-4"})}),e.jsx("h3",{className:"text-sm font-bold text-slate-800",children:"Engagement"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[{icon:P,l:"Total active time",v:N(s.total_active_seconds)},{icon:xe,l:"Sessions",v:t(s.session_count).toLocaleString()},{icon:Y,l:"Avg session",v:N($)},{icon:pe,l:"Last active",v:s.last_seen_at?u(s.last_seen_at):"â"},{icon:U,l:"Last login",v:j?"never":u(s.last_login_at)},{icon:Z,l:"Running campaigns",v:t(s.campaigns_running).toLocaleString()}].map(a=>e.jsxs("div",{className:"rounded-xl bg-slate-50 border border-slate-100 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400 mb-1.5",children:[e.jsx(a.icon,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide",children:a.l})]}),e.jsx("div",{className:"text-lg font-black text-slate-800 tabular-nums",children:a.v})]},a.l))}),e.jsxs("div",{className:"mt-4 text-xs text-slate-500 leading-relaxed bg-slate-50 rounded-xl px-3 py-2.5",children:["Last login ",j?"never":T(s.last_login_at)," · last active ",s.last_seen_at?T(s.last_seen_at):"â",". Time on platform & sessions are accumulated from live activity heartbeats (idle / closed-tab gaps over 5 min excluded)."]})]})]}),e.jsx(c.div,{variants:m,children:e.jsx(ge,{userId:Number(i)})}),e.jsxs(c.div,{variants:m,className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-5",children:[e.jsx("h3",{className:"text-sm font-bold text-slate-800 mb-3",children:"Connected platforms"}),y.length===0?e.jsx("p",{className:"text-xs text-slate-400 italic",children:"No platforms connected across any workspace."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:y.map(a=>{const l=re[a],o=l.icon;return e.jsxs("div",{className:R("inline-flex items-center gap-2 rounded-xl border px-3 py-2 text-sm font-semibold",l.className),children:[e.jsx(o,{className:"h-4 w-4"})," ",l.label]},a)})})]}),e.jsxs(c.div,{variants:m,children:[e.jsxs("h3",{className:"text-sm font-bold text-slate-800 mb-3",children:["Workspaces ",e.jsxs("span",{className:"text-slate-400 font-medium",children:["(",((S=s.workspaces)==null?void 0:S.length)||0,")"]})]}),!s.workspaces||s.workspaces.length===0?e.jsx("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-6 text-center text-sm text-slate-400 italic",children:"This user has no workspaces."}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-3",children:s.workspaces.map(a=>e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-bold text-slate-900 truncate",children:a.name||`Worksp
1ace ${a.id}`}),a.linked_platforms.length>0?e.jsx(v,{className:"bg-primary/10 text-primary border-primary/20 text-[10px] shrink-0",children:"linked"}):e.jsx(v,{variant:"outline",className:"text-[10px] text-slate-400 shrink-0",children:"unlinked"})]}),e.jsx("div",{className:"mt-3",children:e.jsx(ce,{platforms:a.linked_platforms,empty:"No platforms linked"})}),e.jsxs("div",{className:"mt-3 text-[11px] text-slate-400",children:["Created ",E(a.created_at)]})]},a.id))})]})]})}export{Le 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.