import type { ComponentType } from 'react'
import { type NavItemAnchor } from '../../config'

type Props = {
  entry: NavItemAnchor
  linkComponent?: ComponentType<{ href: string; children: React.ReactNode }>
}
export function NavAnchor({
  entry,
  children,
  linkComponent,
}: React.PropsWithChildren<Props>) {
  const AnchorComponent = entry.url.startsWith('/')
    ? (linkComponent ?? 'a')
    : 'a'
  return (
    <AnchorComponent
      href={entry.url}
      className={'block align-middle leading-[0]'}
    >
      {children}
    </AnchorComponent>
  )
}
