import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';
import { cn } from '@/lib/utils';

const buttonVariants = cva(
    'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-semibold uppercase tracking-wide transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-orange-600 focus-visible:ring-offset-2 focus-visible:ring-offset-ink-950 disabled:pointer-events-none disabled:opacity-50',
    {
        variants: {
            variant: {
                primary:
                    'bg-orange-600 text-white shadow-[0_8px_24px_-8px_rgba(245,106,0,0.55)] hover:bg-orange-700 hover:-translate-y-0.5',
                ghost:
                    'border border-white/15 text-white hover:bg-white/5 hover:border-white/30',
                whatsapp:
                    'bg-[var(--color-whatsapp)] text-white hover:brightness-110',
                dark:
                    'bg-ink-900 text-white border border-ink-700 hover:bg-ink-800',
                outline:
                    'border-2 border-orange-600 text-orange-500 hover:bg-orange-600 hover:text-white',
            },
            size: {
                sm: 'h-9 px-4 text-xs',
                md: 'h-11 px-5 text-sm',
                lg: 'h-12 px-7 text-sm',
                xl: 'h-14 px-8 text-base',
            },
        },
        defaultVariants: { variant: 'primary', size: 'md' },
    }
);

export interface ButtonProps
    extends React.ButtonHTMLAttributes<HTMLButtonElement>,
        VariantProps<typeof buttonVariants> {
    asChild?: boolean;
}

export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
    ({ className, variant, size, asChild = false, ...props }, ref) => {
        const Comp = asChild ? Slot : 'button';
        return (
            <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
        );
    }
);
Button.displayName = 'Button';

export { buttonVariants };
