"use client"; import { useState } from "react"; import { Area, AreaChart, Bar, BarChart, CartesianGrid, Line, LineChart, 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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { cn } from "@/lib/utils"; interface ChartGroup9Props { className?: string; } const dateLabel = (monthIndex: number, day: number) => new Intl.DateTimeFormat("fa-IR", { month: "short", day: "numeric", }).format(new Date(2025, monthIndex, day)); 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 numberFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 0, }); const compactNumberFormatter = new Intl.NumberFormat("fa-IR", { notation: "compact", maximumFractionDigits: 1, }); const oneDecimalFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, minimumFractionDigits: 1, }); const formatPercent = (value: number) => `${oneDecimalFormatter.format(value)}٪`; const datePoints: [number, number][] = [ [0, 1], [0, 8], [0, 15], [0, 22], [0, 29], [1, 5], [1, 12], [1, 19], ]; const buildSeries = (values: number[]) => datePoints.map(([month, day], index) => ({ date: dateLabel(month, day), value: values[index], })); const revenueData = buildSeries([ 4200, 5100, 4800, 6200, 7100, 5400, 6800, 7500, ]); const ordersData = buildSeries([42, 51, 48, 62, 71, 54, 68, 75]); const visitorsData = buildSeries([ 1200, 1450, 1380, 1720, 1980, 1540, 1850, 2100, ]); const totalRevenue = revenueData.reduce((sum, d) => sum + d.value, 0); const totalOrders = ordersData.reduce((sum, d) => sum + d.value, 0); const metricOptions = [ { value: "revenue", label: "درآمد" }, { value: "orders", label: "سفارش‌ها" }, { value: "visitors", label: "بازدیدکنندگان" }, ] as const; const revenueConfig = { value: { label: "درآمد", color: "var(--chart-1)" }, } satisfies ChartConfig; const ordersConfig = { value: { label: "سفارش‌ها", color: "var(--chart-2)" }, } satisfies ChartConfig; const visitorsConfig = { value: { label: "بازدیدکنندگان", color: "var(--chart-3)" }, } satisfies ChartConfig; const ChartGroup9 = ({ className }: ChartGroup9Props) => { const [metric, setMetric] = useState("revenue"); return (
مرور شاخص‌ها مشاهده شاخص‌های کلیدی در طول زمان

مجموع درآمد

{currencyFormatter.format(totalRevenue)}

مجموع سفارش‌ها

{numberFormatter.format(totalOrders)}

میانگین ارزش سفارش

{currencyFormatter.format( Math.round(totalRevenue / totalOrders), )}

نرخ تبدیل

{formatPercent(3.2)}

{metric === "revenue" && ( compactCurrencyFormatter.format(Number(v)) } /> currencyFormatter.format(Number(value)) } /> } cursor={{ stroke: "var(--border)", strokeDasharray: "4 4" }} /> )} {metric === "orders" && ( compactNumberFormatter.format(Number(v)) } /> numberFormatter.format(Number(value)) } /> } cursor={{ fillOpacity: 0.05 }} /> )} {metric === "visitors" && ( compactNumberFormatter.format(Number(v)) } /> numberFormatter.format(Number(value)) } /> } cursor={{ stroke: "var(--border)", strokeDasharray: "4 4" }} /> )}
); }; export { ChartGroup9 };