import Link from "next/link"; import { type AnchorHTMLAttributes, forwardRef, type ReactNode } from "react"; import { cn } from "@/lib/utils"; interface CustomLinkProps extends AnchorHTMLAttributes { href: string; target?: "_self" | "_blank" | string; ariaLabel?: string; className?: string; children: ReactNode; scroll?: boolean; size?: string; } function isExternalHref(href: string) { return /^https?:\/\//.test(href) || href.startsWith("mailto:"); } function hasDynamicHrefPlaceholder(href: string) { return href.includes("[") && href.includes("]"); } export const CustomLink = forwardRef( ( { href, target = "_blank", ariaLabel, className, children, scroll = true, size = "xs", ...props }, ref, ) => { const linkClassName = cn( `text-${size} text-button-tertiary p-0`, className, ); const shouldUseAnchor = isExternalHref(href) || hasDynamicHrefPlaceholder(href); if (shouldUseAnchor) { return ( {children} ); } return ( {children} ); }, ); CustomLink.displayName = "CustomLink";