"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { Menu, Heart, Truck, ShoppingCart, Info } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Sheet, SheetContent, SheetHeader, SheetTitle, } from "@/components/ui/sheet"; import { ScrollArea } from "@/components/ui/scroll-area"; import { useCategories, useFavorites, useOrders } from "@/lib/hooks"; import { useCartCount } from "@/features/cart/hooks/useCart"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; interface MobileBottomNavProps { locale?: string; translations?: { catalog: string; favorites: string; orders: string; cart: string; login: string; profile: string; }; onLoginClick?: () => void; } export default function MobileBottomNav({ locale = "ru", translations, onLoginClick, }: MobileBottomNavProps) { const [isClient, setIsClient] = useState(false); const [isCategoryOpen, setIsCategoryOpen] = useState(false); const [expandedCategories, setExpandedCategories] = useState>( new Set(), ); const [touchStart, setTouchStart] = useState(null); const t = useTranslations(); const handleTouchStart = (e: React.TouchEvent) => { setTouchStart(e.targetTouches[0].clientX); }; const handleTouchEnd = (e: React.TouchEvent) => { if (touchStart === null) return; const touchEnd = e.changedTouches[0].clientX; const distance = touchStart - touchEnd; // Side is left, so swiping left (negative delta or positive distance) closes it if (distance > 50) { setIsCategoryOpen(false); } setTouchStart(null); }; const toggleCategory = (categoryId: number) => { setExpandedCategories((prev) => { const newSet = new Set(prev); if (newSet.has(categoryId)) { newSet.delete(categoryId); } else { newSet.add(categoryId); } return newSet; }); }; const { data: categories = [] } = useCategories(); const cartCount = useCartCount(); const { data: favoritesData } = useFavorites(); const { data: ordersData } = useOrders(); const router = useRouter(); useEffect(() => { setIsClient(true); }, []); const handleNavigation = (path: string) => (e: React.MouseEvent) => { e.preventDefault(); router.push(path); }; if (!isClient) return null; return ( <> {/* Mobile Bottom Navigation */}
{/* Catalog Button */} {/* Favorites Button */} {/* Orders Button */} {/* Cart Button */} {/* Info Button */}
{/* Category Sheet/Drawer */} {t("common.catalog")}
{categories.map((category) => (
setIsCategoryOpen(false)} className="flex-1 flex items-center gap-2 px-3 py-2 rounded-xl hover:bg-gray-100 transition-all font-bold text-gray-900 hover:text-gray-700" > {category.name} {/* Toggle button if has children */} {category.children && category.children.length > 0 && ( )}
{/* Subcategories */} {category.children && category.children.length > 0 && expandedCategories.has(category.id) && (
{category.children.map((child: any) => ( setIsCategoryOpen(false)} className="block px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-50 rounded-lg transition-all font-medium" > {child.name} ))}
)}
))}
); }