merge: resolve merge conflicts in ArchivePage.tsx and graphify-out from develop

This commit is contained in:
parsa aghaei committed 2026-08-26 10:17:09 +03:30
commit 753b3dd7ec
48 files changed
+240706 -94210

No files matched your search

+5 -4
View File
@@ -684,13 +684,14 @@ export default function Blogs() {
{blog.author?.firstName ? `${blog.author.firstName} ${blog.author.lastName || ''}` : 'نامشخص'}
</td>
<td className="py-4 px-6 text-gray-500 text-xs font-medium">
<div className="flex items-center gap-1">
<div className="flex items-center gap-1 mb-1">
<Clock className="w-3.5 h-3.5 text-gray-400" />
<span>{blog.readingTime || 3} دقیقه</span>
</div>
<span className="text-[10px] text-gray-400 mt-0.5 block">
{blog.viewCount || 0} بازدید
</span>
<div className="inline-flex items-center gap-1 px-2 py-0.5 bg-gray-100 text-gray-700 rounded-md font-mono text-[11px] font-bold">
<Eye className="w-3 h-3 text-purple-600" />
<span>{(blog.viewCount || 0).toLocaleString('fa-IR')} بازدید</span>
</div>
</td>
<td className="py-4 px-6">{renderStatusBadge(blog.status, blog.isPublished)}</td>
<td className="py-4 px-6">
+300 -101
View File
@@ -1,11 +1,21 @@
import { useState, useEffect } from 'react';
import { TrendingUp, DollarSign, ShoppingBag, Users, HeartHandshake, Download } from 'lucide-react';
import { useState, useEffect, useCallback } from 'react';
import {
TrendingUp,
DollarSign,
ShoppingBag,
Users,
HeartHandshake,
Download,
Calendar,
Filter,
Receipt,
Percent,
Package,
ShieldCheck
} from 'lucide-react';
import api from '../services/api';
import Button from '../components/ui/Button';
import Spinner from '../components/ui/Spinner';
import {
AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer,
BarChart, Bar, PieChart, Pie, Cell, Legend
@@ -15,16 +25,21 @@ const COLORS = ['#8B5CF6', '#EC4899', '#3B82F6', '#10B981', '#F59E0B'];
interface CustomTooltipProps {
active?: boolean;
payload?: Array<{ value: number | string }>;
payload?: Array<{ value: number | string; name?: string; color?: string }>;
label?: string;
}
const CustomTooltip = ({ active, payload, label }: CustomTooltipProps) => {
if (active && payload && payload.length) {
return (
<div className="bg-white p-4 rounded-xl shadow-lg border border-gray-100">
<div className="bg-white p-4 rounded-xl shadow-lg border border-gray-100 text-right font-vazir" dir="rtl">
<p className="font-bold text-gray-900 mb-2">{label}</p>
<p className="text-purple-600 font-bold">{Number(payload[0].value).toLocaleString()} تومان</p>
{payload.map((item, idx) => (
<div key={idx} className="flex items-center justify-between gap-4 text-xs font-bold my-1">
<span style={{ color: item.color }}>{item.name || 'مبلغ'}:</span>
<span>{Number(item.value).toLocaleString()} تومان</span>
</div>
))}
</div>
);
}
@@ -50,13 +65,20 @@ export interface TopCouponItem {
export interface ReportData {
overview?: {
totalRevenue: number;
totalOrders: number;
totalUsers: number;
avgOrderValue: number;
totalCharity?: number;
productSalesRevenue?: number;
totalOrders: number;
totalUsers?: number;
avgOrderValue?: number;
b2bRevenue?: number;
b2cRevenue?: number;
totalTax?: number;
totalShipping?: number;
totalDiscounts?: number;
totalCostOfGoods?: number;
netProfit?: number;
};
salesTimeline?: Array<{ date: string; amount: number }>;
salesTimeline?: Array<{ date: string; amount: number; charity?: number; sales?: number }>;
bestSellers?: BestSellerItem[];
categoryDistribution?: CategoryDistItem[];
topCoupons?: TopCouponItem[];
@@ -66,40 +88,72 @@ export default function Reports() {
const [reportData, setReportData] = useState<ReportData | null>(null);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
let isSubscribed = true;
api.get('/admin/reports').then(reportRes => {
if (!isSubscribed) return;
if (reportRes.data?.success) {
setReportData(reportRes.data.data);
}
}).catch(err => {
console.error(err);
}).finally(() => {
if (isSubscribed) setIsLoading(false);
});
return () => {
isSubscribed = false;
};
}, []);
// Filter States
const [dateFilterType, setDateFilterType] = useState<'all' | 'today' | '7days' | '30days' | 'custom'>('30days');
const [startDate, setStartDate] = useState('');
const [endDate, setEndDate] = useState('');
const [roleFilter, setRoleFilter] = useState('ALL');
if (isLoading) {
const fetchReports = useCallback(async () => {
try {
setIsLoading(true);
const params: Record<string, string> = {};
const now = new Date();
if (dateFilterType === 'today') {
const start = new Date(now);
start.setHours(0, 0, 0, 0);
params.startDate = start.toISOString();
} else if (dateFilterType === '7days') {
const start = new Date(now);
start.setDate(now.getDate() - 7);
params.startDate = start.toISOString();
} else if (dateFilterType === '30days') {
const start = new Date(now);
start.setDate(now.getDate() - 30);
params.startDate = start.toISOString();
} else if (dateFilterType === 'custom') {
if (startDate) params.startDate = startDate;
if (endDate) params.endDate = endDate;
}
if (roleFilter !== 'ALL') {
params.role = roleFilter;
}
const res = await api.get('/admin/reports', { params });
if (res.data?.success) {
setReportData(res.data.data);
}
} catch (err) {
console.error('Failed to fetch reports:', err);
} finally {
setIsLoading(false);
}
}, [dateFilterType, startDate, endDate, roleFilter]);
useEffect(() => {
fetchReports();
}, [fetchReports]);
if (isLoading && !reportData) {
return <div className="flex justify-center items-center h-96"><Spinner size="lg" className="text-purple-600" /></div>;
}
if (!reportData) return <div className="text-center py-12 text-gray-500 font-bold">اطلاعاتی یافت نشد</div>;
const { overview, salesTimeline, bestSellers, categoryDistribution, topCoupons } = reportData;
const { overview, salesTimeline, bestSellers, categoryDistribution, topCoupons } = reportData || {};
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row justify-between gap-4">
<div className="space-y-6 font-vazir text-right" dir="rtl">
{/* Header */}
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 bg-white p-6 rounded-3xl border border-gray-200 shadow-xs">
<div>
<h2 className="text-2xl font-black text-gray-900 flex items-center gap-2">
<TrendingUp className="w-6 h-6 text-purple-600" />
گزارشات و تحلیل‌ها
گزارشات و تحلیل‌های مالی پیشرفته
</h2>
<p className="text-gray-500 font-medium mt-1">آمار فروش، رفتار کاربران و عملکرد تخفیف‌ها</p>
<p className="text-gray-500 font-medium text-xs sm:text-sm mt-1">
تفکیک درآمد کالاها، مبالغ واریزی مهربانی، مالیات، تخفیف‌ها و سود خالص
</p>
</div>
<Button
variant="outline"
@@ -108,73 +162,212 @@ export default function Reports() {
onClick={() => {
if (!reportData) return;
const rows = [
['گزارش کلی سیستم کنینا ایران'],
['درآمد کل (تومان)', overview?.totalRevenue || 0],
['تعداد سفارشات', overview?.totalOrders || 0],
['تعداد کاربران', overview?.totalUsers || 0],
['میانگین ارزش سفارش', overview?.avgOrderValue || 0],
['گزارش مالی و عملکرد فروش کنینا ایران'],
['تاریخ گزارش', new Date().toLocaleDateString('fa-IR')],
[],
['محصولات پرفروش', 'تعداد فروش'],
['شاخص مالی', 'مبلغ (تومان) / مقدار'],
['درآمد کل واریزی‌ها', overview?.totalRevenue || 0],
['سهم مهربانی (خیریه)', overview?.totalCharity || 0],
['خالص فروش کالاها', overview?.productSalesRevenue || 0],
['بهای تمام‌شده کالاها (COGS)', overview?.totalCostOfGoods || 0],
['مجموع مالیات بر ارزش افزوده', overview?.totalTax || 0],
['مجموع تخفیف‌های اعمال شده', overview?.totalDiscounts || 0],
['سود خالص تخمینی', overview?.netProfit || 0],
['تعداد کل سفارشات', overview?.totalOrders || 0],
['فروش همکاران (B2B)', overview?.b2bRevenue || 0],
['فروش مصرف‌کنندگان (B2C)', overview?.b2cRevenue || 0],
[],
['محصولات پرفروش در این بازه', 'تعداد فروش'],
...(bestSellers || []).map(b => [b.name, b.quantity]),
];
const csvContent = 'data:text/csv;charset=utf-8,\uFEFF' + rows.map(e => e.join(',')).join('\n');
const encodedUri = encodeURI(csvContent);
const link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('download', `Canina_Sales_Report_${new Date().toISOString().split('T')[0]}.csv`);
link.setAttribute('download', `Canina_Financial_Report_${new Date().toISOString().split('T')[0]}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}}
>
خروجی اکسل (Excel)
خروجی اکسل مالی (Excel / CSV)
</Button>
</div>
{/* Filter Toolbar */}
<div className="bg-white p-4 rounded-3xl shadow-xs border border-gray-200 flex flex-wrap items-center gap-3">
<div className="flex items-center gap-2">
<Filter className="w-4 h-4 text-purple-600" />
<span className="text-xs font-black text-gray-700">بازه زمانی:</span>
</div>
{/* Overview Cards */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div className="bg-gradient-to-br from-purple-500 to-indigo-600 p-6 rounded-2xl text-white shadow-lg shadow-purple-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-purple-100">درآمد کل</h3>
<div className="p-2 bg-white/20 rounded-xl"><DollarSign className="w-6 h-6" /></div>
</div>
<p className="text-3xl font-black">{Number(overview.totalRevenue).toLocaleString()}</p>
<p className="text-purple-200 text-sm mt-1">تومان</p>
<div className="flex flex-wrap items-center gap-1.5 bg-gray-50 p-1 rounded-2xl border border-gray-200 text-xs font-bold">
<button
onClick={() => setDateFilterType('30days')}
className={`px-3 py-1.5 rounded-xl transition-all ${dateFilterType === '30days' ? 'bg-purple-600 text-white shadow-xs' : 'text-gray-600 hover:text-purple-600'}`}
>
۳۰ روز اخیر
</button>
<button
onClick={() => setDateFilterType('7days')}
className={`px-3 py-1.5 rounded-xl transition-all ${dateFilterType === '7days' ? 'bg-purple-600 text-white shadow-xs' : 'text-gray-600 hover:text-purple-600'}`}
>
۷ روز اخیر
</button>
<button
onClick={() => setDateFilterType('today')}
className={`px-3 py-1.5 rounded-xl transition-all ${dateFilterType === 'today' ? 'bg-purple-600 text-white shadow-xs' : 'text-gray-600 hover:text-purple-600'}`}
>
امروز
</button>
<button
onClick={() => setDateFilterType('all')}
className={`px-3 py-1.5 rounded-xl transition-all ${dateFilterType === 'all' ? 'bg-purple-600 text-white shadow-xs' : 'text-gray-600 hover:text-purple-600'}`}
>
کل تاریخچه
</button>
<button
onClick={() => setDateFilterType('custom')}
className={`px-3 py-1.5 rounded-xl transition-all ${dateFilterType === 'custom' ? 'bg-purple-600 text-white shadow-xs' : 'text-gray-600 hover:text-purple-600'}`}
>
بازه سفارشی
</button>
</div>
<div className="bg-gradient-to-br from-pink-500 to-rose-600 p-6 rounded-2xl text-white shadow-lg shadow-pink-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-pink-100">سهم خیریه (مسئولیت اجتماعی)</h3>
<div className="p-2 bg-white/20 rounded-xl"><HeartHandshake className="w-6 h-6" /></div>
{dateFilterType === 'custom' && (
<div className="flex items-center gap-2 text-xs">
<input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
className="px-3 py-1.5 rounded-xl border border-gray-200 outline-none text-xs"
/>
<span className="text-gray-400">تا</span>
<input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
className="px-3 py-1.5 rounded-xl border border-gray-200 outline-none text-xs"
/>
</div>
<p className="text-3xl font-black">{Number(overview.totalCharity).toLocaleString()}</p>
<p className="text-pink-200 text-sm mt-1">تومان</p>
</div>
<div className="bg-gradient-to-br from-blue-500 to-cyan-600 p-6 rounded-2xl text-white shadow-lg shadow-blue-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-blue-100">فروش همکاران (B2B)</h3>
<div className="p-2 bg-white/20 rounded-xl"><Users className="w-6 h-6" /></div>
</div>
<p className="text-3xl font-black">{Number(overview.b2bRevenue).toLocaleString()}</p>
<p className="text-blue-200 text-sm mt-1">تومان</p>
</div>
<div className="bg-gradient-to-br from-emerald-500 to-teal-600 p-6 rounded-2xl text-white shadow-lg shadow-emerald-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-emerald-100">تعداد سفارشات</h3>
<div className="p-2 bg-white/20 rounded-xl"><ShoppingBag className="w-6 h-6" /></div>
</div>
<p className="text-3xl font-black">{overview.totalOrders}</p>
<p className="text-emerald-200 text-sm mt-1">موفق</p>
)}
<div className="flex items-center gap-2 mr-auto">
<span className="text-xs font-black text-gray-700">نوع مشتری:</span>
<select
value={roleFilter}
onChange={(e) => setRoleFilter(e.target.value)}
className="px-3 py-1.5 rounded-xl border border-gray-200 text-xs font-bold outline-none bg-gray-50/50"
>
<option value="ALL">همه (B2B + B2C)</option>
<option value="B2B">خریداران عمده (B2B)</option>
<option value="User_PetOwner">مصرف‌کنندگان (B2C)</option>
</select>
</div>
</div>
{/* Overview Cards (Core Revenue & Charity) */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
{/* Total Deposited */}
<div className="bg-gradient-to-br from-purple-600 to-indigo-700 p-6 rounded-3xl text-white shadow-lg shadow-purple-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-purple-100 text-sm">مجموع کل واریزی‌ها</h3>
<div className="p-2.5 bg-white/20 rounded-2xl"><DollarSign className="w-5 h-5" /></div>
</div>
<p className="text-3xl font-black">{Number(overview?.totalRevenue || 0).toLocaleString()}</p>
<p className="text-purple-200 text-xs mt-1">تومان (شامل کالا و مهربانی)</p>
</div>
{/* Charity Share */}
<div className="bg-gradient-to-br from-rose-500 to-pink-600 p-6 rounded-3xl text-white shadow-lg shadow-pink-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-rose-100 text-sm">سهم مبالغ مهربانی (خیریه)</h3>
<div className="p-2.5 bg-white/20 rounded-2xl"><HeartHandshake className="w-5 h-5" /></div>
</div>
<p className="text-3xl font-black">{Number(overview?.totalCharity || 0).toLocaleString()}</p>
<p className="text-rose-200 text-xs mt-1">
{overview?.totalRevenue ? `${((Number(overview.totalCharity || 0) / Number(overview.totalRevenue)) * 100).toFixed(1)}% از کل دریافتی` : 'تومان'}
</p>
</div>
{/* Product Sales Only */}
<div className="bg-gradient-to-br from-blue-600 to-cyan-700 p-6 rounded-3xl text-white shadow-lg shadow-blue-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-blue-100 text-sm">خالص فروش محصولات</h3>
<div className="p-2.5 bg-white/20 rounded-2xl"><ShoppingBag className="w-5 h-5" /></div>
</div>
<p className="text-3xl font-black">{Number(overview?.productSalesRevenue || (Number(overview?.totalRevenue || 0) - Number(overview?.totalCharity || 0))).toLocaleString()}</p>
<p className="text-blue-200 text-xs mt-1">تومان (بدون احتساب مبالغ خیریه)</p>
</div>
{/* Net Profit */}
<div className="bg-gradient-to-br from-emerald-600 to-teal-700 p-6 rounded-3xl text-white shadow-lg shadow-emerald-200">
<div className="flex items-center justify-between mb-4">
<h3 className="font-bold text-emerald-100 text-sm">سود خالص تخمینی</h3>
<div className="p-2.5 bg-white/20 rounded-2xl"><TrendingUp className="w-5 h-5" /></div>
</div>
<p className="text-3xl font-black">{Number(overview?.netProfit || 0).toLocaleString()}</p>
<p className="text-emerald-200 text-xs mt-1">تومان (پس از کسر خرید، مالیات و تخفیف)</p>
</div>
</div>
{/* Financial Breakdown Section (Item 2 Requirement) */}
<div className="bg-white p-6 rounded-3xl border border-gray-200 shadow-xs">
<h3 className="text-lg font-black text-gray-900 mb-4 flex items-center gap-2">
<Receipt className="w-5 h-5 text-purple-600" />
تراز و تفکیک اجزای مالی
</h3>
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3">
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">بهای خرید کالاها (COGS)</span>
<span className="text-base font-black text-gray-800">{Number(overview?.totalCostOfGoods || 0).toLocaleString()}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">تومان</span>
</div>
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">مالیات بر ارزش افزوده</span>
<span className="text-base font-black text-amber-600">{Number(overview?.totalTax || 0).toLocaleString()}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">تومان</span>
</div>
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">مجموع تخفیف‌ها</span>
<span className="text-base font-black text-red-500">{Number(overview?.totalDiscounts || 0).toLocaleString()}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">تومان</span>
</div>
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">فروش عمده (B2B)</span>
<span className="text-base font-black text-blue-600">{Number(overview?.b2bRevenue || 0).toLocaleString()}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">تومان</span>
</div>
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">فروش تکی (B2C)</span>
<span className="text-base font-black text-indigo-600">{Number(overview?.b2cRevenue || 0).toLocaleString()}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">تومان</span>
</div>
<div className="p-4 bg-gray-50 rounded-2xl border border-gray-100">
<span className="text-[11px] font-bold text-gray-400 block mb-1">تعداد کل سفارشات</span>
<span className="text-base font-black text-emerald-600">{overview?.totalOrders || 0}</span>
<span className="text-[10px] text-gray-400 block mt-0.5">سفارش موفق</span>
</div>
</div>
</div>
{/* Charts Section */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Sales Chart */}
<div className="lg:col-span-2 bg-white p-6 rounded-2xl shadow-sm border border-gray-100">
<h3 className="text-lg font-bold text-gray-900 mb-6">نمودار فروش روزانه</h3>
{/* Timeline Chart with Dual Area for Total & Charity */}
<div className="lg:col-span-2 bg-white p-6 rounded-3xl shadow-xs border border-gray-200">
<div className="flex items-center justify-between mb-6">
<h3 className="text-base font-black text-gray-900">روند فروش و واریزی‌های مهربانی</h3>
<div className="flex items-center gap-4 text-xs font-bold">
<span className="flex items-center gap-1.5 text-purple-600">
<span className="w-2.5 h-2.5 rounded-full bg-purple-600" />
کل واریزی
</span>
<span className="flex items-center gap-1.5 text-rose-500">
<span className="w-2.5 h-2.5 rounded-full bg-rose-500" />
سهم مهربانی
</span>
</div>
</div>
<div className="h-80 w-full" dir="ltr">
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={salesTimeline} margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
@@ -183,20 +376,25 @@ export default function Reports() {
<stop offset="5%" stopColor="#8B5CF6" stopOpacity={0.3}/>
<stop offset="95%" stopColor="#8B5CF6" stopOpacity={0}/>
</linearGradient>
<linearGradient id="colorCharity" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="#F43F5E" stopOpacity={0.3}/>
<stop offset="95%" stopColor="#F43F5E" stopOpacity={0}/>
</linearGradient>
</defs>
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#f3f4f6" />
<XAxis dataKey="date" stroke="#9ca3af" fontSize={12} tickLine={false} axisLine={false} />
<YAxis stroke="#9ca3af" fontSize={12} tickLine={false} axisLine={false} tickFormatter={(val) => `${val / 1000}k`} />
<XAxis dataKey="date" stroke="#9ca3af" fontSize={11} tickLine={false} axisLine={false} />
<YAxis stroke="#9ca3af" fontSize={11} tickLine={false} axisLine={false} tickFormatter={(val) => `${val >= 1000000 ? `${(val/1000000).toFixed(1)}M` : `${val / 1000}k`}`} />
<RechartsTooltip content={<CustomTooltip />} />
<Area type="monotone" dataKey="amount" stroke="#8B5CF6" strokeWidth={3} fillOpacity={1} fill="url(#colorSales)" />
<Area type="monotone" name="کل دریافتی" dataKey="amount" stroke="#8B5CF6" strokeWidth={2.5} fillOpacity={1} fill="url(#colorSales)" />
<Area type="monotone" name="سهم مهربانی" dataKey="charity" stroke="#F43F5E" strokeWidth={2} fillOpacity={1} fill="url(#colorCharity)" />
</AreaChart>
</ResponsiveContainer>
</div>
</div>
{/* Category Distribution */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-100">
<h3 className="text-lg font-bold text-gray-900 mb-6">سهم فروش دسته‌بندی‌ها</h3>
<div className="bg-white p-6 rounded-3xl shadow-xs border border-gray-200">
<h3 className="text-base font-black text-gray-900 mb-6">سهم فروش دسته‌بندی‌ها</h3>
<div className="h-64 w-full flex justify-center">
{categoryDistribution && categoryDistribution.length > 0 ? (
<ResponsiveContainer width="100%" height="100%">
@@ -211,19 +409,20 @@ export default function Reports() {
</PieChart>
</ResponsiveContainer>
) : (
<div className="text-gray-400 font-medium flex items-center justify-center h-full">داده‌ای موجود نیست</div>
<div className="text-gray-400 font-medium flex items-center justify-center h-full text-xs">داده‌ای موجود نیست</div>
)}
</div>
</div>
</div>
{/* Best Sellers & Top Coupons */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Best Sellers */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-100">
<h3 className="text-lg font-bold text-gray-900 mb-6">پرفروش‌ترین محصولات</h3>
<div className="min-h-[320px] w-full" dir="ltr">
<div className="bg-white p-6 rounded-3xl shadow-xs border border-gray-200">
<h3 className="text-base font-black text-gray-900 mb-6">پرفروش‌ترین محصولات در بازه انتخابی</h3>
<div className="min-h-[300px] w-full" dir="ltr">
{bestSellers && bestSellers.length > 0 ? (
<ResponsiveContainer width="100%" height={Math.max(300, bestSellers.length * 45)}>
<ResponsiveContainer width="100%" height={Math.max(280, bestSellers.length * 45)}>
<BarChart
data={bestSellers}
layout="vertical"
@@ -251,31 +450,31 @@ export default function Reports() {
</BarChart>
</ResponsiveContainer>
) : (
<div className="text-gray-400 font-medium flex items-center justify-center h-64">داده‌ای موجود نیست</div>
<div className="text-gray-400 font-medium flex items-center justify-center h-64 text-xs">داده‌ای موجود نیست</div>
)}
</div>
</div>
{/* Top Coupons */}
<div className="bg-white p-6 rounded-2xl shadow-sm border border-gray-100">
<h3 className="text-lg font-bold text-gray-900 mb-6">پرکاربردترین کدهای تخفیف</h3>
<div className="space-y-4">
<div className="bg-white p-6 rounded-3xl shadow-xs border border-gray-200">
<h3 className="text-base font-black text-gray-900 mb-6">کدهای تخفیف پراستفاده</h3>
<div className="space-y-3">
{topCoupons && topCoupons.length > 0 ? (
topCoupons.map((coupon: TopCouponItem, idx: number) => (
<div key={idx} className="flex items-center justify-between p-4 bg-gray-50 rounded-xl border border-gray-100">
<div key={idx} className="flex items-center justify-between p-4 bg-gray-50 rounded-2xl border border-gray-100">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-lg bg-orange-100 text-orange-600 font-bold flex items-center justify-center text-sm">
<div className="w-9 h-9 rounded-xl bg-purple-100 text-purple-600 font-black flex items-center justify-center text-xs">
#{idx + 1}
</div>
<span className="font-mono font-bold tracking-widest text-gray-800">{coupon.name}</span>
<span className="font-mono font-bold tracking-widest text-gray-800 text-sm">{coupon.name}</span>
</div>
<div className="text-gray-600 font-medium">
<span className="font-black text-gray-900 mx-1">{coupon.usedCount ?? coupon.value ?? 0}</span>بار استفاده
<div className="text-gray-600 text-xs font-medium">
<span className="font-black text-gray-900 mx-1 text-sm">{coupon.usedCount ?? coupon.value ?? 0}</span>بار استفاده
</div>
</div>
))
) : (
<div className="text-gray-400 font-medium flex items-center justify-center h-32">داده‌ای موجود نیست</div>
<div className="text-gray-400 font-medium flex items-center justify-center h-32 text-xs">داده‌ای موجود نیست</div>
)}
</div>
</div>