"use client"; import { Activity, BarChart3, Bell, Building2, ChevronLeft, ChevronRight, ChevronsUpDown, CircleDollarSign, CreditCard, Download, FileText, LayoutDashboard, LogOut, MoreHorizontal, Receipt, Search, Settings, User, UserPlus, Users, Zap, } from "lucide-react"; import * as React from "react"; import type { TooltipProps } from "recharts"; import { Area, AreaChart, Bar, BarChart, CartesianGrid, Tooltip, XAxis, YAxis, } from "recharts"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Button } from "@/components/ui/button"; import { type ChartConfig, ChartContainer } from "@/components/ui/chart"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Input } from "@/components/ui/input"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarTrigger, } from "@/components/ui/sidebar"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { TooltipProvider } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; type NavItem = { label: string; icon: React.ComponentType>; href: string; isActive?: boolean; children?: NavItem[]; }; type NavGroup = { title: string; items: NavItem[]; defaultOpen?: boolean; }; type UserData = { name: string; email: string; avatar: string; }; type SidebarData = { logo: { src: string; alt: string; title: string; description: string; href: string; }; navGroups: NavGroup[]; footerGroup: NavGroup; user?: UserData; }; type TimePeriod = "6months" | "year"; type StatCardItem = { title: string; value: number; format: "currency" | "number"; changePercent: number; isPositive: boolean; icon: React.ComponentType>; sparklineData: number[]; }; type OrderStatus = "Processing" | "Shipped" | "Delivered" | "Cancelled"; type Order = { id: string; orderNumber: string; customer: string; total: number; status: OrderStatus; }; type ActivityItem = { title: string; detail: string; minutesAgo: number; }; const currencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", }); const compactCurrencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", notation: "compact", maximumFractionDigits: 1, }); const numberFormatter = new Intl.NumberFormat("fa-IR"); const relativeTimeFormatter = new Intl.RelativeTimeFormat("fa-IR", { numeric: "auto", }); const monthLabel = (monthIndex: number) => new Intl.DateTimeFormat("fa-IR", { month: "short" }).format( new Date(2025, monthIndex, 1), ); const orderStatusLabels: Record = { Processing: "در حال پردازش", Shipped: "ارسال‌شده", Delivered: "تحویل‌شده", Cancelled: "لغوشده", }; const formatRelativeTime = (minutesAgo: number) => { if (minutesAgo < 60) { return relativeTimeFormatter.format(-minutesAgo, "minute"); } const hours = Math.round(minutesAgo / 60); if (hours < 24) { return relativeTimeFormatter.format(-hours, "hour"); } const days = Math.round(hours / 24); return relativeTimeFormatter.format(-days, "day"); }; const mixBase = "var(--background)"; const palette = { primary: "var(--primary)", secondary: { light: `color-mix(in oklch, var(--primary) 75%, ${mixBase})`, dark: `color-mix(in oklch, var(--primary) 85%, ${mixBase})`, }, tertiary: { light: `color-mix(in oklch, var(--primary) 55%, ${mixBase})`, dark: `color-mix(in oklch, var(--primary) 65%, ${mixBase})`, }, quaternary: { light: `color-mix(in oklch, var(--primary) 40%, ${mixBase})`, dark: `color-mix(in oklch, var(--primary) 45%, ${mixBase})`, }, }; const revenueChartConfig = { thisYear: { label: "امسال", color: palette.primary }, prevYear: { label: "سال قبل", theme: palette.secondary }, } satisfies ChartConfig; const sparklinePositiveConfig = { value: { label: "مقدار", theme: { light: "oklch(0.55 0.18 155)", dark: "oklch(0.72 0.15 155)", }, }, } satisfies ChartConfig; const sparklineNegativeConfig = { value: { label: "مقدار", theme: { light: "oklch(0.55 0.18 25)", dark: "oklch(0.72 0.15 25)", }, }, } satisfies ChartConfig; const sidebarData: SidebarData = { logo: { src: "/block-media/shadcnblocks/block/logos/NovaSales-logo.svg", alt: "نوافروش", title: "NovaSales", description: "پلتفرم فروش ابری", href: "https://www.NovaSales", }, navGroups: [ { title: "نمای کلی", defaultOpen: true, items: [ { label: "داشبورد", icon: LayoutDashboard, href: "#", isActive: true, }, { label: "تحلیل فروش", icon: BarChart3, href: "#" }, { label: "فعالیت تیم", icon: Activity, href: "#" }, ], }, { title: "اعضای تیم", defaultOpen: true, items: [ { label: "فهرست معاملات", icon: Users, href: "#", children: [ { label: "همه اعضای تیم", icon: User, href: "#" }, { label: "فضاهای کاری", icon: Building2, href: "#" }, ], }, { label: "دعوت‌ها", icon: UserPlus, href: "#" }, ], }, { title: "صورتحساب", defaultOpen: false, items: [ { label: "اشتراک‌ها", icon: CreditCard, href: "#" }, { label: "مصرف", icon: Zap, href: "#" }, { label: "فاکتورها", icon: Receipt, href: "#" }, ], }, { title: "گزارش‌ها", defaultOpen: false, items: [ { label: "گزارش‌های ذخیره‌شده", icon: FileText, href: "#" }, { label: "خروجی‌ها", icon: Download, href: "#" }, ], }, ], footerGroup: { title: "تنظیمات", items: [{ label: "تنظیمات", icon: Settings, href: "#" }], }, user: { name: "مریم الیس", email: "morgan.ellis@northwind.app", avatar: "/block-media/shadcnblocks/block/avatar-1.webp", }, }; const headerNotificationItems = [ { id: "1", title: "افزایش مصرف", body: "حجم API در فضای کاری شما ۲۴٪ بالاتر از میانگین ۷ روز است.", time: "۶ دقیقه پیش", }, { id: "2", title: "فاکتور پرداخت شد", body: "نورث‌ویند فاکتور INV-2041 را (۱۲٬۸۰۰ دلار) با ACH پرداخت کرد.", time: "۴۲ دقیقه پیش", }, { id: "3", title: "تمدید نزدیک است", body: "۲ قرارداد سالانه ظرف ۱۴ روز آینده تمدید می‌شوند.", time: "۲ ساعت پیش", }, { id: "4", title: "خلاصه هفتگی", body: "خلاصه درآمد و ریزش برای تیم شما آماده است.", time: "دیروز", }, ] as const; const unreadNotificationCount = headerNotificationItems.length; const fullYearData = [ { month: monthLabel(0), thisYear: 42000, prevYear: 38000 }, { month: monthLabel(1), thisYear: 38000, prevYear: 45000 }, { month: monthLabel(2), thisYear: 52000, prevYear: 41000 }, { month: monthLabel(3), thisYear: 45000, prevYear: 48000 }, { month: monthLabel(4), thisYear: 58000, prevYear: 44000 }, { month: monthLabel(5), thisYear: 41000, prevYear: 52000 }, { month: monthLabel(6), thisYear: 55000, prevYear: 47000 }, { month: monthLabel(7), thisYear: 48000, prevYear: 53000 }, { month: monthLabel(8), thisYear: 62000, prevYear: 49000 }, { month: monthLabel(9), thisYear: 54000, prevYear: 58000 }, { month: monthLabel(10), thisYear: 67000, prevYear: 52000 }, { month: monthLabel(11), thisYear: 71000, prevYear: 61000 }, ]; const periodLabels: Record = { "6months": "۶ ماه اخیر", year: "۱۲ ماه", }; function getDataForPeriod(period: TimePeriod) { if (period === "6months") return fullYearData.slice(0, 6); return fullYearData; } const statsCardData: StatCardItem[] = [ { title: "درآمد خالص", value: 82450, format: "currency", changePercent: 20, isPositive: true, icon: CircleDollarSign, sparklineData: [32, 40, 35, 50, 49, 60, 70, 65, 72, 80], }, { title: "حساب‌های فعال", value: 3670, format: "number", changePercent: -4.2, isPositive: false, icon: Users, sparklineData: [45, 42, 48, 40, 38, 36, 34, 35, 33, 32], }, { title: "ARPU", value: 56.2, format: "currency", changePercent: 4.5, isPositive: true, icon: CreditCard, sparklineData: [20, 25, 22, 30, 28, 35, 40, 38, 42, 45], }, ]; const orderStatuses: OrderStatus[] = [ "Processing", "Shipped", "Delivered", "Cancelled", ]; const orders: Order[] = [ { id: "1", orderNumber: "ORD-2024-001", customer: "Sarah Johnson", status: "Delivered", total: 2499.0, }, { id: "2", orderNumber: "ORD-2024-002", customer: "Michael Chen", status: "Shipped", total: 1348.0, }, { id: "3", orderNumber: "ORD-2024-003", customer: "Emma Wilson", status: "Processing", total: 1198.0, }, { id: "4", orderNumber: "ORD-2024-004", customer: "James Rodriguez", status: "Delivered", total: 799.0, }, { id: "5", orderNumber: "ORD-2024-005", customer: "Lisa Park", status: "Cancelled", total: 599.0, }, { id: "6", orderNumber: "ORD-2024-006", customer: "David Kim", status: "Shipped", total: 5498.0, }, { id: "7", orderNumber: "ORD-2024-007", customer: "Anna Martinez", status: "Delivered", total: 1199.0, }, { id: "8", orderNumber: "ORD-2024-008", customer: "Robert Taylor", status: "Processing", total: 1128.0, }, { id: "9", orderNumber: "ORD-2024-009", customer: "Jennifer Lee", status: "Shipped", total: 449.0, }, { id: "10", orderNumber: "ORD-2024-010", customer: "William Brown", status: "Delivered", total: 2199.0, }, { id: "11", orderNumber: "ORD-2024-011", customer: "Sophia Davis", status: "Cancelled", total: 349.0, }, { id: "12", orderNumber: "ORD-2024-012", customer: "Daniel Garcia", status: "Processing", total: 899.0, }, ]; const tableHeadClassName = "text-xs font-medium text-muted-foreground sm:text-sm"; const statusStyles: Record = { Processing: "bg-amber-50 text-amber-700 ring-1 ring-inset ring-amber-600/20 dark:bg-amber-900/30 dark:text-amber-400 dark:ring-amber-400/20", Shipped: "bg-blue-50 text-blue-700 ring-1 ring-inset ring-blue-700/10 dark:bg-blue-900/30 dark:text-blue-400 dark:ring-blue-400/20", Delivered: "bg-emerald-50 text-emerald-700 ring-1 ring-inset ring-emerald-600/20 dark:bg-emerald-900/30 dark:text-emerald-400 dark:ring-emerald-400/20", Cancelled: "bg-red-50 text-red-700 ring-1 ring-inset ring-red-600/10 dark:bg-red-900/30 dark:text-red-400 dark:ring-red-400/20", }; const recentActivity: ActivityItem[] = [ { title: "ثبت‌نام کاربر جدید", detail: "الکس مورگان", minutesAgo: 2 }, { title: "ایجاد فضای کاری", detail: "نورث‌ویند لبز", minutesAgo: 2 }, { title: "دریافت پرداخت", detail: "INV-2044 · ۴٬۲۰۰ دلار", minutesAgo: 2 }, { title: "ارسال فاکتور", detail: "جیمی لی", minutesAgo: 6 }, { title: "ارتقای پلن", detail: "نوح رابرتس", minutesAgo: 12 }, { title: "ثبت اعتبار", detail: "الیویا وایت", minutesAgo: 18 }, { title: "بازنشانی رمز", detail: "ایتن پارکر", minutesAgo: 24 }, { title: "نظر روی گزارش", detail: "سوفیا دیویس", minutesAgo: 32 }, { title: "بستن تیکت پشتیبانی", detail: "مایکل چن", minutesAgo: 45 }, { title: "پردازش تسویه", detail: "اما ویلسون", minutesAgo: 60 }, ]; const SidebarLogo = ({ logo }: { logo: SidebarData["logo"] }) => { return (
{logo.alt}
{logo.title} {logo.description}
); }; const NavMenuItem = ({ item }: { item: NavItem }) => { const Icon = item.icon; const hasChildren = item.children && item.children.length > 0; if (!hasChildren) { return ( ); } return ( {item.children!.map((child) => ( {child.label} ))} ); }; const NavUser = ({ user }: { user: UserData }) => { return ( {user.name .split(" ") .map((n) => n[0]) .join("")}
{user.name} {user.email}
{user.name .split(" ") .map((n) => n[0]) .join("")}
{user.name} {user.email}
); }; const AppSidebar = ({ ...props }: React.ComponentProps) => { return (
{sidebarData.navGroups.map((group) => ( {group.title} {group.items.map((item) => ( ))} ))} {sidebarData.user && }
); }; const DashboardHeader = () => { return (
); }; function CustomTooltip({ active, payload, label, colors, }: any & { colors: { primary: string; secondary: string }; }) { if (!active || !payload?.length) return null; const thisYear = payload.find((p: any) => p.dataKey === "thisYear")?.value || 0; const prevYear = payload.find((p: any) => p.dataKey === "prevYear")?.value || 0; const diff = Number(thisYear) - Number(prevYear); const percentage = prevYear ? Math.round((diff / Number(prevYear)) * 100) : 0; const currentYear = new Date().getFullYear(); return (

{label}، {currentYear.toLocaleString("fa-IR")}

امسال: {currencyFormatter.format(Number(thisYear))}
سال قبل: {currencyFormatter.format(Number(prevYear))}
= 0 ? "text-emerald-500" : "text-red-500", )} > {diff >= 0 ? "+" : ""} {percentage.toLocaleString("fa-IR")}٪ نسبت به سال قبل
); } const RevenueFlowChart = () => { const [period, setPeriod] = React.useState("6months"); React.useEffect(() => { if (typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); const nextPeriod = params.get("period"); if (nextPeriod === "6months" || nextPeriod === "year") { setPeriod(nextPeriod); } }, []); React.useEffect(() => { if (typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); if (period !== "6months") { params.set("period", period); } else { params.delete("period"); } const nextQuery = params.toString(); const nextUrl = nextQuery ? `${window.location.pathname}?${nextQuery}` : window.location.pathname; window.history.replaceState(null, "", nextUrl); }, [period]); const chartData = getDataForPeriod(period); const totalRevenue = chartData.reduce((acc, item) => acc + item.thisYear, 0); return (

{currencyFormatter.format(totalRevenue)}

درآمد کل ({periodLabels[period]})

امسال
سال قبل
بازه زمانی {(Object.keys(periodLabels) as TimePeriod[]).map((key) => ( setPeriod(key)} > {periodLabels[key]} ))} event.preventDefault()} > خروجی داده نمودار event.preventDefault()} > باز کردن در گزارش‌گیری
compactCurrencyFormatter.format(value)} width={40} /> } cursor={{ fillOpacity: 0.05, radius: 4 }} />
); }; const StatsCardsVertical = () => { return (
{statsCardData.map((stat) => { const sparkData = stat.sparklineData.map((v, i) => ({ idx: i, value: v, })); const chartConfig = stat.isPositive ? sparklinePositiveConfig : sparklineNegativeConfig; const sparkColor = stat.isPositive ? "#16a34a" : "#dc2626"; const gradientId = `sparkFill-${stat.title.replace(/\s+/g, "-")}`; return (
{stat.title} {stat.format === "currency" ? currencyFormatter.format(stat.value) : numberFormatter.format(stat.value)}
{ if (!active || !payload?.length) return null; const value = payload[0].value as number; const formatted = stat.format === "currency" ? currencyFormatter.format(value) : numberFormatter.format(value); return (

{formatted}

); }} cursor={{ strokeOpacity: 0.2 }} />
{stat.isPositive ? "+" : ""} {stat.changePercent.toLocaleString("fa-IR", { minimumFractionDigits: 1, maximumFractionDigits: 1, })} ٪ نسبت به ماه قبل
); })}
); }; const RecentTransactionsTable = ({ className }: { className?: string }) => { const [statusFilter, setStatusFilter] = React.useState( "all", ); const [currentPage, setCurrentPage] = React.useState(1); const [isHydrated, setIsHydrated] = React.useState(false); const pageSize = 6; React.useEffect(() => { if (typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); const nextStatus = params.get("status"); if ( nextStatus && (nextStatus === "all" || orderStatuses.includes(nextStatus as OrderStatus)) ) { setStatusFilter(nextStatus as OrderStatus | "all"); } const nextPage = Number(params.get("page")); if (!Number.isNaN(nextPage) && nextPage > 0) { setCurrentPage(nextPage); } setIsHydrated(true); }, []); const filteredOrders = React.useMemo(() => { if (statusFilter === "all") return orders; return orders.filter((order) => order.status === statusFilter); }, [statusFilter]); const totalPages = Math.max(1, Math.ceil(filteredOrders.length / pageSize)); const paginatedOrders = React.useMemo(() => { const startIndex = (currentPage - 1) * pageSize; return filteredOrders.slice(startIndex, startIndex + pageSize); }, [filteredOrders, currentPage, pageSize]); React.useEffect(() => { setCurrentPage(1); }, [statusFilter]); React.useEffect(() => { if (!isHydrated || typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); if (statusFilter !== "all") { params.set("status", statusFilter); } else { params.delete("status"); } if (currentPage > 1) { params.set("page", String(currentPage)); } else { params.delete("page"); } const nextQuery = params.toString(); const nextUrl = nextQuery ? `${window.location.pathname}?${nextQuery}` : window.location.pathname; window.history.replaceState(null, "", nextUrl); }, [statusFilter, currentPage, isHydrated]); const goToPage = (page: number) => { setCurrentPage(Math.max(1, Math.min(page, totalPages))); }; const startRow = filteredOrders.length ? (currentPage - 1) * pageSize + 1 : 0; const endRow = Math.min(currentPage * pageSize, filteredOrders.length); return (

تراکنش‌های اخیر

{filteredOrders.length.toLocaleString("fa-IR")}
فیلتر بر اساس وضعیت setStatusFilter("all")} > همه وضعیت‌ها {orderStatuses.map((status) => ( setStatusFilter(status)} > {orderStatusLabels[status]} ))}
شماره سفارش خریدار مجموع وضعیت {paginatedOrders.length === 0 ? ( تراکنشی یافت نشد. ) : ( paginatedOrders.map((order) => ( {order.orderNumber} {order.customer} {currencyFormatter.format(order.total)} {orderStatusLabels[order.status]} )) )}
{filteredOrders.length === 0 ? "۰" : `${startRow.toLocaleString("fa-IR")}-${endRow.toLocaleString("fa-IR")}`}{" "} از {filteredOrders.length.toLocaleString("fa-IR")}
); }; const RecentActivity = ({ className }: { className?: string }) => { return (

فعالیت تیم‌های اخیر

{recentActivity.map((item) => (
{item.title} {formatRelativeTime(item.minutesAgo)}
{item.detail}
))}
); }; const DashboardContent = () => { return (
); }; const Dashboard3 = ({ className }: { className?: string }) => { return ( رفتن به محتوای اصلی ); }; export { Dashboard3 };