import s from './styles.module.scss';
import {
  ButtonHTMLAttributes,
  DetailedHTMLProps,
  FunctionComponent,
  ReactNode,
  SVGProps,
} from 'react';
import { clsx } from 'clsx';

type ButtonProps = {
  className?: string;
  children?: ReactNode;
  disabled?: boolean;
  Icon?: FunctionComponent<SVGProps<SVGSVGElement>>;
  onClick?: () => void;
  variant?: 'default' | 'green' | 'ghost' | 'white';
  fullWidth?: boolean;
} & DetailedHTMLProps<
  ButtonHTMLAttributes<HTMLButtonElement>,
  HTMLButtonElement
>;

function Button({
  className,
  children,
  onClick,
  Icon,
  disabled,
  variant = 'default',
  fullWidth = false,
  ...props
}: ButtonProps) {
  return (
    <button
      className={clsx(
        className,
        s.Button,
        disabled && s.Button_disabled,
        s['Button_' + variant],
        fullWidth && s.Button_fullWidth,
      )}
      onClick={onClick}
      disabled={disabled}
      {...props}
    >
      {Icon && <Icon />}
      {children}
    </button>
  );
}

export { Button };
