"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { ShoppingCart } from "lucide-react"; import { getCart } from "@/lib/cart"; export function CartIcon() { const router = useRouter(); const [count, setCount] = useState(0); useEffect(() => { const update = () => setCount(getCart().reduce((s, i) => s + i.quantity, 0)); update(); window.addEventListener("cart-updated", update); return () => window.removeEventListener("cart-updated", update); }, []); return ( ); }