import _Tooltip from "antd/es/tooltip";
import _Icon from "@alifd/next/es/icon";
import _Button from "antd/es/button";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["textValue", "tipColor", "defaultShow", "placement", "style", "mouseEnterDelay", "mouseLeaveDelay", "triggerMethod", "tipTextColor", "fontSize", "fontFamily", "tipsText", "type", "icons", "flag"];
import * as React from 'react';
import { useState } from 'react';
import "./index.less";
var antTooltip = function antTooltip(_ref) {
  var textValue = _ref.textValue,
    tipColor = _ref.tipColor,
    defaultShow = _ref.defaultShow,
    placement = _ref.placement,
    style = _ref.style,
    mouseEnterDelay = _ref.mouseEnterDelay,
    mouseLeaveDelay = _ref.mouseLeaveDelay,
    triggerMethod = _ref.triggerMethod,
    tipTextColor = _ref.tipTextColor,
    fontSize = _ref.fontSize,
    fontFamily = _ref.fontFamily,
    tipsText = _ref.tipsText,
    type = _ref.type,
    icons = _ref.icons,
    flag = _ref.flag,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _style = style || {};
  // _style['width'] = _style['width']
  // _style['fontSize'] = _style['fontSize'] ? _style['fontSize'] : '18px'

  var _otherProps = otherProps || {};
  var others = {};
  var _useState = useState(defaultShow),
    _defaultShow = _useState[0],
    setDefaultShow = _useState[1];
  _otherProps.style = _style;
  if (defaultShow) {
    others.visible = _defaultShow;
  } else {
    if (others.visible == true || others.visible == false) delete others.visible;
  }

  // 改变内容的颜色
  var tip = /*#__PURE__*/React.createElement("span", {
    style: {
      color: tipTextColor,
      fontSize: fontSize,
      fontFamily: fontFamily
    }
  }, tipsText);

  // console.log(_defaultShow)
  var $body = document.documentElement;
  $body.addEventListener('click', function (e) {
    setDefaultShow(false);
    console.log('点击到页面了');
  });
  return /*#__PURE__*/React.createElement("div", _extends({
    id: "my-ant-tooptip"
  }, _otherProps, {
    className: flag ? 'tip-isflag' : 'tip-style'
  }), _defaultShow && /*#__PURE__*/React.createElement(_Tooltip, _extends({
    zIndex: _style['zIndex'],
    trigger: triggerMethod,
    mouseEnterDelay: mouseEnterDelay,
    mouseLeaveDelay: mouseLeaveDelay,
    title: tip,
    placement: placement,
    color: tipColor
  }, others, {
    getPopupContainer: function getPopupContainer(trigger) {
      return trigger.parentNode;
    }
  }), type == '文本' && /*#__PURE__*/React.createElement("span", {
    className: "my-tooptip"
  }, textValue), type == '按钮' && /*#__PURE__*/React.createElement(_Button, _extends({}, _otherProps, {
    className: "my_tip_btn"
  }), textValue), type == '图标' && /*#__PURE__*/React.createElement(_Icon, {
    type: icons
  })), _defaultShow || /*#__PURE__*/React.createElement(_Tooltip, {
    zIndex: _style['zIndex'],
    trigger: triggerMethod,
    mouseEnterDelay: mouseEnterDelay,
    mouseLeaveDelay: mouseLeaveDelay,
    title: tip,
    placement: placement,
    color: tipColor
  }, type == '文本' && /*#__PURE__*/React.createElement("span", {
    className: "my-tooptip"
  }, textValue), type == '按钮' && /*#__PURE__*/React.createElement(_Button, _extends({}, _otherProps, {
    className: "my_tip_btn"
  }), textValue), type == '图标' && /*#__PURE__*/React.createElement(_Icon, {
    type: icons
  })));
};
antTooltip.displayName = 'antTooltip';
export default antTooltip;