'use client'
import { HTMLAttributes } from 'react'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { cn } from '@/lib/utils'
interface LinkComponentProps extends HTMLAttributes {
href: string
isExternal?: boolean
target?: string
}
export function LinkComponent({ href, children, isExternal, className, target = '_blank', ...props }: LinkComponentProps) {
const pathname = usePathname()
const classes = cn(className, {
active: pathname === href,
})
const isExternalEnabled = href.match(/^([a-z0-9]*:|.{0})\/\/.*$/) || isExternal
if (isExternalEnabled) {
return (
{children}
)
}
return (
{children}
)
}