import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"

const buttonVariants = cva(
  "inline-flex items-center justify-center whitespace-nowrap text-sm font-semibold ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
  {
    variants: {
      variant: {
        default: "bg-midnight text-white hover:bg-gray-800",
        destructive: "bg-alert-red text-white hover:bg-alert-red/90",
        outline: "border border-gray-200 bg-white hover:bg-gray-50 text-midnight",
        secondary: "bg-gray-100 text-midnight hover:bg-gray-200",
        ghost: "hover:bg-gray-100 text-midnight",
        link: "text-promise-blue underline-offset-4 hover:underline",
        success: "bg-fulfilled-green text-white hover:bg-fulfilled-green/90",
        amber: "bg-generosity-gold text-white hover:bg-generosity-gold/90",
        blue: "bg-promise-blue text-white hover:bg-promise-blue/90",
      },
      size: {
        default: "h-11 px-6 py-2",
        sm: "h-9 px-4",
        lg: "h-14 px-8 text-base",
        xl: "h-16 px-10 text-lg",
        icon: "h-10 w-10",
      },
    },
    defaultVariants: { variant: "default", size: "default" },
  }
)

export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(({ className, variant, size, ...props }, ref) => (
  <button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
))
Button.displayName = "Button"

export { Button, buttonVariants }
