import _Balloon from "@alifd/next/es/balloon";
import React, { useEffect } from 'react';
import ReactDom from 'react-dom';
var targetClass = 'render-wrapper-target';
var rootClass = 'render-wrapper-root done-note-wrapper';

// 获取DOM真实style的方法
var getStyle = function getStyle(obj, attr) {
  if (obj.currentStyle) {
    // 兼容IE
    return obj.currentStyle[attr];
  } else {
    return window.getComputedStyle(obj, null)[attr];
  }
};
var NoteWrapper = function NoteWrapper(props, ref) {
  var el = document.createElement('div');
  var innerRef = null;
  el.className = rootClass;
  el.id = props.id;
  el.ref = ref;
  var _renderLayer = function _renderLayer() {
    var note = props.note;
    var defaultTrigger = /*#__PURE__*/React.createElement("div", {
      className: "render-wrapper-note"
    }, "N");
    var node = /*#__PURE__*/React.createElement(_Balloon.Tooltip, {
      trigger: defaultTrigger,
      align: "rb",
      triggerType: "click",
      popupStyle: {
        fontSize: '12px',
        lineHeight: '1.6',
        background: '#fff'
      }
    }, note);
    ReactDom.render(node, el);
  };
  useEffect(function () {
    _renderLayer();
    if (innerRef) {
      var refDom = ReactDom.findDOMNode(innerRef);
      if (refDom.className.indexOf(targetClass) === -1) {
        if (getStyle(refDom, 'position') === 'static') {
          refDom.style.position = 'relative'; // 当target目标组件的position为static时, 则使用relative, 方便内层元素定位
        }

        refDom.className += " " + targetClass;
        refDom.appendChild(el);
      }
    }
  });
  var children = props.children;
  var _children = React.Children.map(children, function (child) {
    var c = child;
    if (typeof child === 'string') c = /*#__PURE__*/React.createElement("span", null, child);
    return /*#__PURE__*/React.cloneElement(c, {
      ref: function ref(_ref) {
        return innerRef = _ref;
      }
    });
  });
  return _children || /*#__PURE__*/React.createElement(React.Fragment, null);
};
var RefNoteWrapper = /*#__PURE__*/React.forwardRef(NoteWrapper);
RefNoteWrapper.displayName = 'Wrapper';
export default RefNoteWrapper;