import React, { useState, useRef, useEffect } from 'react'; import { Home, PlusSquare, Library, LogOut, Settings, ChevronDown, Search, Heart, Menu } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { supabase } from '../lib/supabase'; type Page = 'home' | 'deck' | 'login' | 'collection' | 'profile' | 'search' | 'life-counter'; interface NavigationProps { currentPage: Page; setCurrentPage: (page: Page) => void; } export default function Navigation({ currentPage, setCurrentPage }: NavigationProps) { const { user, signOut } = useAuth(); const [showDropdown, setShowDropdown] = useState(false); const [showMobileMenu, setShowMobileMenu] = useState(false); const dropdownRef = useRef(null); const mobileMenuRef = useRef(null); const [username, setUsername] = useState(null); useEffect(() => { const fetchProfile = async () => { if (user) { const { data } = await supabase .from('profiles') .select('username') .eq('id', user.id) .single(); if (data) { setUsername(data.username); } } }; fetchProfile(); }, [user]); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setShowDropdown(false); } if (mobileMenuRef.current && !mobileMenuRef.current.contains(event.target as Node)) { setShowMobileMenu(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const navItems = [ { id: 'home' as const, label: 'Home', icon: Home }, { id: 'deck' as const, label: 'New Deck', icon: PlusSquare }, { id: 'collection' as const, label: 'Collection', icon: Library }, { id: 'search' as const, label: 'Search', icon: Search }, { id: 'life-counter' as const, label: 'Life Counter', icon: Heart }, ]; const handleSignOut = async () => { try { await signOut(); setCurrentPage('login'); } catch (error) { console.error('Error signing out:', error); } }; const getAvatarUrl = (userId: string) => { return `https://api.dicebear.com/7.x/avataaars/svg?seed=${userId}&backgroundColor=b6e3f4,c0aede,d1d4f9`; }; return ( <> {/* Desktop Navigation - Top */} {/* Mobile Navigation - Bottom */} {/* Content Padding */}
); }