File size: 7,293 Bytes
78d0e31 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
"use client"
import { useState, useEffect } from "react"
import { usePathname } from "next/navigation"
import Link from "next/link"
import { Home, Shield, BookOpen, Activity, User, Menu, X, Heart, UserPlus, LogIn } from "lucide-react"
import { motion } from "framer-motion"
import { UserDatabase } from "@/lib/user-database"
export function MobileNav() {
const [isOpen, setIsOpen] = useState(false)
const pathname = usePathname()
const [currentUser, setCurrentUser] = useState<{ id: string; type: string } | null>(null)
// Check for logged in user
useEffect(() => {
const user = UserDatabase.getCurrentUser()
if (user) {
setCurrentUser({
id: user.id,
type: user.type,
})
} else {
setCurrentUser(null)
}
}, [pathname])
// Close menu when route changes
useEffect(() => {
setIsOpen(false)
}, [pathname])
const isActive = (path: string) => {
return pathname === path
}
// Navigation items with their icons, tooltips, and colors
const navItems = [
{ path: "/", icon: Home, label: "Home", color: "#ff3a2f" },
{ path: "/healers", icon: Heart, label: "Healers", color: "#ff7f41" },
{ path: "/become-guardian", icon: Shield, label: "Guardians", color: "#00ffa0" },
{ path: "/guardians-sanctuary", icon: Shield, label: "Sanctuary", color: "#ff4e00" },
{ path: "/flameborn-journey", icon: BookOpen, label: "Journey", color: "#ff00c8" },
{ path: "/community-pulse", icon: Activity, label: "Pulse", color: "#00f3ff" },
]
return (
<>
{/* Mobile menu button */}
<motion.button
className="md:hidden fixed bottom-4 right-4 z-50 bg-flame text-white p-3 rounded-full shadow-lg"
onClick={() => setIsOpen(!isOpen)}
aria-label={isOpen ? "Close menu" : "Open menu"}
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.9 }}
>
{isOpen ? <X className="h-6 w-6" /> : <Menu className="h-6 w-6" />}
</motion.button>
{/* Mobile navigation overlay */}
{isOpen && (
<motion.div
className="fixed inset-0 z-40 bg-black/95 md:hidden"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
<div className="flex flex-col h-full p-6">
<div className="flex justify-between items-center mb-8">
<Link href="/" className="text-2xl font-bold text-flame-red" style={{ textShadow: "none" }}>
FLAMEBORN
</Link>
<button onClick={() => setIsOpen(false)}>
<X className="h-6 w-6 text-white" />
</button>
</div>
<nav className="flex-1">
<div className="grid grid-cols-3 gap-4">
{navItems.map((item) => (
<Link
key={item.path}
href={item.path}
className="flex flex-col items-center justify-center p-4 rounded-lg bg-gray-800/30 hover:bg-gray-800/50 transition-colors"
onClick={() => setIsOpen(false)}
>
<motion.div
initial={{ scale: 1 }}
animate={
isActive(item.path)
? {
scale: [1, 1.2, 1],
transition: { repeat: Number.POSITIVE_INFINITY, repeatType: "reverse", duration: 2 },
}
: { scale: 1 }
}
className="mb-2"
>
<item.icon className="h-8 w-8" style={{ color: isActive(item.path) ? item.color : "#9ca3af" }} />
</motion.div>
<span className="text-sm" style={{ color: isActive(item.path) ? item.color : "#9ca3af" }}>
{item.label}
</span>
</Link>
))}
{currentUser ? (
<Link
href="/profile"
className="flex flex-col items-center justify-center p-4 rounded-lg bg-gray-800/30 hover:bg-gray-800/50 transition-colors"
onClick={() => setIsOpen(false)}
>
<motion.div
initial={{ scale: 1 }}
animate={
isActive("/profile")
? {
scale: [1, 1.2, 1],
transition: { repeat: Number.POSITIVE_INFINITY, repeatType: "reverse", duration: 2 },
}
: { scale: 1 }
}
className="mb-2"
>
<User
className="h-8 w-8"
style={{
color: isActive("/profile")
? currentUser.type === "guardian"
? "#00ffa0"
: "#ff3a2f"
: "#9ca3af",
}}
/>
</motion.div>
<span
className="text-sm"
style={{
color: isActive("/profile")
? currentUser.type === "guardian"
? "#00ffa0"
: "#ff3a2f"
: "#9ca3af",
}}
>
Profile
</span>
</Link>
) : (
<>
<Link
href="/login"
className="flex flex-col items-center justify-center p-4 rounded-lg bg-gray-800/30 hover:bg-gray-800/50 transition-colors"
onClick={() => setIsOpen(false)}
>
<motion.div className="mb-2">
<LogIn className="h-8 w-8 text-gray-400" />
</motion.div>
<span className="text-sm text-gray-400">Log In</span>
</Link>
<Link
href="/register/guardian"
className="flex flex-col items-center justify-center p-4 rounded-lg bg-flame/20 hover:bg-flame/30 transition-colors"
onClick={() => setIsOpen(false)}
>
<motion.div
initial={{ scale: 1 }}
animate={{
scale: [1, 1.2, 1],
transition: { repeat: Number.POSITIVE_INFINITY, repeatType: "reverse", duration: 2 },
}}
className="mb-2"
>
<UserPlus className="h-8 w-8 text-flame" />
</motion.div>
<span className="text-sm text-flame">Register</span>
</Link>
</>
)}
</div>
</nav>
</div>
</motion.div>
)}
</>
)
}
|