Newer
Older
"use client"
import { Icons } from "@/components/icons"
import { SidebarNavItem } from "@/types"
import { User } from "next-auth"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { Button } from "./ui/button"
export const MobileNav = ({ items, user }: { items: SidebarNavItem[], user: User | undefined }) => {
const path = usePathname()
if (!items?.length) {
return null
}
const visibleItems = user ? items : items.slice(0, 2)
return (
<nav className={`grid h-full max-w-lg grid-cols-${visibleItems.length} justify-between mx-auto`}>
{visibleItems.map((item, index) => {
const Icon = Icons[item.icon || "arrowRight"]
if (item.title === "My Profile") {
item.href = `/${user?.username}`
}
return (
item.href && (
<Link key={index} href={item.disabled ? "/" : item.href} className="inline-flex items-center justify-center">
<Button variant={`${path.startsWith(item.href) ? "secondary" : "ghost"}`} size="logo">
<Icon />
</Button>
</Link>
)
)
})}
</nav>
)
}