"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TextButtonWithIcon = void 0;

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

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

var _box = require("../../../primitives/box");

var _span = require("../../typography/span");

var _smallArrowRight = require("../../icon/small-arrow-right");

var _add = require("../../icon/add");

var _focus = require("../../../mixins/focus");

var _branding = require("../../../mixins/branding");

var _unstyledButton = require("../../behaviors/unstyled-button");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

var sharedStyles = (0, _styledComponents.css)(["display:inline-block;text-decoration:none;cursor:pointer;color:inherit;&:hover{text-decoration:underline;}"]);
var StyledSpan = (0, _styledComponents["default"])(_span.Span).withConfig({
  displayName: "StyledSpan",
  componentId: "sc-1a3urqu-0"
})(["svg{vertical-align:middle;> g{fill:", ";}}"], _branding.getForegroundColor);

var ActualLink = _styledComponents["default"].a.withConfig({
  displayName: "ActualLink",
  componentId: "sc-1a3urqu-1"
})(["&&{", " ", "}", "{& > div{box-shadow:", " ", ",", ";border-radius:", ";}}"], sharedStyles, (0, _focus.getBaseFocusState)({
  hoverTransition: false,
  activeTransition: false
}), _focus.FOCUS_VISIBLE_SELECTOR, (0, _focus.focusedBorderShadow)({
  inset: false
}), _focus.focusedBorderColor, _focus.focusedBoxShadow, _focus.focusedBorderRadius);

var ActualButton = (0, _styledComponents["default"])(_unstyledButton.UnstyledButton).withConfig({
  displayName: "ActualButton",
  componentId: "sc-1a3urqu-2"
})(["", ""], sharedStyles);

var getIcon = function getIcon(icon) {
  switch (icon) {
    case 'add':
      return /*#__PURE__*/_react["default"].createElement(_add.Add, null);

    case 'small-arrow-right':
      return /*#__PURE__*/_react["default"].createElement(_smallArrowRight.SmallArrowRight, null);

    default:
      return null;
  }
};

var Display = function Display(_ref) {
  var position = _ref.position,
      icon = _ref.icon,
      children = _ref.children;
  return /*#__PURE__*/_react["default"].createElement(_box.Box, {
    stacked: "row",
    align: "center"
  }, position === 'left' && /*#__PURE__*/_react["default"].createElement(_box.Box, {
    spacing: "mr1",
    stacked: "row",
    align: "center"
  }, getIcon(icon)), /*#__PURE__*/_react["default"].createElement(_box.Box, null, children), position === 'right' && /*#__PURE__*/_react["default"].createElement(_box.Box, {
    spacing: "ml1",
    stacked: "row",
    align: "center"
  }, getIcon(icon)));
};
/**
 * Important: Due to our dependence on Icomoon, we cannot have an element
 * whose class name contains `icon-` in the middle.
 * We need the `Icon` part to be at the end instead of at the start or middle
 * because React auto-generates class names based on the component's displayName.
 */


var TextButtonWithIcon = function TextButtonWithIcon(_ref2) {
  var onClick = _ref2.onClick,
      href = _ref2.href,
      target = _ref2.target,
      spacing = _ref2.spacing,
      position = _ref2.position,
      icon = _ref2.icon,
      children = _ref2.children,
      _ref2$colorName = _ref2.colorName,
      colorName = _ref2$colorName === void 0 ? 'brand-primary-fg' : _ref2$colorName,
      className = _ref2.className,
      dataCy = _ref2['data-cy'],
      dataQa = _ref2['data-qa'];
  return /*#__PURE__*/_react["default"].createElement(StyledSpan, {
    bold: true,
    colorName: colorName,
    spacing: spacing
  }, onClick == null || href != null ? /*#__PURE__*/_react["default"].createElement(ActualLink, {
    href: href,
    target: target,
    onClick: onClick,
    "data-cy": dataCy,
    "data-qa": dataQa,
    className: className
  }, /*#__PURE__*/_react["default"].createElement(Display, {
    position: position,
    icon: icon
  }, children)) : /*#__PURE__*/_react["default"].createElement(ActualButton, {
    onClick: onClick,
    "data-cy": dataCy,
    "data-qa": dataQa,
    className: className
  }, /*#__PURE__*/_react["default"].createElement(Display, {
    position: position,
    icon: icon
  }, children)));
};

exports.TextButtonWithIcon = TextButtonWithIcon;
TextButtonWithIcon.displayName = 'TextButtonWithIcon';