import Link from "next/link";
import { buttonClasses, type ButtonProps } from "./Button";

/**
 * A link that looks like a button.
 *
 * For the case where the control's job is "go to this page" — a "Next" that
 * moves to a form, a "Join our partners" that opens the sponsorship page. Four
 * screens expressed that as `<Link><Button>…</Button></Link>`, which nests a
 * `<button>` inside the link's `<a>`: not valid content, two focus stops for
 * one destination, and a screen reader announcing an inner button that has no
 * behaviour of its own.
 *
 * One element, so there is one thing to Tab to and one thing to announce — and
 * it is a link, so it still opens in a new tab on a middle click and offers
 * "Copy link address", which a button never did. The appearance is identical:
 * the classes come from `buttonClasses`, the same function `Button` itself
 * uses.
 */
export default function ButtonLink({
  href,
  variant,
  size,
  className,
  children,
  onClick,
  ...rest
}: {
  href: string;
  variant?: ButtonProps["variant"];
  size?: ButtonProps["size"];
  className?: string;
  children: React.ReactNode;
  onClick?: () => void;
} & Omit<React.ComponentProps<typeof Link>, "href" | "className" | "children" | "onClick">) {
  return (
    <Link
      href={href}
      className={buttonClasses({ variant, size, className })}
      onClick={onClick}
      {...rest}
    >
      {children}
    </Link>
  );
}
