import { Slot } from '@radix-ui/react-slot';
import { type VariantProps } from 'class-variance-authority';

import * as React from 'react';

import { cn } from '@/lib/utils';

import { buttonVariants } from './button-variants';

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

/**
 * Button component — primary interactive element.
 *
 * @status stable
 *
 * Variant hierarchy:
 * - `default` (primary) — one per view, main action
 * - `secondary` — supporting action
 * - `outline` — tertiary, low-emphasis
 * - `ghost` — icon-only or navigation actions
 * - `destructive` — destructive/irreversible actions only
 *
 * Sizes: `default`, `sm`, `lg`, `icon` (square, for icon-only buttons)
 */
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 };
