import React, { useCallback } from 'react';
import { useHistory } from 'react-router-dom';

export type Props = Partial<{
  onClick: () => void;
  route: string;
  variant: 'contained' | 'outlined';
  size: 'sm' | 'md' | 'lg';
  children: string;
}>


const variants = {
  contained: 'bg-black text-white',
  outlined: '',
};

const sizes = {
  lg: 'p-5',
  md: 'p-4',
  sm: 'p-3',
};

const Button: React.FC<Props> = ({ onClick, route, variant = 'contained', size = 'md', children }) => {
  const history = useHistory();
  const navigateRoute = useCallback(() => history.push(route || '/'), [route, history]);

  return (
    <button
      type="button"
      onClick={route ? navigateRoute : onClick}
      className={`m-3 font-bold tracking-wide hover:underline focus:outline-none border-2 border-black ${variants[variant]} ${sizes[size]}`}
    >
      {children}
    </button>
  );
};

export default Button;
