"use client"; import { BarChart3, Bell, Box, ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight, ChevronsUpDown, ClipboardList, Copy, Eye, Filter, Globe, HelpCircle, LayoutDashboard, LogOut, MessageSquare, MoreHorizontal, Package, Pencil, RotateCcw, Search, Settings, Truck, User, Users, X, } from "lucide-react"; import * as React from "react"; import { CartesianGrid, Line, LineChart, 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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; 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; }; navGroups: NavGroup[]; footerGroup: NavGroup; user?: UserData; }; type StatGridItem = { label: string; value: number; format: "currency" | "number" | "percent" | "days" | "compact"; change: number; invertColor: boolean; }; type FulfillmentItem = { order: string; shipped: Date; progress: number; segments: number[]; }; type OrderStatus = "Processing" | "Shipped" | "Delivered" | "Cancelled"; type Order = { id: string; orderNumber: string; customer: string; customerInitials: string; products: string[]; productCount: number; status: OrderStatus; total: number; date: Date; }; const currencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", }); const numberFormatter = new Intl.NumberFormat("fa-IR"); const compactNumberFormatter = new Intl.NumberFormat("fa-IR", { notation: "compact", }); const percentFormatter = new Intl.NumberFormat("fa-IR", { style: "percent", maximumFractionDigits: 1, }); const oneDecimalFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, }); const weekdayFormatter = new Intl.DateTimeFormat("fa-IR", { weekday: "short", }); const monthDayFormatter = new Intl.DateTimeFormat("fa-IR", { month: "short", day: "numeric", }); const dateFormatter = new Intl.DateTimeFormat("fa-IR", { month: "short", day: "numeric", year: "numeric", }); const orderStatusLabels: Record = { Processing: "در حال پردازش", Shipped: "ارسال‌شده", Delivered: "تحویل‌شده", Cancelled: "لغوشده", }; const formatStatValue = (stat: StatGridItem) => { switch (stat.format) { case "currency": return currencyFormatter.format(stat.value); case "percent": return percentFormatter.format(stat.value); case "days": return `${oneDecimalFormatter.format(stat.value)} روز`; case "compact": return compactNumberFormatter.format(stat.value); default: return numberFormatter.format(stat.value); } }; 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 sidebarData: SidebarData = { logo: { src: "/block-media/shadcnblocks/block/logos/NovaSales-logo.svg", alt: "فروشگاه آکمه", title: "ری یو آی Store", description: "فروشگاه آنلاین", }, navGroups: [ { title: "اصلی", defaultOpen: true, items: [ { label: "داشبورد", icon: LayoutDashboard, href: "#", isActive: true, }, { label: "سفارش‌ها", icon: ClipboardList, href: "#" }, { label: "محصولات", icon: Box, href: "#", children: [ { label: "همه محصولات", icon: Package, href: "#" }, { label: "دسته‌بندی‌ها", icon: Package, href: "#" }, { label: "موجودی", icon: Package, href: "#" }, ], }, { label: "مشتریان", icon: Users, href: "#" }, ], }, { title: "تحلیل فروش", defaultOpen: true, items: [ { label: "تحلیل فروش", icon: BarChart3, href: "#" }, { label: "گزارش‌ها", icon: Globe, href: "#" }, ], }, { title: "سایر", defaultOpen: false, items: [ { label: "ارسال", icon: Truck, href: "#" }, { label: "پیام‌ها", icon: MessageSquare, href: "#" }, { label: "مرجوعی‌ها", icon: RotateCcw, href: "#" }, ], }, ], footerGroup: { title: "تنظیمات", items: [{ label: "تنظیمات", icon: Settings, href: "#" }], }, user: { name: "علی رضایی", email: "john@acme.store", avatar: "/block-media/shadcnblocks/block/avatar-5.webp", }, }; const statsGridData: StatGridItem[] = [ { label: "درآمد کل", value: 1_800_000, format: "currency", change: 12.0, invertColor: false, }, { label: "میانگین تکمیل", value: 2.4, format: "days", change: -5.0, invertColor: false, }, { label: "سفارش‌ها", value: 9420, format: "number", change: 18.0, invertColor: false, }, { label: "نرخ تبدیل", value: 0.042, format: "percent", change: 1.2, invertColor: false, }, { label: "نرخ مرجوعی", value: 0.031, format: "percent", change: -11.0, invertColor: true, }, { label: "بازدید صفحات", value: 184_000, format: "compact", change: 22.0, invertColor: false, }, ]; const categoryWeekData = [ { day: weekdayFormatter.format(new Date(2025, 0, 6)), electronics: 180, clothing: 220, homeGarden: 280, sports: 350, }, { day: weekdayFormatter.format(new Date(2025, 0, 7)), electronics: 420, clothing: 550, homeGarden: 380, sports: 280, }, { day: weekdayFormatter.format(new Date(2025, 0, 8)), electronics: 280, clothing: 380, homeGarden: 520, sports: 450, }, { day: weekdayFormatter.format(new Date(2025, 0, 9)), electronics: 550, clothing: 280, homeGarden: 420, sports: 620, }, { day: weekdayFormatter.format(new Date(2025, 0, 10)), electronics: 323, clothing: 729, homeGarden: 506, sports: 490, }, { day: weekdayFormatter.format(new Date(2025, 0, 11)), electronics: 480, clothing: 420, homeGarden: 280, sports: 380, }, { day: weekdayFormatter.format(new Date(2025, 0, 12)), electronics: 220, clothing: 550, homeGarden: 450, sports: 320, }, ]; const categoryMonthData = [ { day: monthDayFormatter.format(new Date(2025, 0, 1)), electronics: 180, clothing: 220, homeGarden: 280, sports: 350, }, { day: monthDayFormatter.format(new Date(2025, 0, 5)), electronics: 420, clothing: 550, homeGarden: 380, sports: 280, }, { day: monthDayFormatter.format(new Date(2025, 0, 9)), electronics: 280, clothing: 380, homeGarden: 520, sports: 450, }, { day: monthDayFormatter.format(new Date(2025, 0, 13)), electronics: 550, clothing: 280, homeGarden: 420, sports: 620, }, { day: monthDayFormatter.format(new Date(2025, 0, 15)), electronics: 323, clothing: 729, homeGarden: 506, sports: 490, }, { day: monthDayFormatter.format(new Date(2025, 0, 17)), electronics: 480, clothing: 420, homeGarden: 280, sports: 380, }, { day: monthDayFormatter.format(new Date(2025, 0, 21)), electronics: 220, clothing: 550, homeGarden: 450, sports: 320, }, { day: monthDayFormatter.format(new Date(2025, 0, 25)), electronics: 380, clothing: 320, homeGarden: 580, sports: 480, }, { day: monthDayFormatter.format(new Date(2025, 0, 30)), electronics: 520, clothing: 450, homeGarden: 350, sports: 420, }, ]; const categoryChartConfig = { electronics: { label: "الکترونیک", color: palette.primary }, clothing: { label: "پوشاک", theme: palette.secondary, }, homeGarden: { label: "خانه و باغ", theme: palette.tertiary, }, sports: { label: "ورزشی", theme: palette.quaternary, }, } satisfies ChartConfig; function getCategoryColor( config: (typeof categoryChartConfig)[keyof typeof categoryChartConfig], ): string { if ("color" in config && config.color) return config.color; if ("theme" in config && config.theme) { const theme = config.theme as { light: string; dark: string }; return theme.light; } return "var(--primary)"; } const fulfillmentData: FulfillmentItem[] = [ { order: "ORD-4821", shipped: new Date(2025, 0, 27), progress: 92, segments: [ 0.9, 0.7, 1.0, 0.8, 0.6, 0.9, 1.0, 0.7, 0.5, 0.8, 0.9, 1.0, 0.6, 0.7, 0.8, 0.9, 1.0, 0.5, 0.7, 0.8, 0.9, 0.6, 1.0, 0.8, 0.7, 0.3, 0.2, 0.1, 0.1, 0.1, ], }, { order: "ORD-4819", shipped: new Date(2025, 0, 26), progress: 78, segments: [ 0.8, 0.6, 0.9, 0.7, 1.0, 0.5, 0.8, 0.9, 0.6, 0.7, 1.0, 0.8, 0.5, 0.9, 0.7, 0.6, 0.8, 1.0, 0.7, 0.5, 0.2, 0.1, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4815", shipped: new Date(2025, 0, 25), progress: 100, segments: [ 1.0, 0.9, 0.8, 1.0, 0.7, 0.9, 1.0, 0.8, 0.6, 0.9, 1.0, 0.7, 0.8, 0.9, 1.0, 0.6, 0.8, 0.9, 1.0, 0.7, 0.9, 0.8, 1.0, 0.6, 0.9, 0.7, 1.0, 0.8, 0.9, 1.0, ], }, { order: "ORD-4812", shipped: new Date(2025, 0, 24), progress: 65, segments: [ 0.9, 1.0, 0.7, 0.8, 0.6, 0.9, 0.5, 0.8, 1.0, 0.7, 0.9, 0.6, 0.8, 0.5, 0.7, 1.0, 0.6, 0.9, 0.8, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4808", shipped: new Date(2025, 0, 23), progress: 43, segments: [ 0.8, 0.7, 1.0, 0.6, 0.9, 0.8, 0.5, 0.7, 1.0, 0.9, 0.6, 0.8, 0.7, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4805", shipped: new Date(2025, 0, 22), progress: 100, segments: [ 0.9, 0.8, 1.0, 0.7, 0.9, 0.6, 1.0, 0.8, 0.7, 0.9, 1.0, 0.8, 0.6, 0.9, 0.7, 1.0, 0.8, 0.9, 0.7, 1.0, 0.8, 0.9, 0.6, 1.0, 0.7, 0.8, 0.9, 1.0, 0.8, 0.9, ], }, { order: "ORD-4801", shipped: new Date(2025, 0, 21), progress: 88, segments: [ 1.0, 0.8, 0.7, 0.9, 0.6, 1.0, 0.8, 0.5, 0.9, 0.7, 1.0, 0.8, 0.6, 0.9, 0.7, 0.8, 1.0, 0.6, 0.5, 0.3, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4798", shipped: new Date(2025, 0, 20), progress: 55, segments: [ 0.7, 0.9, 1.0, 0.6, 0.8, 0.9, 0.7, 1.0, 0.5, 0.8, 0.6, 0.9, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4794", shipped: new Date(2025, 0, 19), progress: 100, segments: [ 0.8, 1.0, 0.9, 0.7, 0.8, 1.0, 0.6, 0.9, 0.8, 1.0, 0.7, 0.9, 0.8, 1.0, 0.6, 0.9, 0.7, 1.0, 0.8, 0.9, 0.7, 1.0, 0.8, 0.6, 0.9, 1.0, 0.7, 0.8, 0.9, 1.0, ], }, { order: "ORD-4790", shipped: new Date(2025, 0, 18), progress: 71, segments: [ 0.9, 0.6, 0.8, 1.0, 0.7, 0.9, 0.5, 0.8, 1.0, 0.6, 0.9, 0.7, 0.8, 0.5, 0.3, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4786", shipped: new Date(2025, 0, 17), progress: 35, segments: [ 1.0, 0.8, 0.9, 0.7, 0.6, 0.8, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], }, { order: "ORD-4782", shipped: new Date(2025, 0, 16), progress: 96, segments: [ 0.8, 0.9, 1.0, 0.7, 0.8, 0.9, 1.0, 0.6, 0.8, 0.9, 1.0, 0.7, 0.9, 0.8, 1.0, 0.6, 0.9, 0.7, 1.0, 0.8, 0.9, 0.6, 1.0, 0.8, 0.7, 0.9, 1.0, 0.8, 0.3, 0.1, ], }, ]; const orderStatuses: OrderStatus[] = [ "Processing", "Shipped", "Delivered", "Cancelled", ]; const orders: Order[] = [ { id: "1", orderNumber: "ORD-2024-001", customer: "Sarah Johnson", customerInitials: "SJ", products: ["MacBook Pro 14", "Magic Mouse"], productCount: 2, status: "Delivered", total: 2499.0, date: new Date(2024, 0, 28), }, { id: "2", orderNumber: "ORD-2024-002", customer: "Michael Chen", customerInitials: "MC", products: ["iPhone 15 Pro", "AirPods Pro"], productCount: 2, status: "Shipped", total: 1348.0, date: new Date(2024, 0, 27), }, { id: "3", orderNumber: "ORD-2024-003", customer: "Emma Wilson", customerInitials: "EW", products: ["iPad Air", "Apple Pencil", "Smart Keyboard"], productCount: 3, status: "Processing", total: 1198.0, date: new Date(2024, 0, 27), }, { id: "4", orderNumber: "ORD-2024-004", customer: "James Rodriguez", customerInitials: "JR", products: ["Apple Watch Ultra"], productCount: 1, status: "Delivered", total: 799.0, date: new Date(2024, 0, 26), }, { id: "5", orderNumber: "ORD-2024-005", customer: "Lisa Park", customerInitials: "LP", products: ["Mac Mini M2"], productCount: 1, status: "Cancelled", total: 599.0, date: new Date(2024, 0, 26), }, { id: "6", orderNumber: "ORD-2024-006", customer: "David Kim", customerInitials: "DK", products: ["Studio Display", "Mac Studio"], productCount: 2, status: "Shipped", total: 5498.0, date: new Date(2024, 0, 25), }, { id: "7", orderNumber: "ORD-2024-007", customer: "Anna Martinez", customerInitials: "AM", products: ["MacBook Air M2"], productCount: 1, status: "Delivered", total: 1199.0, date: new Date(2024, 0, 25), }, { id: "8", orderNumber: "ORD-2024-008", customer: "Robert Taylor", customerInitials: "RT", products: ["iPhone 15", "MagSafe Charger"], productCount: 2, status: "Processing", total: 878.0, date: new Date(2024, 0, 24), }, { id: "9", orderNumber: "ORD-2024-009", customer: "Jennifer Lee", customerInitials: "JL", products: ["AirPods Max"], productCount: 1, status: "Shipped", total: 549.0, date: new Date(2024, 0, 24), }, { id: "10", orderNumber: "ORD-2024-010", customer: "William Brown", customerInitials: "WB", products: ["iPad Pro 12.9", "Magic Keyboard"], productCount: 2, status: "Delivered", total: 1648.0, date: new Date(2024, 0, 23), }, { id: "11", orderNumber: "ORD-2024-011", customer: "Sophia Davis", customerInitials: "SD", products: ["MacBook Pro 16"], productCount: 1, status: "Processing", total: 2499.0, date: new Date(2024, 0, 23), }, { id: "12", orderNumber: "ORD-2024-012", customer: "Daniel Garcia", customerInitials: "DG", products: ["Apple TV 4K", "HomePod mini"], productCount: 2, status: "Cancelled", total: 278.0, date: new Date(2024, 0, 22), }, { id: "13", orderNumber: "ORD-2024-013", customer: "Olivia White", customerInitials: "OW", products: ["iPhone 15 Pro Max"], productCount: 1, status: "Delivered", total: 1199.0, date: new Date(2024, 0, 22), }, { id: "14", orderNumber: "ORD-2024-014", customer: "Thomas Anderson", customerInitials: "TA", products: ["Mac Pro", "Pro Display XDR"], productCount: 2, status: "Shipped", total: 12498.0, date: new Date(2024, 0, 21), }, { id: "15", orderNumber: "ORD-2024-015", customer: "Emily Thompson", customerInitials: "ET", products: ["iPad mini", "Apple Pencil"], productCount: 2, status: "Delivered", total: 648.0, date: new Date(2024, 0, 21), }, { id: "16", orderNumber: "ORD-2024-016", customer: "Christopher Moore", customerInitials: "CM", products: ["AirPods Pro 2"], productCount: 1, status: "Processing", total: 249.0, date: new Date(2024, 0, 20), }, { id: "17", orderNumber: "ORD-2024-017", customer: "Isabella Jackson", customerInitials: "IJ", products: ["Apple Watch Series 9"], productCount: 1, status: "Shipped", total: 399.0, date: new Date(2024, 0, 20), }, { id: "18", orderNumber: "ORD-2024-018", customer: "Matthew Harris", customerInitials: "MH", products: ["MacBook Air 15"], productCount: 1, status: "Delivered", total: 1299.0, date: new Date(2024, 0, 19), }, { id: "19", orderNumber: "ORD-2024-019", customer: "Ava Clark", customerInitials: "AC", products: ["iPhone SE", "EarPods"], productCount: 2, status: "Cancelled", total: 448.0, date: new Date(2024, 0, 19), }, { id: "20", orderNumber: "ORD-2024-020", customer: "Joshua Lewis", customerInitials: "JL", products: ["Mac Mini M2 Pro"], productCount: 1, status: "Processing", total: 1299.0, date: new Date(2024, 0, 18), }, ]; const PAGE_SIZE_OPTIONS = [10, 25, 50]; function readRecentOrdersTableState() { const defaults = { searchQuery: "", statusFilter: "all", currentPage: 1, pageSize: 10, }; if (typeof window === "undefined") return defaults; const params = new URLSearchParams(window.location.search); const statusParam = params.get("status"); const pageParam = Number.parseInt(params.get("page") ?? "", 10); const pageSizeParam = Number.parseInt(params.get("pageSize") ?? "", 10); return { searchQuery: params.get("q") ?? "", statusFilter: statusParam && orderStatuses.includes(statusParam as OrderStatus) ? statusParam : "all", currentPage: Number.isFinite(pageParam) && pageParam > 0 ? pageParam : 1, pageSize: PAGE_SIZE_OPTIONS.includes(pageSizeParam) ? pageSizeParam : 10, }; } 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 (
); }; const StatsCardsGrid = () => { return (
{statsGridData.map((stat) => { const isPositive = stat.invertColor ? stat.change < 0 : stat.change > 0; return (
{formatStatValue(stat)}
{stat.label} {stat.change > 0 ? "+" : ""} {stat.change.toLocaleString("fa-IR", { minimumFractionDigits: 1, maximumFractionDigits: 1, })} ٪
); })}
); }; const CategoryPerformanceChart = () => { const subscribeToCategoryTab = React.useCallback((onStoreChange: () => void) => { if (typeof window === "undefined") return () => {}; window.addEventListener("popstate", onStoreChange); return () => window.removeEventListener("popstate", onStoreChange); }, []); const readCategoryTabParam = React.useCallback((): "week" | "month" => { if (typeof window === "undefined") return "week"; const nextTab = new URLSearchParams(window.location.search).get( "categoryTab", ); return nextTab === "month" ? "month" : "week"; }, []); const tab = React.useSyncExternalStore( subscribeToCategoryTab, readCategoryTabParam, () => "week" as const, ); const setTab = React.useCallback((next: "week" | "month") => { if (typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); if (next !== "week") { params.set("categoryTab", next); } else { params.delete("categoryTab"); } const nextQuery = params.toString(); const nextUrl = nextQuery ? `${window.location.pathname}?${nextQuery}` : window.location.pathname; window.history.replaceState(null, "", nextUrl); window.dispatchEvent(new PopStateEvent("popstate")); }, []); const chartData = tab === "week" ? categoryWeekData : categoryMonthData; const totalOrders = chartData.reduce( (acc, item) => acc + item.electronics + item.clothing + item.homeGarden + item.sports, 0, ); return (

عملکرد دسته‌ها

{numberFormatter.format(totalOrders)}
{Object.entries(categoryChartConfig).map(([key, config]) => (
))}
{ if (!active || !payload?.length) return null; return (

{label}

{payload.map((entry) => (
{categoryChartConfig[ entry.dataKey as keyof typeof categoryChartConfig ]?.label ?? entry.dataKey} : {numberFormatter.format(Number(entry.value))}
))}
); }} />
); }; const FulfillmentPanel = () => { return (

تکمیل سفارش

خروجی جدول مشاهده همه سفارش‌ها
سفارش ارسال وضعیت تحویل٪
{fulfillmentData.map((row) => (
{row.order} {dateFormatter.format(row.shipped)}
{row.segments.slice(0, 15).map((opacity, i) => { const filled = i < Math.round((row.progress / 100) * 15); return (
); })}
{row.progress.toLocaleString("fa-IR")}
))}
); }; const tableHeadClass = "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 RecentOrdersTable = () => { const [searchQuery, setSearchQuery] = React.useState( () => readRecentOrdersTableState().searchQuery, ); const [statusFilter, setStatusFilter] = React.useState( () => readRecentOrdersTableState().statusFilter, ); const [currentPage, setCurrentPage] = React.useState( () => readRecentOrdersTableState().currentPage, ); const [pageSize, setPageSize] = React.useState( () => readRecentOrdersTableState().pageSize, ); const isHydrated = typeof window !== "undefined"; const skipNextReset = React.useRef(true); const hasActiveFilters = statusFilter !== "all"; const clearFilters = () => { setStatusFilter("all"); }; const filteredOrders = React.useMemo(() => { return orders.filter((order) => { const matchesSearch = order.orderNumber.toLowerCase().includes(searchQuery.toLowerCase()) || order.customer.toLowerCase().includes(searchQuery.toLowerCase()); const matchesStatus = statusFilter === "all" || order.status === statusFilter; return matchesSearch && matchesStatus; }); }, [searchQuery, statusFilter]); const totalPages = Math.ceil(filteredOrders.length / pageSize); const paginatedOrders = React.useMemo(() => { const startIndex = (currentPage - 1) * pageSize; const endIndex = startIndex + pageSize; return filteredOrders.slice(startIndex, endIndex); }, [filteredOrders, currentPage, pageSize]); React.useEffect(() => { if (!isHydrated) return; if (skipNextReset.current) { skipNextReset.current = false; return; } setCurrentPage(1); }, [searchQuery, statusFilter, pageSize, isHydrated]); React.useEffect(() => { if (!isHydrated) return; if (typeof window === "undefined") return; const params = new URLSearchParams(window.location.search); if (searchQuery) { params.set("q", searchQuery); } else { params.delete("q"); } if (statusFilter !== "all") { params.set("status", statusFilter); } else { params.delete("status"); } if (currentPage > 1) { params.set("page", String(currentPage)); } else { params.delete("page"); } if (pageSize !== PAGE_SIZE_OPTIONS[0]) { params.set("pageSize", String(pageSize)); } else { params.delete("pageSize"); } const nextQuery = params.toString(); const nextUrl = nextQuery ? `${window.location.pathname}?${nextQuery}` : window.location.pathname; window.history.replaceState(null, "", nextUrl); }, [searchQuery, statusFilter, currentPage, pageSize, isHydrated]); const goToPage = (page: number) => { setCurrentPage(Math.max(1, Math.min(page, totalPages))); }; return (

