import { cva } from 'class-variance-authority';

/**
 * Button component variants with WCAG AAA touch target compliance (44x44px minimum).
 * All button sizes meet or exceed the minimum touch target dimensions for accessibility.
 *
 * Size guidance:
 * - sm (h-9 = 36px): Use in dense UIs like tables; pair with padding to meet 44px total touch area
 * - default (h-10 = 40px): Standard buttons; combined with horizontal padding meets 44px minimum
 * - lg (h-11 = 44px): Primary CTAs, form submissions; exceeds minimum on all sides
 * - icon (h-10 w-10): Icon buttons; pad parent container if smaller padding is used
 * - icon-sm (h-8 w-8 = 32px visual): Compact icon buttons; min 44px touch target on mobile (sm: resets to 32px)
 *
 * Note: Horizontal touch targets are calculated including px padding (4px+ = 12px total width).
 * For critical touch targets on mobile, prefer `lg` size or ensure sufficient spacing around smaller variants.
 */
export const buttonVariants = cva(
  'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 active:scale-[0.98]',
  {
    variants: {
      variant: {
        default:
          'bg-primary text-primary-foreground hover:bg-primary/90 hover:shadow-md hover:shadow-primary/25',
        destructive:
          'bg-destructive text-destructive-foreground hover:bg-destructive/90 hover:shadow-md hover:shadow-destructive/25',
        outline:
          'border border-input bg-background hover:bg-accent hover:text-accent-foreground hover:border-accent',
        // UI-015: secondary uses stronger foreground to meet WCAG AA 4.5:1 contrast ratio
        secondary:
          'bg-secondary text-secondary-foreground hover:bg-secondary/80 disabled:bg-secondary/40 disabled:text-secondary-foreground/60',
        ghost: 'hover:bg-accent hover:text-accent-foreground',
        link: 'text-primary underline-offset-4 hover:underline',
      },
      size: {
        default: 'h-10 px-4 py-2', /* 40px × 32px+ minimum */
        sm: 'h-9 min-h-[44px] sm:min-h-0 rounded-md px-3', /* 44px min on mobile, 36px on sm+ */
        lg: 'h-11 rounded-md px-8', /* 44px × 48px+ — ideal for mobile CTAs */
        icon: 'h-10 w-10', /* 40px × 40px — add spacing for critical mobile interactions */
        'icon-sm': 'h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0 p-0', /* 44px mobile touch target, 32px on sm+ */
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  },
);
