"use client"; import { useEffect, useRef, useState } from "react"; import { useCart } from "./CartProvider"; import { getContinueUrl } from "@/lib/cart"; import { formatToman } from "@/lib/format"; import { BagIcon, CloseIcon, MinusIcon, PlusIcon, TrashIcon } from "./icons"; export default function MiniCart() { const { items, count, total, updateQuantity, removeItem } = useCart(); const [open, setOpen] = useState(false); const rootRef = useRef(null); useEffect(() => { if (!open) return; function onClickAway(e: MouseEvent) { if (rootRef.current && !rootRef.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener("mousedown", onClickAway); return () => document.removeEventListener("mousedown", onClickAway); }, [open]); return (
{open && (

سبد خرید

{items.length === 0 ? (
سبد خرید شما خالی است
) : (
{items.map((line) => (
{line.name}

{line.name}

{line.quantity}
{formatToman(line.price * line.quantity)}
))}
)} {items.length > 0 && (
جمع کل {formatToman(total)}
ادامه فرآیند خرید
)}
)}
); }