var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

import { jsx as _jsx } from "react/jsx-runtime";
import React, { useEffect, useRef, useState } from 'react';
import ToolTip from "./";
import "./style/tooltip-text.css";
var prefixCls = 'dmc-tooltip-text';

var TooltipText = function TooltipText(_a) {
  var text = _a.text,
      className = _a.className,
      placement = _a.placement;
  var ref = useRef(null);

  var _b = useState(false),
      enable = _b[0],
      setEnable = _b[1];

  useEffect(function () {
    var ele = ref.current;
    var pw = ele.parentElement.getBoundingClientRect().width;
    var ew = ele.getBoundingClientRect().width;
    setEnable(ew > pw);
  }, []);

  var comp = _jsx("div", __assign({
    className: prefixCls + " " + (className || '')
  }, {
    children: _jsx("span", __assign({
      ref: ref
    }, {
      children: text
    }), void 0)
  }), void 0);

  return enable ? _jsx(ToolTip, __assign({
    title: text,
    placement: placement
  }, {
    children: comp
  }), void 0) : comp;
};

TooltipText.displayName = 'Tooltip';
export default TooltipText;
var TooltipTextMemo = /*#__PURE__*/React.memo(TooltipText);
TooltipTextMemo.displayName = 'TooltipTextMemo';
export { TooltipTextMemo };

