import { Slot } from "@radix-ui/react-slot";
import * as React from "react";
import {
  type CommonButtonSize,
  type CommonButtonVariant,
  getCommonButtonClasses,
} from "../../../../common/ui/button";
import { cn } from "../../lib/utils";

export interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: CommonButtonVariant;
  size?: CommonButtonSize;
  asChild?: boolean;
}

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

export { Button };
