'use strict';

var index = require('../Tooltip/index.js');
var cs = require('classnames');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var React__default = /*#__PURE__*/_interopDefault(React);

const Inline = "E_iq1gosr";
const Truncate = props => {
  const {
    text,
    len = 100,
    frontLen,
    backLen = 4,
    hoverShowFullText = true,
    className,
    inline
  } = props;
  if (len <= 0) {
    console.error("[Truncate] prop len can not be 0 or negative number");
    return null;
  }
  if (backLen < 0) {
    console.error("[Truncate] prop backLen can not be negative number");
    return null;
  }
  if (frontLen && frontLen < 0) {
    console.error("[Truncate] prop frontLen can not be negative number");
    return null;
  }
  const ellipse = "...";
  let _backLen = Math.min(backLen, text.length - ellipse.length, len - ellipse.length);
  const _frontLen = frontLen !== void 0 ? Math.min(frontLen, text.length - ellipse.length, len - ellipse.length) : Math.max(len - _backLen - ellipse.length, 0);
  if (_frontLen + _backLen + ellipse.length > len) {
    _backLen = len - _frontLen - ellipse.length;
  }
  const truncated = text.length <= len ? text : text.slice(0, _frontLen) + ellipse + text.slice(text.length - _backLen);
  const Text = /* @__PURE__ */React__default.default.createElement("div", {
    className: cs__default.default([className, inline && Inline])
  }, truncated);
  if (!hoverShowFullText || text.length <= len) {
    return Text;
  }
  return /* @__PURE__ */React__default.default.createElement(index, {
    title: text
  }, Text);
};
var Truncate$1 = Truncate;

module.exports = Truncate$1;
