import { forwardRef } from "react";
 
/**
 * Button
 *
 * variant: "primary" | "secondary" | "tertiary"
 * color:   "default" | "danger" | "success"
 * size:    "sm" | "md" | "lg"
 * shape:   "default" | "square" | "circle"
 * href:    string - renders as <a> instead of <button>
 */
const Button = forwardRef(function Button(
  {
    variant = "primary",
    color = "default",
    size = "md",
    shape = "default",
    href,
    disabled = false,
    className = "",
    children,
    ...props
  },
  ref
) {
  const isLink = Boolean(href);
 
  const classes = [
    "prs-btn",
    variant === "primary" && "prs-btn-primary",
    variant === "secondary" && "prs-btn-secondary",
    variant === "tertiary" && "prs-btn-tertiary",
    color === "danger" && "prs-btn-danger",
    color === "success" && "prs-btn-success",
    size === "sm" && "prs-btn-sm",
    size === "lg" && "prs-btn-lg",
    shape === "square" && "prs-btn-square",
    shape === "circle" && "prs-btn-circle",
    isLink && disabled && "prs-btn_disabled",
    className,
  ]
    .filter(Boolean)
    .join(" ");
 
  const sharedProps = {
    ref,
    className: classes,
    ...props,
  };
 
  if (isLink) {
    return (
      <a
        href={disabled ? undefined : href}
        aria-disabled={disabled ? true : undefined}
        {...sharedProps}
      >
        {children}
      </a>
    );
  }
 
  return (
    <button disabled={disabled} {...sharedProps}>
      {children}
    </button>
  );
});
 
export default Button;
