"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

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

var _link = _interopRequireDefault(require("next/link"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _templateObject, _templateObject2;

var Button = function Button(_ref) {
  var label = _ref.label,
      link = _ref.link,
      onClick = _ref.onClick,
      _ref$variant = _ref.variant,
      variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
      target = _ref.target,
      className = _ref.className,
      children = _ref.children,
      fullWidth = _ref.fullWidth,
      icon = _ref.icon,
      _ref$iconPosition = _ref.iconPosition,
      iconPosition = _ref$iconPosition === void 0 ? 'right' : _ref$iconPosition,
      _ref$bordered = _ref.bordered,
      bordered = _ref$bordered === void 0 ? false : _ref$bordered,
      _ref$small = _ref.small,
      small = _ref$small === void 0 ? false : _ref$small,
      _ref$withCrossOver = _ref.withCrossOver,
      withCrossOver = _ref$withCrossOver === void 0 ? false : _ref$withCrossOver,
      borderRadius = _ref.borderRadius,
      rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["label", "link", "onClick", "variant", "target", "className", "children", "fullWidth", "icon", "iconPosition", "bordered", "small", "withCrossOver", "borderRadius"]);

  var getBorderRadius = function getBorderRadius() {
    if (!borderRadius && fullWidth) {
      return 'small';
    }

    return borderRadius || 'large';
  };

  var attrs = {
    'data-btn': '',
    'data-variant': variant,
    'data-border-radius': getBorderRadius()
  };

  if (fullWidth) {
    attrs['data-fullwidth'] = '';
  }

  if (bordered) {
    attrs['data-bordered'] = '';
  }

  if (small) {
    attrs['data-small'] = '';
  }

  if (withCrossOver) {
    attrs['data-cross-over'] = '';
  }

  if (variant === 'disabled') {
    attrs['disabled'] = '';
  }

  var content = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, iconPosition === 'left' && icon && /*#__PURE__*/_react["default"].createElement(IconWrapper, {
    position: "left"
  }, icon), children || label, iconPosition === 'right' && icon && /*#__PURE__*/_react["default"].createElement(IconWrapper, {
    position: "right"
  }, icon));

  if (link) {
    return /*#__PURE__*/_react["default"].createElement(_link["default"], (0, _extends2["default"])({
      prefetch: false,
      href: link,
      passHref: true
    }, rest), /*#__PURE__*/_react["default"].createElement("a", (0, _extends2["default"])({
      className: className,
      target: target,
      onClick: !rest.disabled ? onClick : function (e) {
        return e.preventDefault();
      }
    }, attrs), content));
  }

  return /*#__PURE__*/_react["default"].createElement(StyledButton, (0, _extends2["default"])({
    className: className,
    onClick: onClick
  }, attrs, rest), content);
};

exports.Button = Button;

var IconWrapper = _styledComponents["default"].span(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 2rem;\n  height: 2rem;\n  position: absolute;\n  top: 1.2rem;\n\n  ", "\n\n  & svg, img {\n    width: 1.8rem;\n    max-height: 1.9rem;\n  }\n"])), function (props) {
  return props.position === 'right' ? 'right: 2.6rem; top: 1.4rem;' : 'left: 2.6rem;';
});

var StyledButton = _styledComponents["default"].button(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])([""])));
//# sourceMappingURL=index.js.map