"use client"; import { ArrowUpDown, Check, Heart, Share2, ShoppingCart, X, } from "lucide-react"; import { useState } from "react"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Separator } from "@/components/ui/separator"; import { cn } from "@/lib/utils"; interface WishlistItem { id: string; name: string; image: string; price: number; originalPrice?: number; inStock: boolean; dateAdded: string; category: string; } const DEFAULT_ITEMS: WishlistItem[] = [ { id: "1", name: "هدفون بی‌سیم نویزکنسل", image: "/block-media/shadcnblocks/block/ecommerce/electronics/Modern-White-Headphones-1.png", price: 50000, originalPrice: 60000, inStock: true, dateAdded: "2024-12-10", category: "لوازم الکترونیکی", }, { id: "2", name: "کیف چرمی کراس‌بادی", image: "/block-media/shadcnblocks/block/ecommerce/clothes/maroon-leather-handbag.png", price: 180000, inStock: true, dateAdded: "2024-12-08", category: "اکسسوری", }, { id: "3", name: "پالتو پشمی کلاسیک", image: "/block-media/shadcnblocks/block/ecommerce/clothes/Young-Man-in-White-Hoodie-1.png", price: 1200000, inStock: false, dateAdded: "2024-12-05", category: "پوشاک", }, { id: "4", name: "گوشواره حلقه‌ای طلا", image: "/block-media/shadcnblocks/block/ecommerce/accessories/Elegant-Gold-Earrings-1.png", price: 8000000, originalPrice: 9000000, inStock: true, dateAdded: "2024-12-02", category: "زیورآلات", }, { id: "5", name: "هودی پنبه‌ای اوورسایز", image: "/block-media/shadcnblocks/block/ecommerce/clothes/black-hoodie-against-light-background.png", price: 6500000, inStock: true, dateAdded: "2024-11-28", category: "پوشاک", }, ]; type SortOption = "date" | "price-low" | "price-high" | "name"; interface Wishlist2Props { items?: WishlistItem[]; className?: string; } const Wishlist2 = ({ items = DEFAULT_ITEMS, className }: Wishlist2Props) => { const [wishlistItems, setWishlistItems] = useState(items); const [sortBy, setSortBy] = useState("date"); const removeItem = (id: string) => { setWishlistItems((prev) => prev.filter((item) => item.id !== id)); }; const formatPrice = (price: number) => { return new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", }).format(price); }; const formatDate = (isoDate: string) => { return new Intl.DateTimeFormat("fa-IR", { dateStyle: "medium" }).format( new Date(isoDate), ); }; const sortedItems = [...wishlistItems].sort((a, b) => { switch (sortBy) { case "price-low": return a.price - b.price; case "price-high": return b.price - a.price; case "name": return a.name.localeCompare(b.name, "fa"); default: return ( new Date(b.dateAdded).getTime() - new Date(a.dateAdded).getTime() ); } }); const sortLabels: Record = { date: "تاریخ افزودن", "price-low": "قیمت: کم به زیاد", "price-high": "قیمت: زیاد به کم", name: "نام", }; return (
{/* Header */}

موارد ذخیره‌شده

{wishlistItems.length.toLocaleString("fa-IR")} مورد در لیست علاقه‌مندی

{(Object.keys(sortLabels) as SortOption[]).map((option) => ( setSortBy(option)} > {sortBy === option && } {sortLabels[option]} ))}
{/* List */} {sortedItems.length > 0 ? (
{sortedItems.map((item, index) => (
{index > 0 && }
{item.name}

{item.name}

{!item.inStock && ( ناموجود )}

{item.category}

{formatPrice(item.price)} {item.originalPrice && ( {formatPrice(item.originalPrice)} )}
افزوده‌شده در {formatDate(item.dateAdded)}
))}
) : (

موردی ذخیره نشده است

مجموعه را مرور کنید و محصولات مورد علاقه را ذخیره کنید

)}
); }; export { Wishlist2 };