import{r as c,j as e,g as o}from"./index-HUEYA8gO.js";function g(){const[a,m]=c.useState({totalInvested:0,totalRoiPaid:0,activePlans:0,investments:[]}),[h,r]=c.useState(!0),[d,i]=c.useState(null);return c.useEffect(()=>{(async()=>{try{r(!0);const[s,x]=await Promise.all([fetch(o("/get_analytics.php"),{credentials:"include"}),fetch(o("/get_investments.php"),{credentials:"include"})]);if(!s.ok||!x.ok)throw new Error("Failed to fetch analytics data");const l=await s.json(),n=await x.json();l.success&&n.success?m({totalInvested:l.totalInvested||0,totalRoiPaid:l.totalRoiPaid||0,activePlans:l.activePlans||0,investments:n.investments||[]}):i(l.error||n.error||"Unknown error")}catch(s){i(s.message)}finally{r(!1)}})()},[]),h?e.jsx("div",{className:"p-8 text-center text-accent",children:"Loading analytics data..."}):d?e.jsxs("div",{className:"p-8 text-center text-red-400",children:["Error: ",d]}):e.jsxs("section",{className:"py-8",children:[e.jsx("h2",{className:"text-3xl font-extrabold mb-6 text-accent",children:"Analytics"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mb-8",children:[e.jsxs("div",{className:"bg-gradient-to-br from-accent to-sui rounded-2xl p-6 shadow-xl text-gray-900",children:[e.jsx("div",{className:"text-lg font-bold mb-2",children:"Total Invested"}),e.jsxs("div",{className:"text-3xl font-extrabold",children:["$",a.totalInvested.toLocaleString()]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-sui/80 to-accent/80 rounded-2xl p-6 shadow-xl text-gray-900",children:[e.jsx("div",{className:"text-lg font-bold mb-2",children:"Total ROI Paid"}),e.jsxs("div",{className:"text-3xl font-extrabold text-green-800",children:["$",a.totalRoiPaid.toLocaleString()]})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mb-8",children:e.jsxs("div",{className:"bg-gradient-to-br from-accent/80 to-sui/80 rounded-2xl p-6 shadow-xl text-gray-900",children:[e.jsx("div",{className:"text-lg font-bold mb-2",children:"Active Plans"}),e.jsx("div",{className:"text-3xl font-extrabold",children:a.activePlans})]})}),e.jsxs("div",{className:"bg-gray-900/80 rounded-2xl p-6 shadow-xl mt-8",children:[e.jsx("h3",{className:"text-xl font-bold mb-4 text-accent",children:"All User Investments"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-xs text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-accent/10 text-accent",children:[e.jsx("th",{className:"py-2 px-3",children:"User"}),e.jsx("th",{className:"py-2 px-3",children:"Plan"}),e.jsx("th",{className:"py-2 px-3",children:"Invested"}),e.jsx("th",{className:"py-2 px-3",children:"ROI %"}),e.jsx("th",{className:"py-2 px-3",children:"ROI Earned"}),e.jsx("th",{className:"py-2 px-3",children:"Status"})]})}),e.jsx("tbody",{children:a.investments.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:"6",className:"py-4 text-center text-gray-400",children:"No investment data available"})}):a.investments.map((t,s)=>e.jsxs("tr",{className:"border-b border-accent/10",children:[e.jsx("td",{className:"py-2 px-3 font-bold text-accent",children:t.username||"User"}),e.jsx("td",{className:"py-2 px-3",children:t.plan_name}),e.jsxs("td",{className:"py-2 px-3",children:["$",Number(t.amount_invested??0).toFixed(2)]}),e.jsxs("td",{className:"py-2 px-3",children:[t.roi_percent,"%"]}),e.jsxs("td",{className:"py-2 px-3 text-green-400",children:["$",Number(t.total_roi_earned??0).toFixed(2)]}),e.jsx("td",{className:"py-2 px-3",children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs ${t.status==="active"?"bg-green-900/30 text-green-400":"bg-gray-800 text-gray-400"}`,children:t.status})})]},s))})]})})]})]})}export{g as default};
