"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    EllipsisWithTooltip: ()=>EllipsisWithTooltip
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_antd_namespaceObject = require("antd");
const getContentWidth = (element)=>{
    if (element) {
        const range = document.createRange();
        range.selectNodeContents(element);
        const contentWidth = range.getBoundingClientRect().width;
        return contentWidth;
    }
};
const ellipsisDefaultStyle = {
    overflow: 'hidden',
    overflowWrap: 'break-word',
    textOverflow: 'ellipsis',
    whiteSpace: 'nowrap',
    wordBreak: 'break-all'
};
const EllipsisWithTooltip = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)((props, ref)=>{
    const [ellipsis, setEllipsis] = (0, external_react_namespaceObject.useState)(false);
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(false);
    const elRef = (0, external_react_namespaceObject.useRef)();
    (0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>({
            setPopoverVisible: setVisible
        }));
    if (!props.ellipsis) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
        children: props.children
    });
    const { popoverContent } = props;
    const isOverflowTooltip = ()=>{
        var _elRef_current;
        const contentWidth = getContentWidth(elRef.current);
        const offsetWidth = null === (_elRef_current = elRef.current) || void 0 === _elRef_current ? void 0 : _elRef_current.offsetWidth;
        return contentWidth > offsetWidth;
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Popover, {
        open: ellipsis && visible,
        onOpenChange: (visible)=>{
            setVisible(ellipsis && visible);
        },
        content: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            style: {
                width: 300,
                overflow: 'auto',
                maxHeight: 400
            },
            children: popoverContent || props.children
        }),
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            ref: elRef,
            style: {
                ...ellipsisDefaultStyle
            },
            onMouseEnter: (e)=>{
                const el = e.target;
                const isShowTooltips = isOverflowTooltip();
                if (isShowTooltips) setEllipsis(el.scrollWidth >= el.clientWidth);
            },
            children: props.children
        })
    });
});
EllipsisWithTooltip.displayName = 'EllipsisWithTooltip';
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
