"use strict";

exports.__esModule = true;
exports.PillButton = 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 PillButton = function PillButton(_ref) {
  var tag = _ref.tag,
      _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'link' : _ref$type,
      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$large = _ref.large,
      large = _ref$large === void 0 ? false : _ref$large,
      _ref$className = _ref.className,
      className = _ref$className === void 0 ? undefined : _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 classes = (0, _classnames.default)('pill-button', className && className, large && 'large');
  return /*#__PURE__*/_react.default.createElement(Tag, _extends({
    className: classes
  }, options, {
    onClick: handleOnClick
  }), children);
};

PillButton.displayName = 'PillButton';
var PillButtonDoc;

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

var PillButtonWrapper = PillButtonDoc || PillButton;
exports.PillButton = PillButtonWrapper;