"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TriggerWithTooltip = void 0;
const react_1 = __importStar(require("react"));
const cn_ui_1 = require("@cainiaofe/cn-ui");
/**
 * 将按钮用 CnTooltip 包裹，同时通过 forwardRef 把 ref 转发到内部按钮，
 * 使 CnPopup 能正确绑定到按钮 DOM 上，点击有效，悬停仍显示 CnTooltip。
 */
exports.TriggerWithTooltip = react_1.default.forwardRef(function TriggerWithTooltip({ children, tooltipContent, disableTooltip = false }, ref) {
    const mergedRef = (0, react_1.useCallback)((node) => {
        const childRef = children.ref;
        if (typeof childRef === 'function')
            childRef(node);
        else if (childRef)
            childRef.current = node;
        if (typeof ref === 'function')
            ref(node);
        else if (ref) {
            const r = ref;
            r.current = node;
        }
    }, [children, ref]);
    const triggerProps = { ref: mergedRef };
    const triggerElement = react_1.default.cloneElement(children, triggerProps);
    // 始终用 CnTooltip 包裹，避免 disableTooltip 切换时从「Tooltip(button)」变为「button」导致按钮被卸载重挂、图标抖动
    return (react_1.default.createElement(cn_ui_1.CnTooltip, { trigger: triggerElement, triggerType: "hover", align: "b", popupProps: disableTooltip ? { visible: false } : undefined }, tooltipContent));
});
