"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = Link;

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _LinkModule = _interopRequireDefault(require("./Link.module.css"));

var _getCompliedClassName3 = _interopRequireDefault(require("../../utils/getCompliedClassName"));

var _Link = _interopRequireWildcard(require("./Link.propTypes"));

var _Link2 = _interopRequireDefault(require("./Link.constantProps"));

var _templateObject;

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 }; }

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

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function Link(prop) {
  var _getCompliedClassName, _getCompliedClassName2;

  var target = prop.target,
      rel = prop.rel,
      href = prop.href,
      title = prop.title,
      download = prop.download,
      children = prop.children,
      text = prop.text,
      textEllipsis = prop.textEllipsis,
      wordWrap = prop.wordWrap,
      textDecoration = prop.textDecoration,
      color = prop.color,
      size = prop.size,
      active = prop.active,
      visited = prop.visited,
      disabled = prop.disabled,
      onClick = prop.onClick,
      customClassName = prop.customClassName,
      customId = prop.customId,
      customIdPrefix = prop.customIdPrefix,
      customIdSuffix = prop.customIdSuffix,
      ariaLabel = prop.ariaLabel,
      ariaHasPopup = prop.ariaHasPopup,
      ariaExpanded = prop.ariaExpanded,
      ariaLabelledBy = prop.ariaLabelledBy,
      role = prop.role,
      tabIndex = prop.tabIndex,
      startIcon = prop.startIcon,
      endIcon = prop.endIcon,
      tagAttributeProps = prop.tagAttributeProps,
      handlePreventDefault = prop.handlePreventDefault,
      hasPreventDefaultBehaviour = prop.hasPreventDefaultBehaviour;
  var hasIcon = startIcon || endIcon;
  var className = (0, _getCompliedClassName3["default"])(customClassName, (_getCompliedClassName = {}, _defineProperty(_getCompliedClassName, _LinkModule["default"].base, true), _defineProperty(_getCompliedClassName, _LinkModule["default"][textDecoration], !!textDecoration), _defineProperty(_getCompliedClassName, _LinkModule["default"].active, !!active), _defineProperty(_getCompliedClassName, _LinkModule["default"].visited, !!visited), _defineProperty(_getCompliedClassName, _LinkModule["default"].disabled, !!disabled), _defineProperty(_getCompliedClassName, _LinkModule["default"].ellipsis, !!textEllipsis), _defineProperty(_getCompliedClassName, _LinkModule["default"].wrap, !!wordWrap), _defineProperty(_getCompliedClassName, _LinkModule["default"][color], !!color), _defineProperty(_getCompliedClassName, _LinkModule["default"][size], !!size), _getCompliedClassName), (_getCompliedClassName2 = {}, _defineProperty(_getCompliedClassName2, customClassName.base, !!customClassName.base), _defineProperty(_getCompliedClassName2, customClassName.textDecoration, !!customClassName.textDecoration), _defineProperty(_getCompliedClassName2, customClassName.active, !!customClassName.active), _defineProperty(_getCompliedClassName2, customClassName.visited, !!customClassName.visited), _defineProperty(_getCompliedClassName2, customClassName.disabled, !!customClassName.disabled), _defineProperty(_getCompliedClassName2, customClassName.textEllipsis, !!customClassName.textEllipsis), _defineProperty(_getCompliedClassName2, customClassName.wordWrap, !!customClassName.wordWrap), _defineProperty(_getCompliedClassName2, customClassName.color, !!customClassName.color), _defineProperty(_getCompliedClassName2, customClassName.size, !!customClassName.size), _getCompliedClassName2));
  return /*#__PURE__*/_react["default"].createElement("a", _extends({
    className: className,
    href: href,
    target: target,
    rel: rel,
    onClick: onClick && hasPreventDefaultBehaviour ? handlePreventDefault : onClick,
    disabled: disabled,
    "data-id": customId.link(_templateObject || (_templateObject = _taggedTemplateLiteral(["", "", ""])), customIdPrefix, customIdSuffix),
    "aria-labelledby": ariaLabelledBy,
    "aria-haspopup": ariaHasPopup,
    "aria-expanded": ariaExpanded,
    "aria-label": ariaLabel,
    role: role,
    tabIndex: tabIndex,
    title: title,
    download: download
  }, tagAttributeProps), /*#__PURE__*/_react["default"].createElement(RenderAsIcon, {
    icon: startIcon,
    className: _LinkModule["default"].start_icon
  }), text && hasIcon ? /*#__PURE__*/_react["default"].createElement("span", {
    className: wordWrap ? _LinkModule["default"].linktext : null
  }, text) : text || null, !text && children ? children : null, /*#__PURE__*/_react["default"].createElement(RenderAsIcon, {
    icon: endIcon,
    className: _LinkModule["default"].end_icon
  }));
}

Link.propTypes = _Link["default"];
Link.defaultProps = _Link.defaultProps;
Link.propsDescription = _Link.propsDescription;
Link.constantProps = _Link2["default"];

var RenderAsIcon = function RenderAsIcon(props) {
  return props.icon ? /*#__PURE__*/_react["default"].createElement("span", {
    className: props.className
  }, props.icon) : null;
};

RenderAsIcon.propTypes = {
  icon: _propTypes["default"].any,
  className: _propTypes["default"].string
};