import { cva, type VariantProps } from 'class-variance-authority';
import { forwardRef, type ButtonHTMLAttributes } from 'react';
import { cn } from '@/lib/cn';

/**
 * Primitive shadcn-style (composant possédé) : les variants correspondent
 * exactement aux boutons de la maquette validée (.btn, .prim, .succes, …).
 */
const buttonVariants = cva('btn', {
  variants: {
    variant: {
      default: '',
      prim: 'prim',
      succes: 'succes',
      dangerLeger: 'danger-l',
      ghost: 'ghost',
    },
  },
  defaultVariants: { variant: 'default' },
});

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

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant, type, ...props }, ref) => (
    <button
      ref={ref}
      type={type ?? 'button'}
      className={cn(buttonVariants({ variant }), className)}
      {...props}
    />
  ),
);
Button.displayName = 'Button';
