"use client"; import { TrendingDown, TrendingUp } from "lucide-react"; import { Area, AreaChart, CartesianGrid, Line, LineChart, ResponsiveContainer, XAxis, YAxis, } from "recharts"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { type ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent, } from "@/components/ui/chart"; import { cn } from "@/lib/utils"; interface Stat { title: string; value: string; change: number; sparklineData: { day: string; value: number }[]; } interface ChartGroup3Props { stats?: Stat[]; className?: string; } const monthLabel = (monthIndex: number) => new Intl.DateTimeFormat("fa-IR", { month: "short" }).format( new Date(2025, monthIndex, 1), ); const weekdayFormatter = new Intl.DateTimeFormat("fa-IR", { weekday: "short", }); const weekdaySparkline = (values: number[]) => values.map((value, index) => ({ day: weekdayFormatter.format(new Date(2025, 0, 6 + index)), value, })); const currencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", minimumFractionDigits: 0, maximumFractionDigits: 0, }); const compactCurrencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", notation: "compact", minimumFractionDigits: 0, maximumFractionDigits: 1, }); const oneDecimalFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, minimumFractionDigits: 1, }); const percentChangeFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, minimumFractionDigits: 1, signDisplay: "exceptZero", }); const formatPercent = (value: number) => `${oneDecimalFormatter.format(value)}٪`; const defaultStats: Stat[] = [ { title: "مجموع درآمد", value: currencyFormatter.format(45231), change: 20.1, sparklineData: weekdaySparkline([6200, 5800, 7100, 6900, 8200, 5400, 5631]), }, { title: "میانگین ارزش سفارش", value: currencyFormatter.format(142), change: 8.5, sparklineData: weekdaySparkline([128, 135, 142, 138, 155, 148, 142]), }, { title: "نرخ تبدیل", value: formatPercent(3.2), change: -2.4, sparklineData: weekdaySparkline([3.8, 3.5, 3.4, 3.6, 3.1, 2.9, 3.2]), }, ]; const chartData = [ { month: monthLabel(0), value: 18600 }, { month: monthLabel(1), value: 30500 }, { month: monthLabel(2), value: 23700 }, { month: monthLabel(3), value: 27300 }, { month: monthLabel(4), value: 20900 }, { month: monthLabel(5), value: 31400 }, ]; const chartConfig = { value: { label: "درآمد", color: "var(--chart-1)" }, } satisfies ChartConfig; const ChartGroup3 = ({ stats = defaultStats, className }: ChartGroup3Props) => { return (
روند درآمد درآمد ماهانه در طول زمان compactCurrencyFormatter.format(Number(v)) } /> currencyFormatter.format(Number(value)) } /> } cursor={{ stroke: "var(--border)", strokeDasharray: "4 4" }} />
{stats.map((stat, index) => { const isPositive = stat.change >= 0; const sparklineColor = isPositive ? "#22c55e" : "#ef4444"; return ( ۷ روز گذشته
{stat.title}
{stat.value}
{isPositive ? (
); })}
); }; export { ChartGroup3 };