"use client"; import { useEffect, useState } from "react"; import { Search, Wallet, Sun, CalendarDays, ShoppingBag, Users, ChevronRight, ChevronLeft, } from "lucide-react"; import Shell from "@/components/Shell"; import StatCard from "@/components/StatCard"; import Badge from "@/components/Badge"; import { TableSkeleton } from "@/components/Skeleton"; import Empty from "@/components/Empty"; import { fmtNum } from "@/components/NumberInput"; import { api } from "@/lib/api"; import { KIND_LABEL, KIND_TONE, STATUS_LABEL, STATUS_TONE, STORE_LABEL } from "@/lib/labels"; type Purchase = { id: number; user_id: number; mobile: string; name: string; store: string; kind: string; product_id: string; coins: number; tickets: number; vip_days: number; price_toman: number; status: string; product_title: string; created_local: string; }; type Stats = { total_revenue: number; verified_count: number; unique_buyers: number; avg_revenue: number; today: { count: number; revenue: number }; month: { count: number; revenue: number }; }; type Resp = { purchases: Purchase[]; stats: Stats; total: number; page: number; page_size: number; pages: number; }; function received(p: Purchase): string { const parts: string[] = []; if (p.coins) parts.push(`${fmtNum(p.coins)} سکه`); if (p.tickets) parts.push(`${fmtNum(p.tickets)} بلیط`); if (p.vip_days) parts.push(`${fmtNum(p.vip_days)} روز VIP`); return parts.join("، ") || "—"; } export default function TransactionsPage() { const [q, setQ] = useState(""); const [qApplied, setQApplied] = useState(""); const [store, setStore] = useState(""); const [kind, setKind] = useState(""); const [status, setStatus] = useState("verified"); const [page, setPage] = useState(1); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [err, setErr] = useState(""); useEffect(() => { let alive = true; setLoading(true); setErr(""); const params = new URLSearchParams(); if (qApplied) params.set("q", qApplied); if (store) params.set("store", store); if (kind) params.set("kind", kind); if (status) params.set("status", status); params.set("page", String(page)); api .get(`/purchases?${params.toString()}`) .then((r) => { if (alive) setData(r); }) .catch((e) => { if (alive) setErr(e.message); }) .finally(() => { if (alive) setLoading(false); }); return () => { alive = false; }; }, [qApplied, store, kind, status, page]); const s = data?.stats; return ( {err &&

{err}

}
} color="var(--gold)" loading={loading} /> } color="#4ade80" sub={s ? `${fmtNum(s.today.count)} خرید` : undefined} loading={loading} /> } color="#60a5fa" loading={loading} /> } color="#c084fc" sub={s ? `میانگین ${fmtNum(s.avg_revenue)} تومان` : undefined} loading={loading} /> } color="#fbbf24" loading={loading} />
{ e.preventDefault(); setQApplied(q.trim()); setPage(1); }} > setQ(e.target.value)} />
{loading ? ( ) : !data || data.purchases.length === 0 ? ( ) : ( <>
{data.purchases.map((p) => ( ))}
کاربر محصول نوع مبلغ دریافت فروشگاه زمان (تهران) وضعیت
{p.name || "—"}
{p.mobile} · {p.user_id}
{p.product_title || p.product_id}
{p.product_id}
{KIND_LABEL[p.kind] ?? (p.kind || "نامشخص")} {fmtNum(p.price_toman)} {" "} تومان {received(p)} {STORE_LABEL[p.store] ?? p.store} {p.created_local} {STATUS_LABEL[p.status] ?? p.status}
صفحه {fmtNum(data.page)} از {fmtNum(data.pages)} — {fmtNum(data.total)} تراکنش
)}
); }