"use client"; import { ArrowUpRight, ChevronRight, Package, RotateCcw, Search, Star, Truck, } from "lucide-react"; import { useState } from "react"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { cn } from "@/lib/utils"; type OrderStatus = "processing" | "shipped" | "delivered" | "returned"; interface OrderItem { id: string; name: string; image: string; price: number; size: string; color: string; quantity: number; canReturn?: boolean; /** ISO 8601 date (YYYY-MM-DD) */ returnByDate?: string; } interface Order { id: string; orderNumber: string; /** ISO 8601 date (YYYY-MM-DD) */ orderDate: string; status: OrderStatus; total: number; items: OrderItem[]; /** ISO 8601 date(s) for expected delivery */ deliveryDateFrom?: string; deliveryDateTo?: string; trackingUrl?: string; } const DEFAULT_ORDERS: Order[] = [ { id: "1", orderNumber: "WEB-9847562", orderDate: "2024-12-12", status: "shipped", total: 1279700.0, deliveryDateFrom: "2024-12-18", deliveryDateTo: "2024-12-20", trackingUrl: "#", items: [ { id: "1a", name: "هودی پنبه‌ای اورسایز", image: "/block-media/shadcnblocks/block/ecommerce/clothes/black-hoodie-against-light-background.png", price: 499900.0, size: "L", color: "مشکی", quantity: 1, }, { id: "1b", name: "جین راسته فاق بلند", image: "/block-media/shadcnblocks/block/ecommerce/clothes/pexels-jay-soundo-2148060180-30624171-1.png", price: 599900.0, size: "32", color: "آبی متوسط", quantity: 1, }, { id: "1c", name: "تی‌شرت یقه گرد ساده", image: "/block-media/shadcnblocks/block/ecommerce/clothes/minimalist-tank-top-flatlay.png", price: 179900.0, size: "M", color: "سفید", quantity: 1, }, ], }, { id: "2", orderNumber: "WEB-9841203", orderDate: "2024-12-05", status: "delivered", total: 899800.0, deliveryDateFrom: "2024-12-10", items: [ { id: "2a", name: "کیف دوشی چرمی", image: "/block-media/shadcnblocks/block/ecommerce/clothes/maroon-leather-handbag.png", price: 699900.0, size: "یک سایز", color: "زرشکی", quantity: 1, canReturn: true, returnByDate: "2025-01-10", }, { id: "2b", name: "کلاه بافتنی", image: "/block-media/shadcnblocks/block/ecommerce/accessories/Classic-Black-Fedora-Hat-1.png", price: 199900.0, size: "یک سایز", color: "ذغالی", quantity: 1, canReturn: true, returnByDate: "2025-01-10", }, ], }, { id: "3", orderNumber: "WEB-9835678", orderDate: "2024-11-28", status: "delivered", total: 1599700.0, deliveryDateFrom: "2024-12-03", items: [ { id: "3a", name: "پالتو پشمی مخلوط", image: "/block-media/shadcnblocks/block/ecommerce/clothes/Young-Man-in-White-Hoodie-1.png", price: 129990.0, size: "M", color: "شتری", quantity: 1, canReturn: false, }, { id: "3b", name: "شال کشمیر", image: "/block-media/shadcnblocks/block/ecommerce/clothes/elegant-peach-scarf.png", price: 299800.0, size: "یک سایز", color: "کرم جو دوسر", quantity: 2, canReturn: false, }, ], }, { id: "4", orderNumber: "WEB-9828901", orderDate: "2024-11-15", status: "returned", total: 459900.0, items: [ { id: "4a", name: "شلوار چینو اسلیم", image: "/block-media/shadcnblocks/block/ecommerce/clothes/pexels-jay-soundo-2148060180-30624171-2.png", price: 459900.0, size: "30", color: "خاکی", quantity: 1, }, ], }, ]; const formatCurrency = (value: number) => `${value.toLocaleString("fa-IR")} ریال`; const dateFormatter = new Intl.DateTimeFormat("fa-IR", { year: "numeric", month: "long", day: "numeric", }); const formatOrderDate = (isoDate: string) => dateFormatter.format(new Date(isoDate + "T12:00:00")); const formatDeliveryEstimate = (from: string, to?: string) => { if (to && to !== from) { return `${formatOrderDate(from)} تا ${formatOrderDate(to)}`; } return formatOrderDate(from); }; const statusConfig: Record< OrderStatus, { label: string; color: string; dotColor: string } > = { processing: { label: "در حال پردازش", color: "text-amber-600", dotColor: "bg-amber-500", }, shipped: { label: "در مسیر تحویل", color: "text-blue-600", dotColor: "bg-blue-500", }, delivered: { label: "تحویل‌شده", color: "text-emerald-600", dotColor: "bg-emerald-500", }, returned: { label: "مرجوع‌شده", color: "text-muted-foreground", dotColor: "bg-muted-foreground", }, }; const tabLabels: Record = { all: "همه سفارش‌ها", active: "در حال انجام", delivered: "تحویل‌شده", returned: "مرجوعات", }; interface OrderHistory5Props { orders?: Order[]; className?: string; } const OrderHistory5 = ({ orders = DEFAULT_ORDERS, className, }: OrderHistory5Props) => { const [activeTab, setActiveTab] = useState("all"); const [searchQuery, setSearchQuery] = useState(""); const filteredOrders = orders.filter((order) => { const matchesTab = activeTab === "all" || (activeTab === "active" && (order.status === "processing" || order.status === "shipped")) || order.status === activeTab; const matchesSearch = searchQuery === "" || order.orderNumber.toLowerCase().includes(searchQuery.toLowerCase()) || order.items.some((item) => item.name.toLowerCase().includes(searchQuery.toLowerCase()), ); return matchesTab && matchesSearch; }); return (

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

پیگیری، بازگشت یا خرید مجدد اقلام

{tabLabels.all} {tabLabels.active} {tabLabels.delivered} {tabLabels.returned}
{filteredOrders.map((order) => { const status = statusConfig[order.status]; return (

تاریخ ثبت سفارش

{formatOrderDate(order.orderDate)}

شماره سفارش

{order.orderNumber}

مجموع

{formatCurrency(order.total)}

{order.status === "shipped" && order.deliveryDateFrom && (

تحویل:{" "} {formatDeliveryEstimate( order.deliveryDateFrom, order.deliveryDateTo, )}

بسته شما در راه است

{order.trackingUrl && ( )}
)} {order.items.map((item, index) => (
{index > 0 && }
{item.name}

{item.name}

{item.color} ·{" "} {item.size} {item.quantity > 1 && ( <> {" "} · تعداد:{" "} {item.quantity.toLocaleString("fa-IR")} )}

{formatCurrency(item.price)}

{order.status === "delivered" && ( <> {item.canReturn && ( )} )} {order.status === "shipped" && ( )}
{item.canReturn && item.returnByDate && (

امکان بازگشت تا{" "} {formatOrderDate(item.returnByDate)}

)}
))}
); })} {filteredOrders.length === 0 && (

سفارشی یافت نشد

{searchQuery ? `نتیجه‌ای برای «${searchQuery}» یافت نشد.` : "هنوز سفارشی ثبت نکرده‌اید."}

)}
); }; export { OrderHistory5 };