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"
import { btnDefault, btnPrimary } from "@/lib/ui/buttonStyles"

const buttonVariants = cva(
  "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-3xl text-sm font-semibold disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 active:scale-[0.98]",
  {
    variants: {
      variant: {
        default: btnPrimary,
        destructive:
          "btn-modern border border-[#C3C3C3] bg-red-500 text-white shadow-sm hover:bg-red-600",
        outline: btnDefault,
        secondary: btnDefault,
        ghost:
          "border border-transparent hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
        link: "border border-transparent text-[#FC8EAC] underline-offset-4 hover:underline",
      },
      size: {
        default: "h-10 px-5 py-2 has-[>svg]:px-4",
        sm: "h-9 rounded-3xl gap-1.5 px-4 has-[>svg]:px-3",
        lg: "h-11 rounded-3xl px-7 has-[>svg]:px-5",
        icon: "size-10 rounded-3xl",
        "icon-sm": "size-9 rounded-3xl",
        "icon-lg": "size-11 rounded-3xl",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "default",
    },
  }
)

function Button({
  className,
  variant,
  size,
  asChild = false,
  ...props
}: React.ComponentProps<"button"> &
  VariantProps<typeof buttonVariants> & {
    asChild?: boolean
  }) {
  const Comp = asChild ? Slot : "button"

  return (
    <Comp
      data-slot="button"
      className={cn(buttonVariants({ variant, size, className }))}
      {...props}
    />
  )
}

export { Button, buttonVariants }
