"use client"; import Image from "next/image"; import Link from "next/link"; import { usePathname, useSearchParams } from "next/navigation"; import { ChevronDown, Heart, Menu, MessageCircle, PackageCheck, ShoppingCart, UserRound } from "lucide-react"; import { Suspense, useMemo, useState } from "react"; import { PredictiveSearch } from "@/components/search/predictive-search"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent } from "@/components/ui/dialog"; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet"; import type { Category, Product } from "@/lib/headless/types"; import { useCartStore } from "@/store/cart-store"; import { useWishlistStore } from "@/store/wishlist-store"; type CategoryNode = Category & { children: Category[] }; function buildCategoryTree(categories: Category[]): CategoryNode[] { return categories .filter((category) => !category.parentId) .map((root) => ({ ...root, children: categories.filter((category) => category.parentId === root.id), })); } export function Navbar({ products, categories }: { products: Product[]; categories: Category[] }) { const [menuOpen, setMenuOpen] = useState(false); const [accountOpen, setAccountOpen] = useState(false); const items = useCartStore((state) => state.items); const cartHydrated = useCartStore((state) => state.hasHydrated); const openCart = useCartStore((state) => state.openCart); const wishlistProducts = useWishlistStore((state) => state.products); const wishlistHydrated = useWishlistStore((state) => state.hasHydrated); const openWishlist = useWishlistStore((state) => state.openWishlist); const count = cartHydrated ? items.reduce((sum, item) => sum + item.quantity, 0) : 0; const wishlistCount = wishlistHydrated ? wishlistProducts.length : 0; const tree = useMemo(() => buildCategoryTree(categories), [categories]); // Derivado de los productos reales (no de un endpoint de colecciones): // solo aparecen colecciones que de verdad tienen productos hoy. const collections = useMemo( () => [...new Set(products.map((product) => product.collection).filter(Boolean))], [products], ); return (
Paga tus compras a cuotas · Envíos nacionales · Compra segura con ARI
ARI Shopping
setMenuOpen(true)} />}> setMenuOpen(true)} /> Explora ARI Categorías y colecciones del catálogo.

Categorías

setMenuOpen(false)} />}> setMenuOpen(false)} />
{collections.length > 0 && ( <>

Colecciones

{collections.map((collection) => setMenuOpen(false)} className="rounded-full bg-slate-100 px-4 py-2 text-sm font-bold hover:bg-violet-100 hover:text-violet-700">{collection})}
)}
Atención personalizada

Tu cuenta ARI

El inicio de sesión quedará conectado al backend headless. Mientras tanto, puedes gestionar pedidos y disponibilidad directamente por WhatsApp.

); } function useCategoryNavigationState() { const pathname = usePathname(); const searchParams = useSearchParams(); const currentCategory = searchParams.get("category") ?? ""; const isCatalog = pathname === "/catalog"; return { isAllActive: isCatalog && !currentCategory, isActive: (name: string) => isCatalog && currentCategory === name, }; } function pillClass(active: boolean): string { return `shrink-0 rounded-full px-4 py-2 text-sm font-extrabold transition ${ active ? "bg-gradient-to-r from-cyan-500 to-violet-500 text-white shadow-lg shadow-violet-950/30" : "text-white/90 hover:bg-gradient-to-r hover:from-cyan-500 hover:to-violet-500 hover:text-white" }`; } function mobileLinkClass(active: boolean): string { return `rounded-2xl border px-4 py-3 font-extrabold transition ${ active ? "border-violet-500 bg-violet-50 text-violet-700" : "border-slate-200 hover:border-cyan-400 hover:bg-cyan-50" }`; } function DesktopCategoryNavigation({ tree, onOpenMenu }: { tree: CategoryNode[]; onOpenMenu: () => void }) { const { isActive, isAllActive } = useCategoryNavigationState(); return ( ); } function DesktopCategoryNavigationFallback({ tree, onOpenMenu }: { tree: CategoryNode[]; onOpenMenu: () => void }) { return ( ); } function MobileCategoryLinks({ tree, onNavigate }: { tree: CategoryNode[]; onNavigate: () => void }) { const { isActive, isAllActive } = useCategoryNavigationState(); return ( <> Todo el catálogo {tree.map((root) => (
{root.name} {root.children.map((child) => ( {child.name} ))}
))} ); } function MobileCategoryLinksFallback({ tree, onNavigate }: { tree: CategoryNode[]; onNavigate: () => void }) { return ( <> Todo el catálogo {tree.map((root) => (
{root.name} {root.children.map((child) => ( {child.name} ))}
))} ); }