import React from "react";

type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
  href: string | { pathname?: string; query?: Record<string, string> };
  children: React.ReactNode;
};

const NextLink = React.forwardRef<HTMLAnchorElement, LinkProps>(({ href, children, ...props }, ref) => {
  const resolvedHref = typeof href === "string" ? href : href?.pathname || "";
  return (
    <a ref={ref} href={resolvedHref} {...props}>
      {children}
    </a>
  );
});

NextLink.displayName = "NextLink";

export default NextLink;
