import Tooltip from '../Tooltip/index.js';
import cs from 'classnames';
import React__default from 'react';

const Inline = "E_4100_0_7_iq1gosr";
const Truncate = props => {
  const {
    text,
    len = 100,
    frontLen,
    backLen = 4,
    hoverShowFullText = true,
    className,
    inline,
    "data-testid": dataTestId
  } = 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.createElement("div", {
    "data-testid": dataTestId,
    className: cs([className, inline && Inline])
  }, truncated);
  if (!hoverShowFullText || text.length <= len) {
    return Text;
  }
  return /* @__PURE__ */React__default.createElement(Tooltip, {
    title: text
  }, Text);
};
var Truncate$1 = Truncate;

export { Truncate$1 as default };
