'use client'

import { SidebarMenuButton } from '@admin/components/ui/sidebar'
import Link from 'next/link'
import { usePathname } from 'next/navigation'

export function AdminNavLink({
  href,
  exact = false,
  children
}: {
  href: string
  exact?: boolean
  children: React.ReactNode
}) {
  const pathname = usePathname()
  const isActive =
    exact || href === '/admin'
      ? pathname === href
      : pathname === href || pathname.startsWith(`${href}/`)

  return (
    <SidebarMenuButton
      render={
        <Link
          aria-current={isActive ? 'page' : undefined}
          data-active={isActive ? true : undefined}
          href={href}
        />
      }
    >
      {children}
    </SidebarMenuButton>
  )
}