سفارش‌های اخیر

{filteredOrders.length.toLocaleString("fa-IR")}
فیلتر بر اساس وضعیت setStatusFilter("all")} > همه وضعیت‌ها {orderStatuses.map((status) => ( setStatusFilter(status)} > {orderStatusLabels[status]} ))} {hasActiveFilters && ( <> )}
{hasActiveFilters && (
فیلترها: {statusFilter !== "all" && ( )}
)}
# سفارش مشتری وضعیت مجموع تاریخ {paginatedOrders.length === 0 ? ( سفارشی با این فیلترها یافت نشد. ) : ( paginatedOrders.map((order, index) => ( {((currentPage - 1) * pageSize + index + 1).toLocaleString( "fa-IR", )}
{order.orderNumber} {order.productCount.toLocaleString("fa-IR")} قلم
{order.customerInitials} {order.customer}
{orderStatusLabels[order.status]} {currencyFormatter.format(order.total)} {dateFormatter.format(order.date)} { event.preventDefault(); if (typeof window === "undefined") return; window.confirm( "این سفارش لغو شود؟ این عمل قابل بازگشت نیست.", ); }} >
)) )}
ردیف در هر صفحه: {filteredOrders.length === 0 ? "۰" : `${((currentPage - 1) * pageSize + 1).toLocaleString("fa-IR")}-${Math.min( currentPage * pageSize, filteredOrders.length, ).toLocaleString("fa-IR")}`}{" "} از {filteredOrders.length.toLocaleString("fa-IR")}
{Array.from({ length: Math.min(totalPages, 5) }, (_, i) => { let pageNum: number; if (totalPages <= 5) { pageNum = i + 1; } else if (currentPage <= 3) { pageNum = i + 1; } else if (currentPage >= totalPages - 2) { pageNum = totalPages - 4 + i; } else { pageNum = currentPage - 2 + i; } return ( ); })}
); }; const DashboardContent = () => { return (
); }; const Dashboard7 = ({ className }: { className?: string }) => { return ( رفتن به محتوای اصلی ); }; export { Dashboard7 };