"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _util = require("../util");
var _excluded = ["prefix", "className", "underline", "delete", "italic", "ellipsizeMode", "numberOfLines", "fontFamily"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var Text = function Text(props, ref) {
  var _classNames;
  var prefix = props.prefix,
    className = props.className,
    underline = props.underline,
    deleteProp = props["delete"],
    _props$italic = props.italic,
    italic = _props$italic === void 0 ? false : _props$italic,
    ellipsizeMode = props.ellipsizeMode,
    numberOfLines = props.numberOfLines,
    fontFamily = props.fontFamily,
    others = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
  var children = props.children;
  if (typeof children === 'string' && children.indexOf('\n') !== -1) {
    var childrenList = children.split('\n');
    var newChildren = [];
    childrenList.forEach(function (child) {
      newChildren.push(child);
      newChildren.push( /*#__PURE__*/React.createElement("br", null));
    });
    newChildren.pop();
    children = newChildren;
  }
  var newType = italic || false ? 'body1-italic' : 'body1';
  var cls = (0, _classnames["default"])(className, (_classNames = {}, _classNames[prefix + "text"] = true, _classNames[prefix + "text-" + newType] = newType, _classNames));
  if (underline) {
    children = /*#__PURE__*/React.createElement("u", null, children);
  }
  if (deleteProp) {
    children = /*#__PURE__*/React.createElement("del", null, children);
  }
  var customStyle = (others.customStyle || []).reduce(function (obj, item) {
    var _Object$assign;
    return Object.assign(obj, (_Object$assign = {}, _Object$assign[item.name] = item.value, _Object$assign));
  }, {});
  var _props = (0, _extends2["default"])({}, others);
  var colorStyle = (0, _util.transformColorStyle)(customStyle);
  if (numberOfLines && numberOfLines >= 0) {
    customStyle = (0, _extends2["default"])({}, customStyle, {
      "WebkitLineClamp": numberOfLines,
      "WebkitBoxOrient": "vertical",
      "display": "-webkit-box"
    });
  }
  if (fontFamily && fontFamily.length > 0) {
    customStyle = (0, _extends2["default"])({}, customStyle, {
      "fontFamily": fontFamily
    });
  }
  _props.style = (0, _extends2["default"])({}, props.style || {}, customStyle, colorStyle);
  if (_props.typeConversion && _props.typeConversion !== 'NextText') {
    (0, _util.replaceNode)(_props.typeConversion);
  }
  return /*#__PURE__*/React.createElement("span", (0, _extends2["default"])({}, _props, {
    className: cls,
    ref: ref
  }), children);
};
var RefText = /*#__PURE__*/React.forwardRef(Text);
RefText.defaultProps = {
  prefix: 'next-'
};
var _default = exports["default"] = RefText;