1import{r as m,j as e,s as l,C as T,y as B,z as I,I as V,an as K,ao as O,B as y,G as z,ap as W,a as E,b as F,u as J,K as q,g as G,a2 as X,ae as R,S as P,Y,a4 as $,M as Q,P as Z,J as ee}from"./index-DO0ZNUzu.js";import{u as te}from"./use-mobile-CrCAEjpp.js";import{L as se}from"./loader-circle-CZ_geqae.js";import{t as U,c as ae}from"./en-US-CXXYYhpC.js";import{C as ie}from"./calendar-Dodd1r6N.js";import{R as re,L as ne,C as oe,X as ce,Y as le,T as de,b as me,a as A}from"./LineChart-B2vz4ggM.js";import{f as v}from"./format-Cn6ElKJ8.js";import{A as ue}from"./AdminNavigation-BALrVg_C.js";import{M as H}from"./message-circle-Dp8Kc7iX.js";import{H as xe}from"./house-CUUNLlcb.js";import"./bell-Dc_RYjMz.js";import"./chart-column-RBik8eZM.js";import"./settings-cLgs3mni.js";function fe(t,r){const o=U(t);return isNaN(r)?ae(t,NaN):(r&&o.setDate(o.getDate()+r),o)}function he(t,r){const o=U(t.start),c=U(t.end);let n=+o>+c;const g=n?+o:+c,u=n?c:o;u.setHours(0,0,0,0);let j=1;const f=[];for(;+u<=g;)f.push(U(u)),u.setDate(u.getDate()+j),u.setHours(0,0,0,0);return n?f.reverse():f}function L(t,r){return fe(t,-r)}const pe=({onRefresh:t,threshold:r=80,resistance:o=2.5})=>{const[c,n]=m.useState(!1),[g,u]=m.useState(0),j=m.useRef(0),f=m.useRef(null);return m.useEffect(()=>{const x=f.current;if(!x)return;let _=0,b=0;const w=d=>{x.scrollTop===0&&(_=d.touches[0].clientY,j.current=_)},M=d=>{if(x.scrollTop===0&&!c){b=d.touches[0].clientY;const h=b-_;if(h>0){const N=Math.min(h/o,r*1.5);u(N),N>5&&d.preventDefault()}}},s=async()=>{if(g>=r&&!c){n(!0);try{await t()}finally{n(!1)}}u(0)};return x.addEventListener("touchstart",w,{passive:!0}),x.addEventListener("touchmove",M,{passive:!1}),x.addEventListener("touchend",s,{passive:!0}),()=>{x.removeEventListener("touchstart",w),x.removeEventListener("touchmove",M),x.removeEventListener("touchend",s)}},[g,r,o,t,c]),{containerRef:f,isRefreshing:c,pullDistance:g}},ge=({onRefresh:t,children:r})=>{const{containerRef:o,isRefreshing:c,pullDistance:n}=pe({onRefresh:t,threshold:80});return e.jsxs("div",{ref:o,className:"relative h-full overflow-auto",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 flex items-center justify-center transition-all duration-200",style:{transform:`translateY(${Math.min(n,60)}px)`,opacity:n/80},children:e.jsx("div",{className:"rounded-full bg-background p-2 shadow-lg",children:e.jsx(se,{className:`h-5 w-5 text-primary ${c?"animate-spin":""}`,style:{transform:`rotate(${n*3}deg)`}})})}),e.jsx("div",{style:{transform:`translateY(${c?"60px":"0px"})`,transition:c?"transform 0.2s ease":"none"},children:r})]})},je=()=>{const[t,r]=m.useState({from:L(new Date,30),to:new Date}),[o,c]=m.useState([]),[n,g]=m.useState(!0);m.useEffect(()=>{u()},[t]);const u=async()=>{g(!0);try{const j=he({start:t.from,end:t.to}),[f,x,_,b]=await Promise.all([l.from("affirmation_usage").select("usage_date, count").gte("usage_date",v(t.from,"yyyy-MM-dd")).lte("usage_date",v(t.to,"yyyy-MM-dd")),l.from("voice_notes_usage").select("usage_date, count").gte("usage_date",v(t.from,"yyyy-MM-dd")).lte("usage_date",v(t.to,"yyyy-MM-dd")),l.from("vision_boards").select("created_at").gte("created_at",t.from.toISOString()).lte("created_at",t.to.toISOString()),l.from("circle_messages").select("created_at").gte("created_at",t.from.toISOString()).lte("created_at",t.to.toISOString())]),w=j.map(M=>{var C,D,S,i;const s=v(M,"yyyy-MM-dd"),d=((C=f.data)==null?void 0:C.filter(a=>a.usage_date===s).reduce((a,k)=>a+k.count,0))||0,h=((D=x.data)==null?void 0:D.filter(a=>a.usage_date===s).reduce((a,k)=>a+k.count,0))||0,N=((S=_.data)==null?void 0:S.filter(a=>v(new Date(a.created_at),"yyyy-MM-dd")===s).length)||0,p=((i=b.data)==null?void 0:i.filter(a=>v(new Date(a.created_at),"yyyy-MM-dd")===s).length)||0;return{date:v(M,"MMM dd"),affirmations:d,voiceNotes:h,visionBoards:N,circleMessages:p}});c(w)}catch(j){console.error("Error fetching trend data:",j)}finally{g(!1)}};return e.jsxs(T,{children:[e.jsx(B,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(I,{children:"Feature Usage Trends"}),e.jsx(V,{children:"Daily activity across platform features"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(K,{children:[e.jsx(O,{asChild:!0,children:e.jsxs(y,{variant:"outline",className:z("justify-start text-left font-normal"),children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),v(t.from,"MMM dd, yyyy")," - ",v(t.to,"MMM dd, yyyy")]})}),e.jsx(W,{className:"w-auto p-0",align:"end",children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r({from:L(new Date,7),to:new Date}),children:"Last 7 days"}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r({from:L(new Date,30),to:new Date}),children:"Last 30 days"}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r({from:L(new Date,90),to:new Date}),children:"Last 90 days"})]})})]})})]})}),e.jsx(E,{children:n?e.jsx("div",{className:"h-[400px] flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading chart data..."})}):e.jsx(re,{width:"100%",height:400,children:e.jsxs(ne,{data:o,children:[e.jsx(oe,{strokeDasharray:"3 3"}),e.jsx(ce,{dataKey:"date"}),e.jsx(le,{}),e.jsx(de,{}),e.jsx(me,{}),e.jsx(A,{type:"monotone",dataKey:"affirmations",stroke:"hsl(var(--chart-1))",name:"Affirmations",strokeWidth:2}),e.jsx(A,{type:"monotone",dataKey:"voiceNotes",stroke:"hsl(var(--chart-2))",name:"Voice Notes",strokeWidth:2}),e.jsx(A,{type:"monotone",dataKey:"visionBoards",stroke:"hsl(var(--chart-3))",name:"Vision Boards",strokeWidth:2}),e.jsx(A,{type:"monotone",dataKey:"circleMessages",stroke:"hsl(var(--chart-4))",name:"Circle Messages",strokeWidth:2})]})})})]})},Le=()=>{const t=F();J();const{isAdmin:r,loading:o}=q();te();const{toast:c}=G(),[n,g]=m.useState({totalUsers:0,activeSubscribers:0,totalAffirmations:0,totalVoiceNotes:0,totalVisionBoards:0,totalVisionBoardItems:0,totalCircleMembers:0,totalCircleMessages:0}),[u,j]=m.useState(!0),[f,x]=m.useState([]);m.useEffect(()=>
1{!o&&!r&&(t("/admin/dashboard"),c({title:"Access Denied",description:"You must be an admin to access this page",variant:"destructive"}))},[r,o,t]),m.useEffect(()=>{r&&(b(),w())},[r]);const _=async()=>{await Promise.all([b(),w()]),c({title:"Refreshed",description:"Dashboard data updated"})},b=async()=>{var s;j(!0);try{const[d,h,N,p,C,D,S]=await Promise.all([l.from("profiles").select("subscription_status",{count:"exact"}),l.from("affirmation_usage").select("*",{count:"exact",head:!0}),l.from("voice_notes_usage").select("*",{count:"exact",head:!0}),l.from("vision_boards").select("*",{count:"exact",head:!0}),l.from("vision_board_items").select("*",{count:"exact",head:!0}),l.from("circle_members").select("*",{count:"exact",head:!0}),l.from("circle_messages").select("*",{count:"exact",head:!0})]),i=((s=d.data)==null?void 0:s.filter(a=>a.subscription_status==="active").length)||0;g({totalUsers:d.count||0,activeSubscribers:i,totalAffirmations:h.count||0,totalVoiceNotes:N.count||0,totalVisionBoards:p.count||0,totalVisionBoardItems:C.count||0,totalCircleMembers:D.count||0,totalCircleMessages:S.count||0})}catch(d){console.error("Error fetching stats:",d),c({title:"Error",description:"Failed to load statistics",variant:"destructive"})}finally{j(!1)}},w=async()=>{var s,d,h,N;try{const p=[],{data:C}=await l.from("profiles").select("id, user_id, display_name, created_at").order("created_at",{ascending:!1}).limit(20);if(C)for(const i of C){const{data:a}=await l.auth.admin.getUserById(i.user_id);p.push({id:i.id,type:"signup",user_email:((s=a==null?void 0:a.user)==null?void 0:s.email)||"Unknown",user_name:i.display_name||void 0,timestamp:i.created_at})}const{data:D}=await l.from("profiles").select("id, user_id, display_name, subscription_tier, updated_at").eq("subscription_status","active").not("subscription_tier","is",null).order("updated_at",{ascending:!1}).limit(20);if(D)for(const i of D){const{data:a}=await l.auth.admin.getUserById(i.user_id);p.push({id:i.id+"-sub",type:"membership",user_email:((d=a==null?void 0:a.user)==null?void 0:d.email)||"Unknown",user_name:i.display_name||void 0,details:i.subscription_tier||"Premium",timestamp:i.updated_at})}const{data:S}=await l.from("circle_members").select("id, user_id, joined_at, circle_id, circles(name)").order("joined_at",{ascending:!1}).limit(20);if(S)for(const i of S){const{data:a}=await l.from("profiles").select("user_id, display_name").eq("user_id",i.user_id).single(),{data:k}=await l.auth.admin.getUserById(i.user_id);p.push({id:i.id,type:"circle",user_email:((h=k==null?void 0:k.user)==null?void 0:h.email)||"Unknown",user_name:(a==null?void 0:a.display_name)||void 0,details:((N=i.circles)==null?void 0:N.name)||"Unknown Circle",timestamp:i.joined_at||new Date().toISOString()})}p.sort((i,a)=>new Date(a.timestamp).getTime()-new Date(i.timestamp).getTime()),x(p.slice(0,30))}catch(p){console.error("Error fetching recent activity:",p)}};if(o||u)return e.jsx(X,{});if(!r)return null;const M=[{title:"Total Users",value:n.totalUsers,icon:R,description:`${n.activeSubscribers} active subscribers`,color:"text-blue-600"},{title:"Affirmations Used",value:n.totalAffirmations,icon:P,description:"Total affirmation sessions",color:"text-yellow-600"},{title:"Voice Notes Created",value:n.totalVoiceNotes,icon:Y,description:"Total voice recordings",color:"text-purple-600"},{title:"Vision Boards",value:n.totalVisionBoards,icon:$,description:`${n.totalVisionBoardItems} total items`,color:"text-pink-600"},{title:"Circle Members",value:n.totalCircleMembers,icon:R,description:"Users in circles",color:"text-green-600"},{title:"Circle Messages",value:n.totalCircleMessages,icon:H,description:"Total messages sent",color:"text-indigo-600"}];return e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background to-muted/20",children:e.jsx("div",{className:"container mx-auto px-4 py-6 md:py-8",children:e.jsxs("div",{className:"flex flex-col gap-4 md:gap-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold text-foreground",children:"Admin Dashboard"}),e.jsx("p",{className:"text-sm md:text-base text-muted-foreground mt-1",children:"Manage your HERPower platform"})]}),e.jsx(Q,{})]}),e.jsx(ue,{}),e.jsx(ge,{onRefresh:_,children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 md:gap-6",children:M.map((s,d)=>{const h=s.icon;return e.jsxs(T,{className:"hover:shadow-lg transition-all duration-300 active:scale-95 touch-manipulation",children:[e.jsxs(B,{className:"flex flex-row items-center justify-between pb-2 space-y-0",children:[e.jsx(I,{className:"text-sm font-medium text-muted-foreground",children:s.title}),e.jsx(h,{className:`h-5 w-5 ${s.color}`})]}),e.jsxs(E,{children:[e.jsx("div",{className:"text-2xl font-bold",children:s.value.toLocaleStr
1ing()}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.description})]})]},d)})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 md:gap-6",children:[e.jsx("div",{className:"lg:col-span-2",children:e.jsx(je,{})}),e.jsxs(T,{className:"touch-manipulation",children:[e.jsxs(B,{children:[e.jsx(I,{className:"text-lg md:text-xl",children:"Recent Activity"}),e.jsx(V,{className:"text-sm",children:"Latest platform events"})]}),e.jsx(E,{children:e.jsx("div",{className:"space-y-3 md:space-y-4 max-h-[400px] md:max-h-[600px] overflow-y-auto",children:f.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No recent activity"}):f.map(s=>e.jsxs("div",{className:"flex items-start gap-3 pb-3 border-b last:border-0 last:pb-0",children:[e.jsxs("div",{className:"mt-1",children:[s.type==="signup"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-green-100 flex items-center justify-center",children:e.jsx(R,{className:"h-4 w-4 text-green-600"})}),s.type==="membership"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-purple-100 flex items-center justify-center",children:e.jsx(Z,{className:"h-4 w-4 text-purple-600"})}),s.type==="circle"&&e.jsx("div",{className:"h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center",children:e.jsx(H,{className:"h-4 w-4 text-blue-600"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.user_name||s.user_email}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.type==="signup"&&"New user signup",s.type==="membership"&&`Subscribed to ${s.details}`,s.type==="circle"&&`Joined ${s.details}`]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[new Date(s.timestamp).toLocaleDateString()," at"," ",new Date(s.timestamp).toLocaleTimeString()]})]})]},s.id))})})]})]}),e.jsxs(T,{className:"touch-manipulation",children:[e.jsxs(B,{children:[e.jsx(I,{className:"text-lg md:text-xl",children:"Quick Actions"}),e.jsx(V,{className:"text-sm",children:"Common management tasks"})]}),e.jsx(E,{children:e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3 md:gap-4",children:[e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin"),children:[e.jsx(xe,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Home"})]}),e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin/affirmations"),children:[e.jsx(P,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Affirmations"})]}),e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin/media"),children:[e.jsx($,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Media"})]}),e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin/voice-notes"),children:[e.jsx(Y,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Voice Notes"})]}),e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin/analytics"),children:[e.jsx(ee,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Analytics"})]}),e.jsxs(y,{variant:"outline",className:"h-auto py-4 px-3 flex-col gap-2 touch-manipulation active:scale-95 transition-transform",onClick:()=>t("/admin/moderation"),children:[e.jsx(R,{className:"h-5 w-5"}),e.jsx("span",{className:"text-xs",children:"Moderation"})]})]})})]})]})})]})})})};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.