"use strict";

exports.__esModule = true;
exports.Button = void 0;

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

// import { Icon } from '..';
// Colors: white, grey, blue, blue_light, yellow
// Hover Colors: blue_dark, blue_med
var Button = function Button(_ref) {
  var className = _ref.className,
      _ref$tag = _ref.tag,
      tag = _ref$tag === void 0 ? 'a' : _ref$tag,
      _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'blue' : _ref$color,
      _ref$hover = _ref.hover,
      hover = _ref$hover === void 0 ? 'blue-dark' : _ref$hover,
      onClick = _ref.onClick,
      outline = _ref.outline,
      type = _ref.type,
      url = _ref.url,
      _ref$blank = _ref.blank,
      blank = _ref$blank === void 0 ? false : _ref$blank,
      _ref$disabled = _ref.disabled,
      disabled = _ref$disabled === void 0 ? false : _ref$disabled,
      _ref$small = _ref.small,
      small = _ref$small === void 0 ? false : _ref$small,
      children = _ref.children;
  var Tag = tag;
  var options = {};

  var handleOnClick = function handleOnClick(e) {
    if (!onClick) return;

    if (disabled) {
      e.preventDefault();
      return;
    }

    if (onClick) {
      onClick(e);
    }
  };

  if (['document', 'route'].indexOf(type.toLowerCase()) >= 0) {
    options.to = url;
  } else {
    options.href = url;
  }

  if (type === 'Media' || blank) {
    options.target = '_blank';
    options.rel = 'noreferrer';
  }

  if (onclick || ['button', 'submit'].indexOf(type.toLowerCase()) >= 0) {
    options.type = type;
  }

  var colorClass = outline ? color.toLowerCase() + "-outline" : color.toLowerCase();
  var classes = (0, _classnames.default)('button', colorClass, // icon && 'has-icon',
  hover && "hover-" + hover, small && 'small');
  return _react.default.createElement(Tag, _extends({
    className: className || classes
  }, options, {
    onClick: handleOnClick
  }), children);
};

Button.displayName = 'Button';
var ButtonDoc;

if (process.env.NODE_ENV !== 'production') {
  // eslint-disable-next-line global-require
  ButtonDoc = require('./doc').doc(Button);
}

var ButtonWrapper = ButtonDoc || Button;
exports.Button = ButtonWrapper;