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 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-kodo-cyan disabled:pointer-events-none disabled:opacity-50 active:scale-95",
  {
    variants: {
      variant: {
        default:
          "bg-kodo-cyan text-kodo-void hover:bg-kodo-cyan-dim shadow-[0_0_15px_rgba(102,252,241,0.25)] hover:shadow-[0_0_25px_rgba(102,252,241,0.4)] border border-transparent font-bold 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",
        outline:
          "border border-kodo-steel bg-transparent text-kodo-secondary hover:bg-white/5 hover:text-white hover:border-kodo-cyan/50",
        secondary:
          "bg-kodo-steel/30 text-white hover:bg-kodo-steel/50 border border-white/5",
        ghost: "hover:bg-white/5 hover:text-white text-kodo-secondary",
        link: "text-kodo-cyan underline-offset-4 hover:underline",
        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_20px_rgba(102,252,241,0.5)]",
        glass: "bg-white/5 border border-white/10 backdrop-blur-md text-white hover:bg-white/10 hover:border-white/20 shadow-lg",
      },
      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 }