import { _ as _slicedToArray } from '../_verture/slicedToArray-76060636.js';
import { _ as __rest } from '../_verture/tslib.es6-55ed4bd2.js';
import { jsx } from 'react/jsx-runtime';
import React__default from 'react';
import RcTooltip from 'rc-tooltip';
import { placements } from 'rc-tooltip/lib/placements';
import clsx from 'clsx';
import { a as $rcPrefixCls, $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
import '../_verture/unsupportedIterableToArray-cb478f24.js';

//自动调整位置
var autoAdjustOverflowEnabled = {
  adjustX: 1,
  adjustY: 1
};
//非自动调整位置
var autoAdjustOverflowDisabled = {
  adjustX: 0,
  adjustY: 0
};
var targetOffset = [0, 0];
//获得调整位置选项
function getOverflowOptions(autoAdjustOverflow) {
  if (typeof autoAdjustOverflow === 'boolean') {
    return autoAdjustOverflow ? autoAdjustOverflowEnabled : autoAdjustOverflowDisabled;
  }
  return Object.assign(Object.assign({}, autoAdjustOverflowDisabled), autoAdjustOverflow);
}
//tooltip placement
function getPlacements(config) {
  var _config$arrowWidth = config.arrowWidth,
    arrowWidth = _config$arrowWidth === void 0 ? 4 : _config$arrowWidth,
    _config$horizontalArr = config.horizontalArrowShift,
    horizontalArrowShift = _config$horizontalArr === void 0 ? 16 : _config$horizontalArr,
    _config$verticalArrow = config.verticalArrowShift,
    verticalArrowShift = _config$verticalArrow === void 0 ? 8 : _config$verticalArrow,
    autoAdjustOverflow = config.autoAdjustOverflow,
    arrowPointAtCenter = config.arrowPointAtCenter;
  var placementMap = {
    left: {
      points: ['cr', 'cl'],
      offset: [-8, 0]
    },
    right: {
      points: ['cl', 'cr'],
      offset: [8, 0]
    },
    top: {
      points: ['bc', 'tc'],
      offset: [0, -8]
    },
    bottom: {
      points: ['tc', 'bc'],
      offset: [0, 8]
    },
    topLeft: {
      points: ['bl', 'tc'],
      offset: [-(horizontalArrowShift + arrowWidth), -8]
    },
    leftTop: {
      points: ['tr', 'cl'],
      offset: [-8, -(verticalArrowShift + arrowWidth)]
    },
    topRight: {
      points: ['br', 'tc'],
      offset: [horizontalArrowShift + arrowWidth, -8]
    },
    rightTop: {
      points: ['tl', 'cr'],
      offset: [8, -(verticalArrowShift + arrowWidth)]
    },
    bottomRight: {
      points: ['tr', 'bc'],
      offset: [horizontalArrowShift + arrowWidth, 8]
    },
    rightBottom: {
      points: ['bl', 'cr'],
      offset: [8, verticalArrowShift + arrowWidth]
    },
    bottomLeft: {
      points: ['tl', 'bc'],
      offset: [-(horizontalArrowShift + arrowWidth), 8]
    },
    leftBottom: {
      points: ['br', 'cl'],
      offset: [-8, verticalArrowShift + arrowWidth]
    }
  };
  Object.keys(placementMap).forEach(function (key) {
    placementMap[key] = arrowPointAtCenter ? Object.assign(Object.assign({}, placementMap[key]), {
      overflow: getOverflowOptions(autoAdjustOverflow),
      targetOffset: targetOffset
    }) : Object.assign(Object.assign({}, placements[key]), {
      offset: getAlignOffset(key).offset,
      overflow: getOverflowOptions(autoAdjustOverflow)
    });
    placementMap[key].ignoreShake = true;
  });
  return placementMap;
}
var splitObject = function splitObject(obj, keys) {
  var picked = {};
  var omitted = Object.assign({}, obj);
  keys.forEach(function (key) {
    if (obj && key in obj) {
      picked[key] = obj[key];
      delete omitted[key];
    }
  });
  return {
    picked: picked,
    omitted: omitted
  };
};
//兼容禁用title
function getDisabledCompatibleChildren(child) {
  var element = /*#__PURE__*/React__default.isValidElement(child) ? child : jsx("span", {
    children: child
  });
  if (element.type === 'button' && element.props.disabled) {
    var _splitObject = splitObject(element.props.style, ['position', 'left', 'right', 'top', 'bottom', 'float', 'display', 'zIndex']),
      picked = _splitObject.picked,
      omitted = _splitObject.omitted;
    var spanStyle = Object.assign(Object.assign({
      display: 'inline-block'
    }, picked), {
      cursor: 'not-allowed',
      width: element.props.block ? '100%' : null
    });
    var buttonStyle = Object.assign(Object.assign({}, omitted), {
      pointerEvents: 'none'
    });
    var _child = /*#__PURE__*/React__default.cloneElement(element, {
      style: buttonStyle,
      className: null
    });
    return jsx("span", Object.assign({
      style: spanStyle,
      className: clsx(element.props.className, "".concat($rcPrefixCls, "-tooltip-disabled-compatible-wrapper"))
    }, {
      children: _child
    }));
  }
  return element;
}
//映射placement
function mapLegacyPlacement(place) {
  var legacyPlacement = {
    'bottom-end': 'bottomRight',
    'bottom-start': 'bottomLeft',
    'left-end': 'leftBottom',
    'left-start': 'leftTop',
    'right-end': 'rightBottom',
    'right-start': 'rightTop',
    'top-end': 'topRight',
    'top-start': 'topLeft'
  };
  return legacyPlacement[place] || place;
}
//浮层偏移量
function getAlignOffset(place) {
  var mPlace = mapLegacyPlacement(place);
  var offsetMap = {
    left: {
      offset: [-8, 0]
    },
    right: {
      offset: [8, 0]
    },
    top: {
      offset: [0, -8]
    },
    bottom: {
      offset: [0, 8]
    },
    topLeft: {
      offset: [0, -8]
    },
    leftTop: {
      offset: [-8, 0]
    },
    topRight: {
      offset: [0, -8]
    },
    rightTop: {
      offset: [8, 0]
    },
    bottomRight: {
      offset: [0, 8]
    },
    rightBottom: {
      offset: [8, 0]
    },
    bottomLeft: {
      offset: [0, 8]
    },
    leftBottom: {
      offset: [-8, 0]
    }
  };
  return offsetMap[mPlace];
}

var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/5/25 下午7:17\n* @description\n*/\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-tooltip {\n  color: rgb(255, 255, 255);\n  font-size: 14px;\n  line-height: 1.5715;\n  position: absolute;\n  z-index: 1500;\n  display: block;\n  width: max-content;\n  visibility: visible;\n}\n.paraui-v3-tooltip .component-tooltip-content {\n  position: relative;\n}\n.paraui-v3-tooltip.component-tooltip-hidden {\n  display: none;\n}\n.paraui-v3-tooltip.paraui-v3-tooltip-hide-arrow .component-tooltip-arrow {\n  display: none;\n}\n.paraui-v3-tooltip .component-tooltip-inner {\n  min-width: 30px;\n  min-height: 32px;\n  padding: 5px 12px;\n  color: rgb(255, 255, 255);\n  text-align: left;\n  text-decoration: none;\n  word-break: break-all;\n  background-color: rgba(46, 55, 67, 0.7);\n  border-radius: 4px;\n  line-height: 22px;\n}\n.paraui-v3-tooltip .component-tooltip-arrow {\n  position: absolute;\n  z-index: 2;\n  display: block;\n  width: 22px;\n  height: 22px;\n  overflow: hidden;\n  background: transparent;\n  pointer-events: none;\n}\n.paraui-v3-tooltip .component-tooltip-arrow-content {\n  position: absolute;\n  top: 0;\n  right: 0;\n  bottom: 0;\n  left: 0;\n  display: block;\n  width: 11.3137085px;\n  height: 11.3137085px;\n  margin: auto;\n  content: \"\";\n  border-radius: 0 0 2px;\n  pointer-events: none;\n  background: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-tooltip .component-tooltip-arrow-content::before {\n  position: absolute;\n  top: -11.3137085px;\n  left: -11.3137085px;\n  width: 33.9411255px;\n  height: 33.9411255px;\n  background-repeat: no-repeat;\n  background-position: -10px -10px;\n  content: \"\";\n  clip-path: path(\"M 9.849242404917499 24.091883092036785 A 5 5 0 0 1 13.384776310850237 22.627416997969522 L 20.627416997969522 22.627416997969522 A 2 2 0 0 0 22.627416997969522 20.627416997969522 L 22.627416997969522 13.384776310850237 A 5 5 0 0 1 24.091883092036785 9.849242404917499 L 23.091883092036785 9.849242404917499 L 9.849242404917499 23.091883092036785 Z\");\n}\n.paraui-v3-tooltip.component-tooltip-placement-top .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-topLeft .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-topRight .component-tooltip-arrow {\n  bottom: 0;\n  transform: translateY(100%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-top .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-topLeft .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-topRight .component-tooltip-arrow-content {\n  box-shadow: 3px 3px 7px rgba(0, 0, 0, 0.07);\n  transform: translateY(-11px) rotate(45deg);\n}\n.paraui-v3-tooltip.component-tooltip-placement-top .component-tooltip-arrow {\n  left: 50%;\n  transform: translateY(100%) translateX(-50%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-topLeft .component-tooltip-arrow {\n  left: 13px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-topRight .component-tooltip-arrow {\n  right: 13px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-right .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-rightTop .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-rightBottom .component-tooltip-arrow {\n  left: 0;\n  transform: translateX(-100%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-right .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-rightTop .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-rightBottom .component-tooltip-arrow-content {\n  box-shadow: -3px 3px 7px rgba(0, 0, 0, 0.07);\n  transform: translateX(11px) rotate(135deg);\n}\n.paraui-v3-tooltip.component-tooltip-placement-right .component-tooltip-arrow {\n  top: 50%;\n  transform: translateX(-100%) translateY(-50%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-rightTop .component-tooltip-arrow {\n  top: 5px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-rightBottom .component-tooltip-arrow {\n  bottom: 5px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-left .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-leftTop .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-leftBottom .component-tooltip-arrow {\n  right: 0;\n  transform: translateX(100%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-left .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-leftTop .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-leftBottom .component-tooltip-arrow-content {\n  box-shadow: 3px -3px 7px rgba(0, 0, 0, 0.07);\n  transform: translateX(-11px) rotate(315deg);\n}\n.paraui-v3-tooltip.component-tooltip-placement-left .component-tooltip-arrow {\n  top: 50%;\n  transform: translateX(100%) translateY(-50%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-leftTop .component-tooltip-arrow {\n  top: 5px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-leftBottom .component-tooltip-arrow {\n  bottom: 5px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-bottom .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-bottomLeft .component-tooltip-arrow, .paraui-v3-tooltip.component-tooltip-placement-bottomRight .component-tooltip-arrow {\n  top: 0;\n  transform: translateY(-100%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-bottom .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-bottomLeft .component-tooltip-arrow-content, .paraui-v3-tooltip.component-tooltip-placement-bottomRight .component-tooltip-arrow-content {\n  box-shadow: -3px -3px 7px rgba(0, 0, 0, 0.07);\n  transform: translateY(11px) rotate(225deg);\n}\n.paraui-v3-tooltip.component-tooltip-placement-bottom .component-tooltip-arrow {\n  left: 50%;\n  transform: translateY(-100%) translateX(-50%);\n}\n.paraui-v3-tooltip.component-tooltip-placement-bottomLeft .component-tooltip-arrow {\n  left: 13px;\n}\n.paraui-v3-tooltip.component-tooltip-placement-bottomRight .component-tooltip-arrow {\n  right: 13px;\n}\n\n.component-tooltip-zoom-big-fast-enter,\n.component-tooltip-zoom-big-fast-appear {\n  animation-duration: 0.1s;\n  animation-fill-mode: both;\n  animation-play-state: paused;\n}\n\n.component-tooltip-zoom-big-fast-leave {\n  animation-duration: 0.1s;\n  animation-fill-mode: both;\n  animation-play-state: paused;\n}\n\n.component-tooltip-zoom-big-fast-enter.component-tooltip-zoom-big-fast-enter-active,\n.component-tooltip-zoom-big-fast-appear.component-tooltip-zoom-big-fast-appear-active {\n  animation-name: componentTooltipZoomBigIn;\n  animation-play-state: running;\n}\n\n.component-tooltip-zoom-big-fast-leave.component-tooltip-zoom-big-fast-leave-active {\n  animation-name: componentTooltipZoomBigOut;\n  animation-play-state: running;\n  pointer-events: none;\n}\n\n.component-tooltip-zoom-big-fast-enter,\n.component-tooltip-zoom-big-fast-appear {\n  transform: scale(0);\n  opacity: 0;\n  animation-timing-function: cubic-bezier(0.08, 0.82, 0.17, 1);\n}\n\n.component-tooltip-zoom-big-fast-enter-prepare,\n.component-tooltip-zoom-big-fast-appear-prepare {\n  transform: none;\n}\n\n.component-tooltip-zoom-big-fast-leave {\n  animation-timing-function: cubic-bezier(0.78, 0.14, 0.15, 0.86);\n}\n\n@keyframes componentTooltipZoomBigIn {\n  0% {\n    transform: scale(0.8);\n    opacity: 0;\n  }\n  100% {\n    transform: scale(1);\n    opacity: 1;\n  }\n}\n@keyframes componentTooltipZoomBigOut {\n  0% {\n    transform: scale(1);\n  }\n  100% {\n    transform: scale(0.8);\n    opacity: 0;\n  }\n}";
styleInject(css_248z);

//tooltip
var Tooltip = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
  var _a;
  var _React$useState = React__default.useState(props.defaultVisible),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    visible = _React$useState2[0],
    setVisible = _React$useState2[1]; //是否显示
  var wrapRef = React__default.useRef(); //锚点
  var tRef = React__default.useRef(); //实例
  var _React$useState3 = React__default.useState([0, 0]),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    targetOffset = _React$useState4[0],
    setTargetOffset = _React$useState4[1];
  React__default.useEffect(function () {
    var _a;
    if ('visible' in props || 'open' in props) {
      setVisible(!!((_a = props.visible) !== null && _a !== void 0 ? _a : props.open));
    }
  }, [(_a = props.visible) !== null && _a !== void 0 ? _a : props.open]);
  //no title
  var isUntitled = function isUntitled() {
    var title = props.title;
    return !title && title !== 0;
  };
  //浮层切换时回调
  var onVisibleChange = function onVisibleChange(vis) {
    var _a;
    if (!('visible' in props || 'open' in props)) {
      setVisible(isUntitled() ? false : vis);
    }
    if (!isUntitled()) {
      (_a = props.onVisibleChange) === null || _a === void 0 ? void 0 : _a.call(props, vis);
    }
  };
  //tooltip 弹出位置
  var getTooltipPlacements = function getTooltipPlacements() {
    var builtinPlacements = props.builtinPlacements,
      arrowPointAtCenter = props.arrowPointAtCenter,
      autoAdjustOverflow = props.autoAdjustOverflow;
    return builtinPlacements || getPlacements({
      arrowPointAtCenter: arrowPointAtCenter,
      autoAdjustOverflow: autoAdjustOverflow
    });
  };
  // 动态设置动画点
  var onPopupAlign = function onPopupAlign(domNode, align) {
    var placements = getTooltipPlacements();
    // 当前返回的位置
    var placement = Object.keys(placements).find(function (key) {
      return placements[key].points[0] === align.points[0] && placements[key].points[1] === align.points[1];
    });
    if (!placement) {
      return;
    }
    // 根据当前坐标设置动画点
    var rect = domNode.getBoundingClientRect();
    var transformOrigin = {
      top: '50%',
      left: '50%'
    };
    if (placement.indexOf('top') >= 0 || placement.indexOf('Bottom') >= 0) {
      transformOrigin.top = "".concat(rect.height - align.offset[1], "px");
    } else if (placement.indexOf('Top') >= 0 || placement.indexOf('bottom') >= 0) {
      transformOrigin.top = "".concat(-align.offset[1], "px");
    }
    if (placement.indexOf('left') >= 0 || placement.indexOf('Right') >= 0) {
      transformOrigin.left = "".concat(rect.width - align.offset[0], "px");
    } else if (placement.indexOf('right') >= 0 || placement.indexOf('Left') >= 0) {
      transformOrigin.left = "".concat(-align.offset[0], "px");
    }
    domNode.style.transformOrigin = "".concat(transformOrigin.left, " ").concat(transformOrigin.top);
  };
  //跟随光标
  var handleMouseMove = function handleMouseMove(e) {
    var _a, _b, _c, _d;
    if (wrapRef.current) {
      var popupHeight = ((_d = (_c = (_b = (_a = tRef.current) === null || _a === void 0 ? void 0 : _a.popupRef) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.getElement()) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 0;
      var cursorSpace = popupHeight === 0 ? 60 : 30;
      var _wrapRef$current$getB = wrapRef.current.getBoundingClientRect(),
        x = _wrapRef$current$getB.x,
        y = _wrapRef$current$getB.y,
        width = _wrapRef$current$getB.width;
      var newX = e.clientX - (x + width / 2);
      var newY = e.clientY - y + popupHeight + cursorSpace;
      setTimeout(function () {
        setTargetOffset([-newX, -newY]);
      });
    }
  };
  var _props$prefixCls = props.prefixCls,
    prefixCls = _props$prefixCls === void 0 ? "".concat($rcPrefixCls, "-tooltip") : _props$prefixCls,
    getPopupContainer = props.getPopupContainer,
    overlayClassName = props.overlayClassName,
    overlayInnerStyle = props.overlayInnerStyle,
    overlayStyle = props.overlayStyle,
    children = props.children,
    title = props.title,
    placement = props.placement,
    isPopover = props.isPopover,
    followCursor = props.followCursor,
    maxWidth = props.maxWidth,
    restProps = __rest(props, ["prefixCls", "getPopupContainer", "overlayClassName", "overlayInnerStyle", "overlayStyle", "children", "title", "placement", "isPopover", "followCursor", "maxWidth"]);
  var tempVisible = visible;
  if (!('visible' in props || 'open' in props) && isUntitled()) {
    //没有title必然不可见
    tempVisible = false;
  }
  //overlayCls
  var overlayCls = clsx(!isPopover && "".concat($prefixCls, "-tooltip"), overlayClassName, !props.arrow && "".concat($prefixCls, "-tooltip-hide-arrow"));
  var mergeOverlayStyle = Object.assign({}, overlayStyle);
  if (maxWidth) {
    mergeOverlayStyle.maxWidth = maxWidth;
  }
  return jsx(RcTooltip, Object.assign({}, restProps, {
    prefixCls: prefixCls,
    placement: followCursor ? 'top' : mapLegacyPlacement(placement),
    overlayClassName: overlayCls,
    getTooltipContainer: getPopupContainer,
    ref: ref || tRef,
    builtinPlacements: getTooltipPlacements(),
    overlay: title,
    visible: tempVisible,
    align: {
      targetOffset: targetOffset
    },
    onVisibleChange: onVisibleChange,
    onPopupAlign: onPopupAlign,
    overlayStyle: mergeOverlayStyle,
    overlayInnerStyle: overlayInnerStyle,
    arrowContent: props.arrow ? jsx("span", {
      className: "".concat($rcPrefixCls, "-tooltip-arrow-content")
    }) : null,
    motion: {
      motionName: "".concat($rcPrefixCls, "-tooltip-zoom-big-fast"),
      motionDeadline: 1000
    }
  }, {
    children: followCursor ? jsx("div", Object.assign({
      style: {
        display: 'inline-block'
      },
      ref: wrapRef,
      onMouseMove: handleMouseMove
    }, {
      children: getDisabledCompatibleChildren(children)
    })) : getDisabledCompatibleChildren(children)
  }));
});
Tooltip.displayName = 'Tooltip';
Tooltip.defaultProps = {
  placement: 'top',
  mouseEnterDelay: 0.1,
  mouseLeaveDelay: 0.1,
  arrowPointAtCenter: false,
  autoAdjustOverflow: true,
  arrow: false,
  defaultVisible: false,
  followCursor: false
};

export { Tooltip, Tooltip as default };
