import Link from "next/link";
import { cn } from "@/lib/cn";

type ButtonProps = {
  children: React.ReactNode;
  className?: string;
  href?: string;
  variant?: "primary" | "secondary" | "ghost";
  type?: "button" | "submit";
  onClick?: () => void;
  disabled?: boolean;
};

/** Primary interactive button / link used across the storefront. */
export function Button({
  children,
  className,
  href,
  variant = "primary",
  type = "button",
  onClick,
  disabled,
}: ButtonProps) {
  const styles = cn(
    "btn-bin",
    (variant === "secondary" || variant === "ghost") && "btn-bin-outline",
    className,
  );

  if (href) {
    return (
      <Link href={href} className={styles}>
        {children}
      </Link>
    );
  }

  return (
    <button type={type} onClick={onClick} disabled={disabled} className={styles}>
      {children}
    </button>
  );
}
