import{u as w,c as R,b as S,j as e}from"./index-D9pJRAs5.js";import{r as g}from"./vendor-D6aTFYy9.js";import{P as N}from"./PageHeader-qe8kxWqe.js";import{S as C}from"./StatCard-B6PlblaT.js";import{D as L,ac as D,b2 as $,q as O,aP as T,ae as b,af as F,ag as h,ah as m,ai as u,aj as p,ak as M,aS as A,aT as P}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const q=()=>{const{t:r}=w(),{orders:t}=R(),{theme:f}=S(),a=f.mode==="dark",{totalRevenue:j,averageOrderValue:v,completionRate:y}=g.useMemo(()=>{const s=t.reduce((o,n)=>o+n.totalPrice,0),i=t.length>0?s/t.length:0,l=t.length>0?t.filter(o=>o.status==="completed"||o.status==="delivered").length/t.length*100:0;return{totalRevenue:s,averageOrderValue:i,completionRate:l}},[t]),x=g.useMemo(()=>{const s=[],i=new Date;for(let l=5;l>=0;l--){const o=new Date(i.getFullYear(),i.getMonth()-l,1);s.push(o)}return s.map(l=>{const o=l.toLocaleString("default",{month:"short"}),n=t.filter(d=>{const c=new Date(d.createdAt);return c.getMonth()===l.getMonth()&&c.getFullYear()===l.getFullYear()});return{name:o,revenue:n.reduce((d,c)=>d+(c.totalPrice||0),0),orders:n.length,customers:new Set(n.map(d=>d.customerName)).size}})},[t]),k=[{label:r("analytics.stats.totalRevenue"),value:`RM ${j.toLocaleString()}`,icon:L,gradient:"from-emerald-500 to-teal-600",trend:"+12.5%"},{label:r("analytics.stats.avgOrderValue"),value:`RM ${v.toFixed(2)}`,icon:D,gradient:"from-blue-500 to-cyan-600",trend:"+8.3%"},{label:r("analytics.stats.completionRate"),value:`${y.toFixed(1)}%`,icon:$,gradient:"from-violet-500 to-purple-600",trend:"+2.1%"},{label:r("analytics.stats.totalOrders"),value:t.length,icon:O,gradient:"from-amber-500 to-orange-600",trend:`${t.length} ${r("analytics.stats.jobs")}`}];return e.jsxs("div",{className:"space-y-8 animate-fade-in pb-20",children:[e.jsx(N,{title:r("analytics.title"),subtitle:r("analytics.subtitle"),description:r("analytics.description"),icon:T,gradient:"from-violet-600 to-fuchsia-600"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6",children:k.map((s,i)=>e.jsx(C,{label:s.label,value:s.value,icon:s.icon,gradient:s.gradient,trend:s.trend},i))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:`p-6 rounded-3xl border shadow-sm ${a?"bg-slate-900 border-slate-800":"bg-white border-slate-100"}`,children:[e.jsx("h3",{className:`text-lg font-bold mb-6 ${a?"text-white":"text-slate-900"}`,children:r("analytics.charts.revenueTrends")}),e.jsx("div",{className:"h-[350px]",children:e.jsx(b,{width:"100%",height:"100%",children:e.jsxs(F,{data:x,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"revenueGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#8b5cf6",stopOpacity:.3}),e.jsx("stop",{offset:"100%",stopColor:"#8b5cf6",stopOpacity:0})]})}),e.jsx(h,{strokeDasharray:"3 3",vertical:!1,stroke:a?"#1e293b":"#e2e8f0"}),e.jsx(m,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:a?"#94a3b8":"#64748b"},dy:10}),e.jsx(u,{axisLine:!1,tickLine:!1,tick:{fill:a?"#94a3b8":"#64748b"}}),e.jsx(p,{contentStyle:{backgroundColor:a?"rgba(15, 23, 42, 0.95)":"rgba(255, 255, 255, 0.95)",border:"none",borderRadius:"12px",boxShadow:"0 10px 40px rgba(0, 0, 0, 0.2)",backdropFilter:"blur(12px)"}}),e.jsx(M,{type:"monotone",dataKey:"revenue",stroke:"#8b5cf6",strokeWidth:3,fill:"url(#revenueGrad)"})]})})})]}),e.jsxs("div",{className:`p-6 rounded-3xl border shadow-sm ${a?"bg-slate-900 border-slate-800":"bg-white border-slate-100"}`,children:[e.jsx("h3",{className:`text-lg font-bold mb-6 ${a?"text-white":"text-slate-900"}`,children:r("analytics.charts.orderVolume")}),e.jsx("div",{className:"h-[350px]",children:e.jsx(b,{width:"100%",height:"100%",children:e.jsxs(A,{data:x,children:[e.jsx(h,{strokeDasharray:"3 3",vertical:!1,stroke:a?"#1e293b":"#e2e8f0"}),e.jsx(m,{dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:a?"#94a3b8":"#64748b"},dy:10}),e.jsx(u,{axisLine:!1,tickLine:!1,tick:{fill:a?"#94a3b8":"#64748b"}}),e.jsx(p,{contentStyle:{backgroundColor:a?"rgba(15, 23, 42, 0.95)":"rgba(255, 255, 255, 0.95)",border:"none",borderRadius:"12px",boxShadow:"0 10px 40px rgba(0, 0, 0, 0.2)",backdropFilter:"blur(12px)"}}),e.jsx(P,{dataKey:"orders",fill:"#3b82f6",radius:[4,4,0,0]})]})})})]})]})]})};export{q as default};
