import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["prefix", "className", "underline", "delete", "italic", "ellipsizeMode", "numberOfLines", "fontFamily"];
import * as React from 'react';
import classNames from 'classnames';
import { replaceNode, transformColorStyle } from "../util";
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 = _objectWithoutPropertiesLoose(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 = classNames(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 = _extends({}, others);
  var colorStyle = transformColorStyle(customStyle);
  if (numberOfLines && numberOfLines >= 0) {
    customStyle = _extends({}, customStyle, {
      "WebkitLineClamp": numberOfLines,
      "WebkitBoxOrient": "vertical",
      "display": "-webkit-box"
    });
  }
  if (fontFamily && fontFamily.length > 0) {
    customStyle = _extends({}, customStyle, {
      "fontFamily": fontFamily
    });
  }
  _props.style = _extends({}, props.style || {}, customStyle, colorStyle);
  if (_props.typeConversion && _props.typeConversion !== 'NextText') {
    replaceNode(_props.typeConversion);
  }
  return /*#__PURE__*/React.createElement("span", _extends({}, _props, {
    className: cls,
    ref: ref
  }), children);
};
var RefText = /*#__PURE__*/React.forwardRef(Text);
RefText.defaultProps = {
  prefix: 'next-'
};
export default RefText;