import classNames from "classnames/dedupe";
import type { HTMLAttributeAnchorTarget, MouseEvent } from "react";
import { Button, type ButtonProps } from "../Button";

export interface LinkButtonProps extends ButtonProps {
  href: string;
  title?: string;
  style?: React.CSSProperties;
  referrerPolicy?: ReferrerPolicy;
  download?: boolean | string;
  rel?: string;
  target?: HTMLAttributeAnchorTarget;
  onClick?: (event: MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => void;
  to?: unknown;
}

export function LinkButton({
  href,
  children,
  className,
  elementType = "a",
  ...rest
}: LinkButtonProps) {
  if (!href) {
    throw new Error("LinkButton requires a href prop");
  }

  const classes = classNames("mobius", "mobius-link-button", className);

  return (
    <Button elementType={elementType} href={href} className={classes} {...rest}>
      {children}
    </Button>
  );
}
