"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.textTypeMap = exports.isProduction = exports["default"] = exports.createTitle = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _excluded = ["prefix", "className"],
  _excluded2 = ["prefix", "className", "type", "component", "strong", "underline", "delete", "code", "mark"],
  _excluded3 = ["prefix", "className", "component"];
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; }
var createTitle = function createTitle(Tag) {
  /**
   * Typography.Title
   * @description 分为 H1, H2, H3, H4, H5, H6 不同的组件，表示不同层级，继承 Typography.Text API
   * @order 1
   */
  var Title = /*#__PURE__*/function (_React$Component) {
    (0, _inheritsLoose2["default"])(Title, _React$Component);
    function Title() {
      return _React$Component.apply(this, arguments) || this;
    }
    var _proto = Title.prototype;
    _proto.render = function render() {
      var _this$props = this.props,
        prefix = _this$props.prefix,
        className = _this$props.className,
        others = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
      return /*#__PURE__*/React.createElement(Text, (0, _extends2["default"])({}, others, {
        component: Tag,
        className: (className || '') + " " + prefix + "typography-title"
      }));
    };
    return Title;
  }(React.Component);
  Title.defaultProps = {
    prefix: 'next-'
  };
  Title.displayName = Tag.toUpperCase();
  return Title;
};

/**
 * 判断是否是生产环境
 * @type {Boolean}
 */
exports.createTitle = createTitle;
var isProduction = function isProduction() {
  var PRODUCTION_ENV = 'production';
  var result = false;
  try {
    if (process.env.NODE_ENV === PRODUCTION_ENV) {
      result = true;
    }
  } catch (err) {
    //
  }
  return result;
};

// 兼容老逻辑
exports.isProduction = isProduction;
var textTypeMap = {
  'body-1': 'body2',
  'body-2': 'body1',
  subhead: 'h6',
  title: 'h5',
  headline: 'h4',
  'display-1': 'h3',
  'display-2': 'h2',
  'display-3': 'h1'
};
exports.textTypeMap = textTypeMap;
/**
 * 文字 字体、大小、行高
 * @param props
 */
var Text = function Text(props, ref) {
  var _classNames;
  var prefix = props.prefix,
    className = props.className,
    type = props.type,
    _props$component = props.component,
    component = _props$component === void 0 ? 'span' : _props$component,
    strong = props.strong,
    underline = props.underline,
    deleteProp = props["delete"],
    code = props.code,
    mark = props.mark,
    others = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded2);
  var children = props.children;
  var newType = textTypeMap[type] || type;
  var cls = (0, _classnames["default"])(className, (_classNames = {}, _classNames[prefix + "text"] = true, _classNames[prefix + "text-" + newType] = newType, _classNames));
  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 Tag = component;
  if (strong) {
    children = /*#__PURE__*/React.createElement("strong", null, children);
  }
  if (underline) {
    children = /*#__PURE__*/React.createElement("u", null, children);
  }
  if (deleteProp) {
    children = /*#__PURE__*/React.createElement("del", null, children);
  }
  if (code) {
    children = /*#__PURE__*/React.createElement("code", null, children);
  }
  if (mark) {
    children = /*#__PURE__*/React.createElement("mark", null, children);
  }
  return /*#__PURE__*/React.createElement(Tag, (0, _extends2["default"])({}, others, {
    className: cls,
    ref: ref
  }), children);
};
var RefText = /*#__PURE__*/React.forwardRef(Text);
RefText.defaultProps = {
  prefix: 'next-'
};
var Paragraph = function Paragraph(props) {
  var prefix = props.prefix,
    className = props.className,
    component = props.component,
    others = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded3);
  var cls = (0, _classnames["default"])(prefix + "text-paragraph", className);
  if (!isProduction()) {
    console.warn('Warning: Text.Paragraph is deprecated, use P instead');
  }
  return /*#__PURE__*/React.createElement(Text, (0, _extends2["default"])({}, others, {
    className: cls,
    component: component
  }));
};
// 为了保证兼容性，@alifd/next基础组件中 Typography 组件有的所有子组件、功能，Text也有，但是均不建议使用
RefText.H1 = createTitle('h1');
RefText.H2 = createTitle('h2');
RefText.H3 = createTitle('h3');
RefText.H4 = createTitle('h4');
RefText.H5 = createTitle('h5');
RefText.H6 = createTitle('h6');
RefText.Paragraph = Paragraph;
var _default = RefText;
exports["default"] = _default;