import React from 'react'
import { cn } from '@/lib/utils'
import { Loader2 } from 'lucide-react'

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: 'primary' | 'secondary' | 'ghost' | 'destructive' | 'outline' | 'default'
  size?: 'default' | 'sm' | 'lg' | 'icon'
  isLoading?: boolean
  children: React.ReactNode
}

export function Button({
  variant = 'primary',
  size = 'default',
  isLoading = false,
  children,
  className = '',
  disabled,
  ...props
}: ButtonProps) {
  const baseClasses = 'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50'

  const variantClasses = {
    primary: 'bg-blue-600 text-white hover:bg-blue-700 shadow hover:bg-blue-700/90',
    default: 'bg-blue-600 text-white hover:bg-blue-700 shadow hover:bg-blue-700/90',
    secondary: 'bg-slate-100 text-slate-900 hover:bg-slate-200/80',
    ghost: 'hover:bg-slate-100 hover:text-slate-900',
    destructive: 'bg-red-500 text-white hover:bg-red-600/90',
    outline: 'border border-input bg-transparent shadow-sm hover:bg-slate-100 hover:text-slate-900'
  }

  const sizeClasses = {
    default: 'h-9 px-4 py-2',
    sm: 'h-8 rounded-md px-3 text-xs',
    lg: 'h-10 rounded-md px-8',
    icon: 'h-9 w-9'
  }

  return (
    <button
      className={cn(baseClasses, variantClasses[variant], sizeClasses[size], className)}
      disabled={disabled || isLoading}
      {...props}
    >
      {isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
      {children}
    </button>
  )
}