1import{r as o,b as w,t as P,j as e,L as R,R as J,Z as v}from"./index-DuFHDgjL.js";import{B as Q}from"./button-yDjC60w6.js";import{S as ee,a as te,b as se,c as ae,d as re}from"./select-CTaXbays.js";import{C as x,a as m,b as h,c as p,d as f}from"./card-D1jcw98M.js";import{T}from"./progress-CS80WwC5.js";import{U as B}from"./users-C2aoE3DH.js";import{D as S}from"./droplet-v2hhTJVU.js";import{R as _,X as le,Y as ne,T as G,B as oe,C as ce}from"./generateCategoricalChart-DWDIDkZ0.js";import{B as ie}from"./BarChart-BY9rrHe6.js";import{C as de}from"./CartesianGrid-BWUh3etj.js";import{P as xe,a as me}from"./PieChart-vz_ybygT.js";import{C as he}from"./circle-check-big-ye-FYAvc.js";import{T as pe}from"./triangle-alert-BjdqLddS.js";import"./index-DFErrfuN.js";import"./index-BKzA9_yg.js";import"./index-BdQq_4o_.js";import"./index-Byqjatey.js";import"./index-DopWwC6Z.js";import"./Combination-CvBmiCYy.js";import"./index-DxLiK4pb.js";import"./index-oxxjwFLh.js";import"./index-DNEy9Puf.js";import"./index-KNO01SsF.js";import"./index-BDQDCtFg.js";import"./chevron-down-Bdq-JZJg.js";import"./chevron-up-KePEYZmq.js";import"./tiny-invariant-BaFNuDhB.js";import"./index-B3XiQiTJ.js";import"./index-Dh4i1-J3.js";const U=[{fn:"scanBusinessCard",label:"Scan Business Card",feature:"AI OCR / LLM",cost:1,category:"Scanner"},{fn:"scanAnything",label:"Scan Anything",feature:"AI OCR / LLM",cost:1,category:"Scanner"},{fn:"processMultiCardPhoto",label:"Multi-Card Photo Scan",feature:"AI OCR / LLM",cost:1,category:"Scanner"},{fn:"generateAIProfile",label:"AI Profile Generation",feature:"InvokeLLM",cost:1,category:"AI Enrichment"},{fn:"fetchLinkedInProfile",label:"Fetch LinkedIn Profile",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchLinkedInPhoto",label:"Fetch LinkedIn Photo",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchFacebookPage",label:"Fetch Facebook Page",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchCompanyWebsite",label:"Fetch Company Website",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchBusinessAddress",label:"Fetch Business Address",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchPhoneNumbers",label:"Fetch Phone Numbers",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"fetchEmail",label:"Fetch Email",feature:"InvokeLLM + Web",cost:1,category:"AI Enrichment"},{fn:"deductSparks (PowerFill)",label:"PowerFill (per field batch)",feature:"InvokeLLM per field",cost:"1 per field",category:"AI Enrichment"},{fn:"syncGoogleContact",label:"Sync to Google Contacts",feature:"OAuth API",cost:0,category:"Integrations"},{fn:"syncMicrosoftContact",label:"Sync to Microsoft Contacts",feature:"OAuth API",cost:0,category:"Integrations"},{fn:"exportContacts",label:"Export Contacts (CSV/VCF)",feature:"Server Processing",cost:0,category:"Export"},{fn:"parseVCFFile",label:"Import VCF File",feature:"Server Processing",cost:0,category:"Import"},{fn:"generateGiftCard",label:"Generate Gift Card",feature:"Server Logic",cost:0,category:"Payments"},{fn:"createCheckoutSession",label:"Create Stripe Checkout",feature:"Stripe API",cost:0,category:"Payments"},{fn:"sendNewMemberNotification",label:"New Member Email Notification",feature:"SendGrid",cost:0,category:"Email"},{fn:"sendWelcomeEmail",label:"Welcome Email",feature:"SendGrid",cost:0,category:"Email"},{fn:"sendAdminReply",label:"Admin Reply Email",feature:"SendGrid",cost:0,category:"Email"},{fn:"reverseGeocode",label:"Reverse Geocode Location",feature:"Google Maps API",cost:0,category:"Maps"},{fn:"autoCropCard",label:"Auto-Crop Business Card",feature:"InvokeLLM (Vision)",cost:1,category:"Scanner"},{fn:"createAppBackup",label:"Create App Backup",feature:"Dropbox API",cost:0,category:"System"}],O={Scanner:{bg:"bg-cyan-500/10",text:"text-cyan-300",border:"border-cyan-500/30"},"AI Enrichment":{bg:"bg-purple-500/10",text:"text-purple-300",border:"border-purple-500/30"},Integrations:{bg:"bg-blue-500/10",text:"text-blue-300",border:"border-blue-500/30"},Email:{bg:"bg-green-500/10",text:"text-green-300",border:"border-green-500/30"},Payments:{bg:"bg-amber-500/10",text:"text-amber-300",border:"border-amber-500/30"},Export:{bg:"bg-teal-500/10",text:"text-teal-300",border:"border-teal-500/30"},Import:{bg:"bg-indigo-500/10",text:"text-indigo-300",border:"border-indigo-500/30"},Maps:{bg:"bg-red-500/10",text:"text-red-300",border:"border-red-500/30"},System:{bg:"bg-slate-500/10",text:"text-slate-300",border:"border-slate-500/30"}},y=["#0ea5e9","#8b5cf6","#ec4899","#f59e0b","#10b981","#06b6d4","#3b82f6","#6366f1"];function Ve(){const[d,W]=o.useState([]),[k,$]=o.useState([]),[b,V]=o.useState(null),[z,L]=o.useState(!0),[u,Y]=o.useState("7d"),[I,M]=o.use
1State(!1),[N,K]=o.useState("All"),A={"1d":{label:"Last 24h",days:1},"7d":{label:"Last 7 Days",days:7},"30d":{label:"Last 30 Days",days:30},"90d":{label:"Last 90 Days",days:90}};o.useEffect(()=>{E()},[]);const E=async()=>{var t,s,a;L(!0);try{const[r,l,n]=await Promise.all([w.entities.User.list(),w.entities.SparkTransaction.list("-created_date",500),w.functions.invoke("getCreditUsage",{}).catch(c=>(console.warn("Failed to fetch real credit usage:",c),null))]);W(r||[]),$(l||[]),(t=n==null?void 0:n.data)!=null&&t.success?V((s=n.data)==null?void 0:s.data):(a=n==null?void 0:n.data)!=null&&a.error&&console.error("Credit usage error:",n.data.error)}catch{P.error("Failed to load data")}finally{L(!1)}},H=async()=>{M(!0),await E(),M(!1),P.success("Data refreshed!")},g=A[u].days,i=o.useMemo(()=>{const t=new Date;return t.setDate(t.getDate()-g),k.filter(s=>new Date(s.created_date)>=t)},[k,u]),X=o.useMemo(()=>{const t={};for(let s=g-1;s>=0;s--){const a=new Date;a.setDate(a.getDate()-s);const r=a.toLocaleDateString("en-US",{month:"short",day:"numeric"});t[r]=0}return i.forEach(s=>{var r;const a=new Date(s.created_date).toLocaleDateString("en-US",{month:"short",day:"numeric"});t[a]!==void 0&&(t[a]+=Math.abs(((r=s.data)==null?void 0:r.amount)||0))}),Object.entries(t).map(([s,a])=>({date:s,drops:a}))},[i,u]),C=o.useMemo(()=>{const t={};return i.forEach(s=>{var r,l;const a=(((r=s.data)==null?void 0:r.reason)||"Other").replace("Spark: ","").replace("Power Fill: ","PowerFill: ");t[a]=(t[a]||0)+Math.abs(((l=s.data)==null?void 0:l.amount)||0)}),Object.entries(t).map(([s,a])=>({name:s,value:a})).sort((s,a)=>a.value-s.value).slice(0,8)},[i]),D=o.useMemo(()=>{const t={};return i.forEach(s=>{var r,l;const a=(r=s.data)==null?void 0:r.user_email;a&&(t[a]=(t[a]||0)+Math.abs(((l=s.data)==null?void 0:l.amount)||0))}),Object.entries(t).map(([s,a])=>{var l,n;const r=d.find(c=>c.email===s);return{email:s,name:(r==null?void 0:r.full_name)||s,consumed:a,balance:((l=r==null?void 0:r.data)==null?void 0:l.spark_balance)||0,plan:((n=r==null?void 0:r.data)==null?void 0:n.subscription_plan)||"â"}}).sort((s,a)=>a.consumed-s.consumed).slice(0,10)},[i,d]),j=o.useMemo(()=>{const t=d.length,s=d.reduce((l,n)=>{var c;return l+(((c=n.data)==null?void 0:c.spark_balance)||0)},0),a=Math.floor(i.reduce((l,n)=>{var c;return l+Math.abs(((c=n.data)==null?void 0:c.amount)||0)},0)),r=t>0?(s/t).toFixed(1):0;return{totalUsers:t,totalBalance:s,totalConsumed:a,avgBalance:r}},[d,i]),F=o.useMemo(()=>{const t=new Date;return d.filter(s=>{var a;return(a=s.data)==null?void 0:a.subscription_expires}).map(s=>{var c;const r=new Date(s.data.subscription_expires)-t,l=Math.floor(r/864e5),n=Math.floor(r%864e5/36e5);return{email:s.email,name:s.full_name,days:l,hours:n,plan:(c=s.data)==null?void 0:c.subscription_plan}}).filter(s=>s.days>=0&&s.days<=30).sort((s,a)=>s.days-a.days||s.hours-a.hours)},[d]);o.useMemo(()=>{if(!(b!=null&&b.renewal_date))return null;const t=new Date,a=new Date(b.renewal_date)-t,r=Math.max(0,Math.floor(a/864e5)),l=Math.max(0,Math.floor(a%864e5/36e5));return{days:r,hours:l,isExpired:a<0}},[b]);const Z=U.filter(t=>N==="All"||t.category===N),q=["All",...new Set(U.map(t=>t.category))];return z?e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsxs("div",{className:"text-center",children:[e.jsx(R,{className:"w-12 h-12 animate-spin text-cyan-400 mx-auto mb-4"}),e.jsx("p",{className:"text-slate-300 font-semibold",children:"Loading GoFuel metrics..."})]})}):e.jsxs("div",{className:"space-y-6 pb-10",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-slate-300 font-semibold text-sm",children:"Time Range:"}),e.jsxs(ee,{value:u,onValueChange:Y,children:[e.jsx(te,{className:"w-40 bg-slate-800 border-slate-700 text-white",children:e.jsx(se,{})}),e.jsx(ae,{className:"bg-slate-800 border-slate-700",children:Object.entries(A).map(([t,{label:s}])=>e.jsx(re,{value:t,className:"text-white",children:s},t))})]})]}),e.jsxs(Q,{onClick:H,disabled:I,className:"bg-gradient-to-r from-cyan-500 to-blue-600 text-white font-bold",children:[I?e.jsx(R,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(J,{className:"w-4 h-4 mr-2"}),"Refresh Data"]})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[{label:"Total Users",value:j.totalUsers.toLocaleStr
1ing(),sub:"Registered accounts",icon:B,color:"text-cyan-400",bg:"from-cyan-900/40 to-slate-900"},{label:"Total GoFuel Balance",value:j.totalBalance.toLocaleString(),sub:"Drops across all users",icon:S,color:"text-blue-400",bg:"from-blue-900/40 to-slate-900"},{label:"Drops Consumed",value:j.totalConsumed.toLocaleString(),sub:`Last ${g} day${g>1?"s":""}`,icon:T,color:"text-purple-400",bg:"from-purple-900/40 to-slate-900"},{label:"Avg Balance / User",value:j.avgBalance,sub:"Current drops",icon:v,color:"text-amber-400",bg:"from-amber-900/40 to-slate-900"}].map(({label:t,value:s,sub:a,icon:r,color:l,bg:n})=>e.jsxs(x,{className:`bg-gradient-to-br ${n} border-slate-700`,children:[e.jsx(m,{className:"pb-2 pt-4 px-4",children:e.jsxs(h,{className:"text-xs font-semibold text-slate-300 flex items-center gap-1.5",children:[e.jsx(r,{className:`w-4 h-4 ${l}`})," ",t]})}),e.jsxs(p,{className:"px-4 pb-4",children:[e.jsx("div",{className:`text-3xl font-black ${l}`,children:s}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:a})]})]},t))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(x,{className:"bg-slate-800/60 border-slate-700",children:[e.jsxs(m,{children:[e.jsxs(h,{className:"text-white flex items-center gap-2",children:[e.jsx(T,{className:"w-5 h-5 text-cyan-400"})," Daily Drop Consumption"]}),e.jsx(f,{children:"Total drops consumed per day"})]}),e.jsx(p,{children:e.jsx(_,{width:"100%",height:280,children:e.jsxs(ie,{data:X,children:[e.jsx(de,{strokeDasharray:"3 3",stroke:"#334155"}),e.jsx(le,{dataKey:"date",stroke:"#94a3b8",tick:{fontSize:11}}),e.jsx(ne,{stroke:"#94a3b8",tick:{fontSize:11}}),e.jsx(G,{contentStyle:{backgroundColor:"#1e293b",border:"1px solid #475569",borderRadius:"8px"}}),e.jsx(oe,{dataKey:"drops",fill:"#0ea5e9",radius:[4,4,0,0]})]})})})]}),e.jsxs(x,{className:"bg-slate-800/60 border-slate-700",children:[e.jsxs(m,{children:[e.jsxs(h,{className:"text-white flex items-center gap-2",children:[e.jsx(v,{className:"w-5 h-5 text-purple-400"})," Breakdown by Feature"]}),e.jsx(f,{children:"Which features consume the most drops"})]}),e.jsxs(p,{children:[e.jsx(_,{width:"100%",height:280,children:e.jsxs(xe,{children:[e.jsx(me,{data:C,cx:"50%",cy:"50%",outerRadius:90,dataKey:"value",labelLine:!1,children:C.map((t,s)=>e.jsx(ce,{fill:y[s%y.length]},s))}),e.jsx(G,{contentStyle:{backgroundColor:"#1e293b",border:"1px solid #475569",borderRadius:"8px"},formatter:(t,s)=>[`${t} drops`,s]})]})}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-3 justify-center",children:C.map((t,s)=>e.jsxs("span",{className:"flex items-center gap-1 text-xs text-slate-300",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{backgroundColor:y[s%y.length]}}),t.name," (",t.value,")"]},s))})]})]})]}),e.jsxs(x,{className:"bg-slate-800/60 border-slate-700",children:[e.jsxs(m,{children:[e.jsxs(h,{className:"text-white flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5 text-blue-400"})," Top Drop Consumers"]}
1),e.jsx(f,{children:"Users consuming the most GoFuel drops in this period"})]}),e.jsx(p,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-700",children:[e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"#"}),e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"User"}),e.jsx("th",{className:"text-right py-3 px-4 text-slate-400 font-semibold",children:"Drops Used"}),e.jsx("th",{className:"text-right py-3 px-4 text-slate-400 font-semibold",children:"Balance"}),e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"Plan"})]})}),e.jsxs("tbody",{children:[D.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-8 text-slate-500",children:"No consumption data in this period"})}),D.map((t,s)=>e.jsxs("tr",{className:"border-b border-slate-700/50 hover:bg-slate-700/20 transition",children:[e.jsx("td",{className:"py-3 px-4 text-slate-500 font-bold",children:s+1}),e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("div",{className:"font-semibold text-white",children:t.name}),e.jsx("div",{className:"text-xs text-slate-400",children:t.email})]}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsxs("span",{className:"bg-red-500/20 text-red-300 px-3 py-1 rounded-full text-xs font-bold",children:["â",t.consumed]})}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsx("span",{className:"bg-cyan-500/20 text-cyan-300 px-3 py-1 rounded-full text-xs font-bold",children:t.balance})}),e.jsx("td",{className:"py-3 px-4 text-slate-300 text-xs capitalize",children:t.plan.replace(/_/g," ")})]},s))]})]})})})]}),e.jsxs(x,{className:"bg-slate-800/60 border-slate-700",children:[e.jsx(m,{children:e.jsxs("div",{className:"flex items-start justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsxs(h,{className:"text-white flex items-center gap-2",children:[e.jsx(v,{className:"w-5 h-5 text-amber-400"})," Function Credit Cost Registry"]}),e.jsx(f,{children:"Every backend function in your app and its GoFuel Drop cost per execution"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:q.map(t=>e.jsx("button",{onClick:()=>K(t),className:`px-3 py-1 rounded-full text-xs font-bold border transition-all ${N===t?"bg-cyan-500 border-cyan-500 text-white":"border-slate-600 text-slate-400 hover:border-slate-400"}`,children:t},t))})]})}),e.jsx(p,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-700",children:[e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"Function"}),e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"Category"}),e.jsx("th",{className:"text-left py-3 px-4 text-slate-400 font-semibold",children:"AI Feature Used"}),e.jsx("th",{className:"text-right py-3 px-4 text-slate-400 font-semibold",children:"Cost / Execution"})]})}),e.jsx("tbody",{children:Z.map((t,s)=>{const a=O[t.category]||O.System;return e.jsxs("tr",{className:"border-b border-slate-700/50 hover:bg-slate-700/20 transition",children:[e.jsxs("td",{className:"py-3 px-4",children:[e.jsx("div",{className:"font-semibold text-white",children:t.label}),e.jsx("div",{className:"text-xs text-slate-500 font-mono",children:t.fn})]}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs font-bold border ${a.bg} ${a.text} ${a.border}`,children:t.category})}),e.jsx("td",{className:"py-3 px-4 text-slate-300 text-xs",children:t.feature}),e.jsx("td",{className:"py-3 px-4 text-right",children:t.cost===0?e.jsxs("span",{className:"flex items-center justify-end gap-1 text-green-400 font-bold text-xs",children:[e.jsx(he,{className:"w-3.5 h-3.5"})," Free"]}):e.jsxs("span",{className:"flex items-center justify-end gap-1 text-cyan-300 font-black text-sm",children:[e.jsx(S,{className:"w-3.5 h-3.5 fill-cyan-400 text-cyan-400"}),t.cost]})})]},s)})})]})})})]}),e.jsxs(x,{className:"bg-gradient-to-br from-amber-900/20 to-slate-900 border-amber-700/40",children:[e.jsxs(m,{children:[e.jsxs(h,{className:"text-white flex items-center gap-2",children:[e.jsx(S,{className:"w-5 h-5 text-amber-400 fill-amber-400"})," User Credit Renewals"]}),e.jsx(f,{children:"Users whose subscriptions renew within the next 30 days"})]}),e.jsx(p,{children:F.length===0?e.jsx("p",{className:"text-slate-400 text-center py-8",children:"No renewals in the next 30 days"}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:F.map((t,s)=>{var a;return e.jsx("div",{className:`p-4 rounded-xl border transition ${t.days<=3?"bg-red-900/20 border-red-500/40":"bg-slate-700/40 border-slate-600 hover:border-amber-500/40"}`,children:e.jsxs("div",{className:"flex justify-between items-start gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-bold text-white truncate",children:t.name}),e.jsx("p",{className:"text-xs text-slate-400 truncate",children:t.email}),e.jsx("p",{className:"text-xs text-slate-500 capitalize mt-1",children:(a=t.plan)==null?void 0:a.replace(/_/g," ")})]}),e.jsxs("div",{className:"text-right flex-shrink-0",children:[t.days<=3&&e.jsx(pe,{className:"w-4 h-4 text-red-400 ml-auto mb-1"}),e.jsxs("div",{className:`text-lg font-black ${t.days<=3?"text-red-400":"text-amber-400"}`,children:[t.days,"d : ",t.hours,"h"]}),e.jsx("p",{className:"text-xs text-slate-500",children:"until renew"})]})]})},s)})})})]})]})}export{Ve 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.