import Link from 'next/link'
import { type ComponentProps, type PropsWithChildren } from 'react'

export type Props = ComponentProps<typeof Link>

export default function HybridLink({
  href,
  children,
  ...rest
}: PropsWithChildren<Props>) {
  if (href && (typeof href !== 'string' || href.startsWith('/')))
    return (
      <Link href={href} {...rest}>
        {children}
      </Link>
    )
  else
    return (
      <a href={href} {...rest}>
        {children}
      </a>
    )
}
