import { useHistory } from 'react-router-dom';
import PropTypes from 'prop-types';
import Button from './button';

function BackLink(props) {
  const history = useHistory();

  return (
    <Button
      color={props.color}
      outline={props.outline}
      flat={props.flat}
      size={props.size}
      loading={props.loading}
      disabled={props.disabled}
      className={props.className}
      onClick={history.goBack}
    >
      {props.content || props.children}
    </Button>
  );
}

BackLink.defaultProps = {
  content: 'بازگشت',
  outline: false,
  flat: false,
  size: 'base',
  textSize: 'sm',
  color: 'blue',
  loading: false,
  disabled: false
};

BackLink.propTypes = {
  content: PropTypes.string,
  color: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
  outline: PropTypes.bool.isRequired,
  flat: PropTypes.bool.isRequired,
  size: PropTypes.oneOf(['zero', 'xs', 'sm', 'base', 'lg', 'xl']).isRequired,
  textSize: PropTypes.oneOf(['xs', 'sm', 'base', 'lg', 'xl']).isRequired,
  loading: PropTypes.bool.isRequired,
  disabled: PropTypes.bool.isRequired,
  className: PropTypes.string
};

export default BackLink;
