1import{j as e}from"./react-vendor-DUhHROXo.js";import{P}from"./PortalLayout-BUxGSFei.js";import{C as u,a as p,b as g,c as v,d as M}from"./card-9IoFUltb.js";import{B as U}from"./badge-BsE4KYIf.js";import{m as H,J as R,aM as I}from"./index-BLtzf0SR.js";import{s as C}from"./client-DTel1CZI.js";import{t as N}from"./getTimezoneOffsetInMilliseconds-DsfBWtEI.js";import{D as B}from"./dollar-sign-D3lTBfQm.js";import{U as E}from"./users-CIwSfVhi.js";import{T as K}from"./trending-down-kRHyCAJr.js";import{A as V}from"./arrow-up-right-N1rr5vHt.js";import{s as z}from"./subMonths-BX5J2nWI.js";import{s as J}from"./startOfMonth-CCTdL9mE.js";import{e as Q}from"./endOfMonth-D3_uxaJK.js";import{f as G}from"./format-DGzj7MEM.js";import{s as W}from"./subDays-Cc0kVtWU.js";import"./AdminLayout-4AAuHeAU.js";import"./router-vendor-Dz9PdDzH.js";import"./NavLink-CsyG-eHO.js";import"./scroll-area-BdyOmc9o.js";import"./index-BdQq_4o_.js";import"./collapsible-BAD8kbtc.js";import"./index-CMI-ZfmW.js";import"./arrow-left-CRb8P6iH.js";import"./globe-CQ83QW2m.js";import"./activity-CwFToTs3.js";import"./list-todo-BR3jv1RJ.js";import"./calendar-BDETTnfZ.js";import"./users-round-CCw5yxW7.js";import"./radio-BQgeDg5T.js";import"./clapperboard-BvstouST.js";import"./clipboard-list-CQJ-vJ2y.js";import"./image-arBWrt3y.js";import"./folder-open-CIWhCFhy.js";import"./pencil-C2cyk8cg.js";import"./message-square-BDdDilNB.js";import"./ticket-l9bl0kcm.js";import"./megaphone-DpQsxotQ.js";import"./package-DKB1lvtO.js";import"./circle-user-BeB3uaA1.js";import"./folder-kanban-B8jlMC6s.js";import"./settings-Baim_Eei.js";import"./briefcase-CdSp4ViD.js";import"./chart-line-ohAz7u_s.js";import"./HostOwnerLayout-PM2-LrXf.js";import"./layers-CvbkNa7J.js";import"./en-US-Bfz1jvxT.js";import"./differenceInCalendarDays-D4nmWE3G.js";import"./addDays-BhORGywK.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const X=H("ArrowDownRight",[["path",{d:"m7 7 10 10",key:"1fmybs"}],["path",{d:"M17 7v10H7",key:"6fjiku"}]]);function Y(a,l){const r=N(a.start),i=N(a.end);let c=+r>+i;const x=c?+r:+i,n=c?i:r;n.setHours(0,0,0,0),n.setDate(1);let d=1;const o=[];for(;+n<=x;)o.push(N(n)),n.setMonth(n.getMonth()+d);return c?o.reverse():o}function Ge(){const{data:a=[]}=R({queryKey:["sales-transactions"],queryFn:async()=>{const{data:t,error:s}=await C.from("sales_transactions").select("*").order("created_at",{ascending:!1});if(s)throw s;return t}}),{data:l=[]}=R({queryKey:["profiles-tiers"],queryFn:async()=>{const{data:t,error:s}=await C.from("profiles").select("membership_tier, is_active, created_at");if(s)throw s;return t}}),r=a.filter(t=>t.transaction_type==="subscription"),i=a.filter(t=>t.transaction_type==="churn"),c=a.filter(t=>t.transaction_type==="refund"),x=r.reduce((t,s)=>t+Number(s.amount),0),n=c.reduce((t,s)=>t+Math.abs(Number(s.amount)),0),d=x-n,o=l.filter(t=>t.membership_tier!=="free"&&t.is_active).length,h=l.length,f=i.length,S=o>0?(f/(o+f)*100).toFixed(1):"0",y=new Set(r.map(t=>t.user_id)).size,A=y>0?(d/y).toFixed(2):"0.00",j={};l.forEach(t=>{j[t.membership_tier]=(j[t.membership_tier]||0)+1});const $=z(new Date,6),L=Y({start:$,end:new Date}).map(t=>{const s=J(t),F=Q(t),_=r.filter(b=>{const m=new Date(b.created_at);return m>=s&&m<=F}),O=_.reduce((b,m)=>b+Number(m.amount),0);return{month:G(t,"MMM yyyy"),revenue:O,count:_.length}}),w=W(new Date,30),D=r.filter(t=>new Date(t.created_at)>=w),T=i.filter(t=>new Date(t.created_at)>=w),k=D.reduce((t,s)=>t+Number(s.amount),0),q=[{label:"Net Revenue",value:`$${d.toLocaleString()}`,icon:B,color:"text-green-500",desc:"All time"},{label:"Active Subscribers",value:o.toString(),icon:E,color:"text-primary",desc:`of ${h} total`},{label:"Avg LTV",value:`$${A}`,icon:I,color:"text-blue-500",desc:"Per paying user"},{label:"Churn Rate",value:`${S}%`,icon:K,color:"text-destructive",desc:`${f} churns`}];return e.jsx(P,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold",children:"Subscriber Analytics"}),e.jsx("p",{className:"text-muted-foreground",children:"LTV, churn, and revenue tracking"})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:q.map(t=>{const s=t.icon;return e.jsx(u,{children:e.jsxs(p,{className:"pt-5 pb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(s,{className:`h-4 w-4 ${t.color}`}),e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:t.label})]}),e.jsx("p",{className:"text-2xl font-bold",children:t.value}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.desc})]})},t.label)})}),e.jsxs(u,{children:[e.jsx(g,{children:e.jsx(v,{children:"Last 30 Days"})}),e.jsx(p,{children:e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsxs("div",{className:"text-center p-4 rounded-lg border",children:[e.jsxs("p",{className:"text-2xl font-bold text-green-500",children:["$",k.toLocaleStr
6ing()]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Revenue"})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg border",children:[e.jsxs("p",{className:"text-2xl font-bold flex items-center justify-center gap-1",children:[e.jsx(V,{className:"h-5 w-5 text-green-500"})," ",D.length]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"New Subscriptions"})]}),e.jsxs("div",{className:"text-center p-4 rounded-lg border",children:[e.jsxs("p",{className:"text-2xl font-bold flex items-center justify-center gap-1",children:[e.jsx(X,{className:"h-5 w-5 text-destructive"})," ",T.length]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Churns"})]})]})})]}),e.jsxs(u,{children:[e.jsxs(g,{children:[e.jsx(v,{children:"Tier Distribution"}),e.jsx(M,{children:"Current membership breakdown"})]}),e.jsx(p,{children:e.jsx("div",{className:"grid grid-cols-3 gap-4",children:Object.entries(j).sort().map(([t,s])=>e.jsxs("div",{className:"p-4 rounded-lg border text-center",children:[e.jsx(U,{variant:t==="free"?"outline":"default",className:"mb-2",children:t.replace("_"," ")}),e.jsx("p",{className:"text-2xl font-bold",children:s}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h>0?(s/h*100).toFixed(0):0,"%"]})]},t))})})]}),e.jsxs(u,{children:[e.jsxs(g,{children:[e.jsx(v,{children:"Monthly Revenue"}),e.jsx(M,{children:"Last 6 months"})]}),e.jsx(p,{children:e.jsx("div",{className:"space-y-2",children:L.reverse().map(t=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border",children:[e.jsx("span",{className:"font-medium text-sm",children:t.month}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t.count," txns"]}),e.jsxs("span",{className:"font-bold",children:["$",t.revenue.toLocaleString()]})]})]},t.month))})})]})]})})}export{Ge 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.