"use client";

import { ButtonHTMLAttributes, ReactNode, ElementType } from "react";

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: "primary" | "secondary" | "success" | "danger" | "ghost";
  size?: "sm" | "md" | "lg";
  children: ReactNode;
  as?: ElementType;
}

const variantClasses = {
  primary: "btn-primary border transition-colors",
  secondary: "btn-secondary border transition-colors",
  success: "btn-success border transition-colors",
  danger: "btn-danger border transition-colors",
  ghost: "btn-ghost border-transparent transition-colors",
};

const sizeClasses = {
  sm: "px-2 sm:px-3 py-1 text-[10px] sm:text-xs",
  md: "px-4 py-2 text-xs",
  lg: "px-6 py-3 text-sm",
};

export default function Button({
  variant = "primary",
  size = "md",
  className = "",
  disabled,
  children,
  as: Component = "button",
  ...props
}: ButtonProps) {
  return (
    <Component
      className={`border uppercase tracking-widest rounded transition disabled:opacity-50 disabled:cursor-not-allowed ${variantClasses[variant]} ${sizeClasses[size]} ${className}`}
      disabled={disabled}
      {...props}
    >
      {children}
    </Component>
  );
}
