"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"] = Text;

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

var _TextModule = _interopRequireDefault(require("./Text.module.css"));

var _Text = _interopRequireDefault(require("./Text.constantProps"));

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

var _Text2 = _interopRequireWildcard(require("./Text.propTypes"));

var _getCompliedCustomId = _interopRequireDefault(require("../../utils/getCompliedCustomId"));

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

var _textConstants$type$h, _tagNamesMapping;

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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

var tagNamesMapping = (_tagNamesMapping = {}, _defineProperty(_tagNamesMapping, _Text["default"].type.heading, (_textConstants$type$h = {}, _defineProperty(_textConstants$type$h, _Text["default"].level.one, "h1"), _defineProperty(_textConstants$type$h, _Text["default"].level.two, "h2"), _defineProperty(_textConstants$type$h, _Text["default"].level.three, "h3"), _defineProperty(_textConstants$type$h, _Text["default"].level.four, "h4"), _defineProperty(_textConstants$type$h, _Text["default"].level.five, "h5"), _defineProperty(_textConstants$type$h, _Text["default"].level.six, "h6"), _textConstants$type$h)), _defineProperty(_tagNamesMapping, _Text["default"].type.paragraph, "p"), _defineProperty(_tagNamesMapping, _Text["default"].type.blockquote, "blockquote"), _tagNamesMapping);

var getTagNameByTypeProperty = function getTagNameByTypeProperty(type, level) {
  if (type === _Text["default"].type.heading) {
    return tagNamesMapping[type][level];
  } else {
    return tagNamesMapping[type];
  }
};

var defaultTagName = "span";

function Text(props) {
  var _getCompliedClassName, _getCompliedClassName2;

  var textEllipsis = props.textEllipsis,
      wordWrap = props.wordWrap,
      variant = props.variant,
      size = props.size,
      stretch = props.stretch,
      auto = props.auto,
      align = props.align,
      direction = props.direction,
      weight = props.weight,
      transform = props.transform,
      colorPalette = props.colorPalette,
      decoration = props.decoration,
      decorationColor = props.decorationColor,
      type = props.type,
      level = props.level,
      startIcon = props.startIcon,
      endIcon = props.endIcon,
      lineHeight = props.lineHeight,
      letterSpacing = props.letterSpacing,
      indent = props.indent,
      tagName = props.tagName,
      onClick = props.onClick,
      customClassName = props.customClassName,
      customId = props.customId,
      customIdPrefix = props.customIdPrefix,
      ariaLabel = props.ariaLabel,
      role = props.role,
      tabIndex = props.tabIndex,
      children = props.children,
      content = props.content,
      tagAttributeProps = props.tagAttributeProps;
  var hasIcon = startIcon || endIcon;
  var className = (0, _getCompliedClassName3["default"])(customClassName, (_getCompliedClassName = {}, _defineProperty(_getCompliedClassName, _TextModule["default"].base, true), _defineProperty(_getCompliedClassName, _TextModule["default"].ellipsis, !!textEllipsis), _defineProperty(_getCompliedClassName, _TextModule["default"].wrap, !!wordWrap), _defineProperty(_getCompliedClassName, _TextModule["default"][variant], !!variant), _defineProperty(_getCompliedClassName, _TextModule["default"][size], !!size), _defineProperty(_getCompliedClassName, _TextModule["default"].stretch, !!stretch), _defineProperty(_getCompliedClassName, _TextModule["default"].auto, !!auto), _defineProperty(_getCompliedClassName, _TextModule["default"][direction], !!direction), _defineProperty(_getCompliedClassName, _TextModule["default"][align], !!align), _defineProperty(_getCompliedClassName, _TextModule["default"][weight], !!weight), _defineProperty(_getCompliedClassName, _TextModule["default"][transform], !!transform), _defineProperty(_getCompliedClassName, _TextModule["default"][colorPalette], !!colorPalette), _defineProperty(_getCompliedClassName, _TextModule["default"][lineHeight], !!lineHeight), _defineProperty(_getCompliedClassName, _TextModule["default"][letterSpacing], !!letterSpacing), _defineProperty(_getCompliedClassName, _TextModule["default"][decoration], !!decoration), _defineProperty(_getCompliedClassName, _TextModule["default"][decorationColor], !!decorationColor), _defineProperty(_getCompliedClassName, _TextModule["default"][indent], !!indent), _defineProperty(_getCompliedClassName, _TextModule["default"][type], !!type), _defineProperty(_getCompliedClassName, _TextModule["default"][level], !!level), _defineProperty(_getCompliedClassName, _TextModule["default"].content, !!(children || hasIcon)), _getCompliedClassName), (_getCompliedClassName2 = {}, _defineProperty(_getCompliedClassName2, customClassName.base, !!customClassName.base), _defineProperty(_getCompliedClassName2, customClassName.textEllipsis, !!customClassName.textEllipsis), _defineProperty(_getCompliedClassName2, customClassName.wordWrap, !!customClassName.wordWrap), _defineProperty(_getCompliedClassName2, customClassName.variant, !!customClassName.variant), _defineProperty(_getCompliedClassName2, customClassName.size, !!customClassName.size), _defineProperty(_getCompliedClassName2, customClassName.stretch, !!customClassName.stretch), _defineProperty(_getCompliedClassName2, customClassName.auto, !!customClassName.auto), _defineProperty(_getCompliedClassName2, customClassName.direction, !!customClassName.direction), _defineProperty(_getCompliedClassName2, customClassName.align, !!customClassName.align), _defineProperty(_getCompliedClassName2, customClassName.weight, !!customClassName.weight), _defineProperty(_getCompliedClassName2, customClassName.transform, !!customClassName.transform), _defineProperty(_getCompliedClassName2, customClassName.colorPalette, !!customClassName.colorPalette), _defineProperty(_getCompliedClassName2, customClassName.lineHeight, !!customClassName.lineHeight), _defineProperty(_getCompliedClassName2, customClassName.letterSpacing, !!customClassName.letterSpacing), _defineProperty(_getCompliedClassName2, customClassName.decoration, !!customClassName.decoration), _defineProperty(_getCompliedClassName2, customClassName.decorationColor, !!customClassName.decorationColor), _defineProperty(_getCompliedClassName2, customClassName.indent, !!customClassName.indent), _defineProperty(_getCompliedClassName2, customClassName.type, !!customClassName.type), _defineProperty(_getCompliedClassName2, customClassName.level, !!customClassName.level), _getCompliedClassName2));

  var textProperties = _objectSpread({
    className: className,
    onClick: onClick,
    "data-id": (0, _getCompliedCustomId["default"])(props, customId.text),
    "aria-label": ariaLabel,
    role: role,
    tabIndex: tabIndex
  }, tagAttributeProps);

  var displayTagName = tagName || props.type && getTagNameByTypeProperty(props.type, props.level) || defaultTagName;

  var displayContent = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(RenderAsIcon, {
    icon: startIcon,
    className: _TextModule["default"].start_icon
  }), content && hasIcon ? /*#__PURE__*/_react["default"].createElement("span", null, content) : content || null, !content && children ? children : null, /*#__PURE__*/_react["default"].createElement(RenderAsIcon, {
    icon: endIcon,
    className: _TextModule["default"].end_icon
  }));

  var element = /*#__PURE__*/_react["default"].createElement(displayTagName);

  return /*#__PURE__*/_react["default"].createElement(element.type, textProperties, displayContent);
}

Text.propTypes = _Text2["default"];
Text.defaultProps = _Text2.defaultProps;
Text.propsDescription = _Text2.propsDescription;
Text.constantProps = _Text["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
};