import * as React from 'react';
import { CnTooltip } from '@cainiaofe/cn-ui';
export const CellContentWithTooltip = React.memo(({ children, isClickable, onClick }) => {
    const ref = React.useRef(null);
    const [visible, setVisible] = React.useState(false);
    const tooltipTextRef = React.useRef('');
    const handleMouseEnter = React.useCallback(() => {
        const el = ref.current;
        if (el && el.scrollWidth > el.clientWidth) {
            tooltipTextRef.current = el.innerText || el.textContent || '';
            if (tooltipTextRef.current) {
                setVisible(true);
            }
        }
    }, []);
    const handleMouseLeave = React.useCallback(() => {
        setVisible(false);
    }, []);
    return (React.createElement(CnTooltip, { popupProps: { visible }, trigger: React.createElement("div", { ref: ref, className: "ai-table-cell-content", onClick: isClickable ? onClick : undefined, style: { cursor: isClickable ? 'pointer' : 'default' }, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave }, children) }, tooltipTextRef.current || ''));
});
