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

const buttonVariants = cva(
  'inline-flex items-center justify-center whitespace-nowrap rounded-xl text-sm font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-kodo-cyan focus-visible:ring-offset-2 focus-visible:ring-offset-kodo-void disabled:pointer-events-none disabled:opacity-50 active:scale-[0.98] hover-lift',
  {
    variants: {
      variant: {
        default:
          'bg-kodo-cyan text-kodo-void hover:bg-kodo-cyan-dim shadow-[0_0_20px_rgba(102,252,241,0.3)] hover:shadow-[0_0_30px_rgba(102,252,241,0.5)] border border-transparent font-semibold tracking-tight',
        destructive:
          'bg-kodo-red/10 text-kodo-red hover:bg-kodo-red/20 border border-kodo-red/30 hover:border-kodo-red/50 hover:shadow-[0_0_15px_rgba(230,57,70,0.2)]',
        outline:
          'border border-kodo-steel bg-transparent text-kodo-secondary hover:bg-white/5 hover:text-white hover:border-kodo-cyan/50 hover:shadow-[0_0_10px_rgba(102,252,241,0.1)]',
        secondary:
          'bg-kodo-steel/30 text-white hover:bg-kodo-steel/50 border border-white/5 hover:border-white/10',
        ghost: 'hover:bg-white/5 hover:text-white text-kodo-secondary',
        link: 'text-kodo-cyan underline-offset-4 hover:underline hover:text-kodo-cyan-dim',
        neon: 'bg-transparent border border-kodo-cyan text-kodo-cyan shadow-[0_0_10px_rgba(102,252,241,0.2),inset_0_0_10px_rgba(102,252,241,0.1)] hover:bg-kodo-cyan hover:text-kodo-void hover:shadow-[0_0_25px_rgba(102,252,241,0.6)]',
        glass:
          'bg-white/5 border border-white/10 backdrop-blur-md text-white hover:bg-white/10 hover:border-white/20 shadow-lg hover:shadow-xl',
        premium:
          'bg-gradient-to-r from-kodo-cyan to-kodo-cyan-dim text-kodo-void font-semibold shadow-[0_0_25px_rgba(102,252,241,0.4)] hover:shadow-[0_0_35px_rgba(102,252,241,0.6)] border border-transparent',
      },
      size: {
        default: 'h-10 px-4 py-2',
        sm: 'h-8 rounded-lg px-3 text-xs',
        lg: 'h-12 rounded-xl px-8 text-base',
        icon: 'h-10 w-10',
      },
    },
    defaultVariants: {
      variant: 'default',
      size: 'default',
    },
  },
);

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

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 { Button, buttonVariants };
