"use strict";

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

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

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

var _DragonKitContext = require("../../context/DragonKitContext");

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); }

var Button = function Button(_ref) {
  var tag = _ref.tag,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'link' : _ref$type,
      _ref$color = _ref.color,
      color = _ref$color === void 0 ? 'blue-light' : _ref$color,
      _ref$hover = _ref.hover,
      hover = _ref$hover === void 0 ? 'blue-on-white' : _ref$hover,
      onClick = _ref.onClick,
      to = _ref.to,
      _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$outline = _ref.outline,
      outline = _ref$outline === void 0 ? false : _ref$outline,
      _ref$small = _ref.small,
      small = _ref$small === void 0 ? false : _ref$small,
      className = _ref.className,
      children = _ref.children;

  var _useDragonKitValue = (0, _DragonKitContext.useDragonKitValue)(),
      dragonKit = _useDragonKitValue[0];

  var options = {};
  var Tag = tag || 'button';
  if (!tag && type === 'link') Tag = blank ? 'a' : dragonKit.Link;
  if (type === 'link' && !blank) options.to = to;else {
    options.href = to;
    options.target = '_blank';
    options.rel = 'noreferrer';
  }
  if (onclick || ['button', 'submit'].indexOf(type) >= 0) options.type = type;

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

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

    if (onClick) onClick(e);
  };

  var colorClass = outline ? "outline-" + color.toLowerCase() : color.toLowerCase();
  var classes = (0, _classnames.default)('button', colorClass, hover && "hover-" + hover, small && 'small');
  return /*#__PURE__*/_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;