import * as React from 'react';
import isPlainObject from 'lodash/isPlainObject';
import { CnTooltip } from '@cainiaofe/cn-ui';
import { domStyleMap } from '../../../cn-utils';
import { renderValueHandleEmpty } from '../../utils';
/**
 * 渲染文本内容
 * 支持纯文本、带链接、带 Tooltip 等多种形式
 */
export function renderText(value) {
    var _a;
    if (isPlainObject(value)) {
        // 对象传入，目前支持 ToolTips, link
        const linkStyle = (value === null || value === void 0 ? void 0 : value.link) ? { color: '#284cc0' } : {};
        const styleAttribute = Object.keys(value).reduce((pre, cur) => {
            if (cur in domStyleMap) {
                pre[cur] = value[cur];
            }
            return pre;
        }, {});
        const textDom = (React.createElement("span", { style: { ...linkStyle, ...styleAttribute }, onClick: () => (value === null || value === void 0 ? void 0 : value.link) && window.open(value === null || value === void 0 ? void 0 : value.link) }, renderValueHandleEmpty((_a = value.value) !== null && _a !== void 0 ? _a : value.text)));
        if (value === null || value === void 0 ? void 0 : value.toolTips) {
            const renderTooltipContent = (data) => (React.createElement("div", null, data.map((item, index) => (React.createElement("div", { key: index }, item.desc)))));
            return (React.createElement(CnTooltip, { trigger: textDom, triggerType: "hover" }, Array.isArray(value.toolTips)
                ? renderTooltipContent(value.toolTips)
                : renderValueHandleEmpty(value.toolTips)));
        }
        return textDom;
    }
    return renderValueHandleEmpty(value);
}
/**
 * 渲染带 Tooltip 的行
 * @param value 值
 * @param lineNumber 行号（用于样式）
 * @param key React key
 */
export function renderLine(value, lineNumber = 1, key) {
    const text = renderText(value);
    return (React.createElement("div", { key: key, className: `ctmt-line ctmt-line-${lineNumber}` },
        React.createElement(CnTooltip, { v2: true, delay: 100, align: "t", trigger: React.createElement("span", null, text) }, text)));
}
