%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : /home2/rezakur1/ai.rezakurnia.com/assets/DashboardPage-Bpyo9lTA.js |
import{r as n,a as w,j as e,L}from"./index-CYXd_ywS.js";import{u as C}from"./useWallet-zSIKlLaL.js";import{B as T}from"./Button-BtCTiucz.js";import{C as h,a as g,b as k}from"./Card-DxTZG1_W.js";import{S as m}from"./StatCard-DTooG2Uf.js";import{b as v,c as l,f as _,d as z}from"./format-CjhWL3Ta.js";import{R,C as S,X as q,Y as A,T as M}from"./CartesianChart-DrWDYIYJ.js";import{A as B,a as N}from"./AreaChart-V8oZPMY_.js";import{B as O}from"./Badge-Bs3KAUoA.js";import"./index-CyoKYIp9.js";import"./with-selector-DIjl9Exq.js";function D(t=30){const[s,r]=n.useState(null),[u,o]=n.useState(!0),[p,x]=n.useState(null),[i,f]=n.useState(0),j=n.useCallback(()=>f(a=>a+1),[]);return n.useEffect(()=>{let a=!1;return o(!0),x(null),w(`/me/dashboard?days=${t}`).then(c=>{a||r(c)}).catch(c=>{a||x(c.message)}).finally(()=>{a||o(!1)}),()=>{a=!0}},[t,i]),{data:s,loading:u,error:p,refresh:j}}function H({active:t,payload:s}){if(!t||!(s!=null&&s.length))return null;const r=s[0].payload;return e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-ink-900 px-3.5 py-2.5 text-xs shadow-modal",children:[e.jsx("p",{className:"mb-1.5 font-semibold text-white",children:v(r.date)}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"flex justify-between gap-6 text-slate-400",children:["Requests"," ",e.jsx("span",{className:"font-semibold tabular-nums text-white",children:r.requests})]}),e.jsxs("p",{className:"flex justify-between gap-6 text-slate-400",children:["Input token"," ",e.jsx("span",{className:"font-semibold tabular-nums text-white",children:l(r.input_tokens)})]}),e.jsxs("p",{className:"flex justify-between gap-6 text-slate-400",children:["Cached token"," ",e.jsx("span",{className:"font-semibold tabular-nums text-white",children:l(r.cached_tokens)})]}),e.jsxs("p",{className:"flex justify-between gap-6 text-slate-400",children:["Output token"," ",e.jsx("span",{className:"font-semibold tabular-nums text-white",children:l(r.output_tokens)})]})]})]})}const y=t=>e.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:t}});function W({data:t}){return t.length===0?e.jsx("div",{className:"flex h-64 items-center justify-center text-sm text-slate-500",children:"Belum ada data penggunaan pada rentang ini."}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4 flex items-center gap-5 text-xs text-slate-400",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[y("#3b82f6")," Requests"]}),e.jsxs("span",{className:"flex items-center gap-2",children:[y("#60a5fa")," Output token"]})]}),e.jsx("div",{className:"h-64 w-full",children:e.jsx(R,{width:"100%",height:"100%",children:e.jsxs(B,{data:t,margin:{top:4,right:4,left:-12,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"gRequests",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#3b82f6",stopOpacity:.28}),e.jsx("stop",{offset:"100%",stopColor:"#3b82f6",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"gTokens",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#60a5fa",stopOpacity:.18}),e.jsx("stop",{offset:"100%",stopColor:"#60a5fa",stopOpacity:0})]})]}),e.jsx(S,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.05)",vertical:!1}),e.jsx(q,{dataKey:"date",tickFormatter:v,tick:{fill:"#475569",fontSize:11},axisLine:!1,tickLine:!1,minTickGap:24}),e.jsx(A,{tick:{fill:"#475569",fontSize:11},tickFormatter:l,axisLine:!1,tickLine:!1}),e.jsx(M,{content:e.jsx(H,{}),cursor:{stroke:"rgba(255,255,255,0.1)"}}),e.jsx(N,{type:"monotone",dataKey:"requests",stroke:"#3b82f6",strokeWidth:2,fill:"url(#gRequests)",name:"Requests"}),e.jsx(N,{type:"monotone",dataKey:"output_tokens",stroke:"#60a5fa",strokeWidth:1.5,fill:"url(#gTokens)",name:"Output token"})]})})})]})}function K(t){return t>=200&&t<300?"success":t>=400?"danger":"warning"}function P({items:t}){return t.length===0?e.jsx("div",{className:"py-10 text-center text-sm text-slate-500",children:"Belum ada aktivitas tercatat."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[640px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Endpoint"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Key"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Input"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Cached"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Output"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Waktu"})]})}),e.jsx("tbody",{children:t.map(s=>e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsx("span",{className:"font-mono text-xs text-slate-300",children:s.endpoint})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(O,{tone:K(s.http_status),children:s.http_status})}),e.jsxs("td",{className:"px-4 py-3 text-xs text-slate-400",children:[s.key_name,e.jsx("span",{className:"ml-1.5 font-mono text-[10px] text-slate-600",children:s.key_prefix})]}),e.jsx("td",{className:"px-4 py-3 text-right font-medium tabular-nums text-slate-300",children:l(s.input_tokens)}),e.jsx("td",{className:"px-4 py-3 text-right font-medium tabular-nums text-slate-500",children:l(s.cached_tokens)}),e.jsx("td",{className:"px-4 py-3 text-right font-medium tabular-nums text-slate-300",children:l(s.output_tokens)}),e.jsx("td",{className:"px-5 py-3 text-right text-xs tabular-nums text-slate-500",children:_(s.created_at)})]},s.id))})]})})}function b({className:t=""}){return e.jsx("div",{className:`animate-pulse rounded-2xl border border-white/[0.04] bg-white/[0.02] ${t}`})}const d={className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.7};function Z(){const{data:t,loading:s,error:r,refresh:u}=D(30),{data:o}=C(),[p,x]=n.useState(30);if(r)return e.jsxs(h,{className:"p-8 text-center",children:[e.jsxs("p",{className:"text-sm text-red-300",children:["Gagal memuat dashboard: ",r]}),e.jsx("button",{onClick:u,className:"mt-4 rounded-xl border border-white/[0.08] bg-white/[0.03] px-4 py-2 text-sm font-medium text-white transition hover:bg-white/[0.06]",children:"Coba lagi"})]});if(s||!t)return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[...Array(4)].map((a,c)=>e.jsx(b,{className:"h-28"},c))}),e.jsx(b,{className:"h-80"}),e.jsx(b,{className:"h-64"})]});const{summary:i,daily:f,activity:j}=t;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold tracking-tight text-white sm:text-2xl",children:["Halo, ",t.account.name.split(" ")[0]," 👋"]}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Ringkasan aktivitas gateway 30 hari terakhir."})]}),e.jsx("div",{className:"flex items-center gap-1 rounded-xl border border-white/[0.06] bg-white/[0.03] p-1",children:[7,30].map(a=>e.jsxs("button",{onClick:()=>x(a),className:`rounded-lg px-3.5 py-1.5 text-xs font-medium transition-colors ${p===a?"bg-white/[0.08] text-white":"text-slate-500 hover:text-slate-300"}`,children:[a," hari"]},a))})]}),e.jsxs(h,{className:"flex flex-wrap items-center justify-between gap-4 p-5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-white/[0.06] bg-white/[0.04] text-brand-300",children:e.jsx("svg",{...d,className:"h-6 w-6",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 8.25h19.5m-16.5.75h12a2.25 2.25 0 012.25 2.25v3a2.25 2.25 0 01-2.25 2.25h-12A2.25 2.25 0 012.25 14.25v-3a2.25 2.25 0 012.25-2.25z"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-slate-400",children:"Saldo Wallet"}),e.jsx("p",{className:"mt-0.5 text-2xl font-bold tracking-tight tabular-nums text-white",children:o?z(o.wallet.balance):"—"})]})]}),e.jsx(L,{to:"/topup",children:e.jsxs(T,{children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 4.5v15m7.5-7.5h-15"})}),"Top Up"]})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(m,{label:"Total Requests",value:i.requests,accent:"pink",hint:"Permintaan API",icon:e.jsx("svg",{...d,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 6.75h12M8.25 12h12m-12 5.25h12M3.75 6.75h.007v.008H3.75V6.75zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zM3.75 12h.007v.008H3.75V12zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zm-.375 5.25h.007v.008H3.75v-.008zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"})})}),e.jsx(m,{label:"Input Tokens",value:i.input_tokens,accent:"fuchsia",icon:e.jsx("svg",{...d,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.456 2.456L21.75 6l-1.035.259a3.375 3.375 0 00-2.456 2.456z"})})}),e.jsx(m,{label:"Cached Tokens",value:i.cached_tokens,accent:"rose",icon:e.jsx("svg",{...d,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7l4.029-1.523a.75.75 0 01.93.539v.011a.75.75 0 01-.539.93l-4.029 1.523a8.25 8.25 0 01-13.803 3.7l-3.182-3.182v-.001z"})})}),e.jsx(m,{label:"Output Tokens",value:i.output_tokens,accent:"hot",icon:e.jsx("svg",{...d,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"})})})]}),e.jsxs(h,{children:[e.jsx(g,{title:"Tren Penggunaan Harian",subtitle:"Requests vs output tokens per hari"}),e.jsx(k,{children:e.jsx(W,{data:f})})]}),e.jsxs(h,{children:[e.jsx(g,{title:"Aktivitas Terbaru",subtitle:"20 request terakhir menggunakan API key Anda"}),e.jsx(k,{className:"p-0",children:e.jsx(P,{items:j})})]})]})}export{Z as default};