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

import { ComponentPropsWithRef } from 'react';
import { buttonVariants } from './button.variants';
import { cn } from '@/lib/utils';

export interface ButtonProps
  extends ComponentPropsWithRef<'button'>,
    VariantProps<typeof buttonVariants> {
  asChild?: boolean;
}

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

export { Button };
