import { useState, useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { motion } from 'motion/react'
import { Home, LayoutGrid, Info, ExternalLink, Shield } from 'lucide-react'
interface DockItem {
label: string
icon: React.ReactNode
path?: string
href?: string
}
const items: DockItem[] = [
{ label: 'Home', icon: , path: '/' },
{ label: 'Products', icon: , path: '/products' },
{ label: 'About', icon: , path: '/about' },
{ label: 'Privacy', icon: , path: '/privacy-policy' },
{ label: 'TechLatest', icon: , href: 'https://tech-latest.com' },
]
export default function Dock() {
const location = useLocation()
const navigate = useNavigate()
const [activeIndex, setActiveIndex] = useState(0)
useEffect(() => {
const idx = items.findIndex(item => item.path && item.path === location.pathname)
if (idx !== -1) setActiveIndex(idx)
}, [location.pathname])
function handleClick(item: DockItem, index: number) {
setActiveIndex(index)
if (item.href) {
window.open(item.href, '_blank', 'noopener noreferrer')
} else if (item.path) {
navigate(item.path)
}
}
return (
<>
{/* ── DESKTOP DOCK (sm+) — centered floating pill ── */}
{items.map((item, i) => {
const isActive = i === activeIndex
return (
handleClick(item, i)}
whileHover={{ scale: 1.06, y: -2 }}
whileTap={{ scale: 0.93 }}
transition={{ type: 'spring', stiffness: 400, damping: 22 }}
className={`
relative flex items-center gap-2 rounded-xl cursor-pointer px-3 py-2
transition-all duration-200
${isActive
? 'bg-white/10 border border-white/15 text-white'
: 'border border-transparent text-zinc-500 hover:text-zinc-300'
}
`}
aria-label={item.label}
>
{item.icon}
{/* Expanding active label */}
{item.label}
{/* Active dot */}
{isActive && (
)}
)
})}
{/* ── MOBILE DOCK (
{items.map((item, i) => {
const isActive = i === activeIndex
return (
)
})}
>
)
}