"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;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderText = renderText;
exports.renderLine = renderLine;
const React = __importStar(require("react"));
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
const cn_ui_1 = require("@cainiaofe/cn-ui");
const cn_utils_1 = require("../../../cn-utils");
const utils_1 = require("../../utils");
/**
 * 渲染文本内容
 * 支持纯文本、带链接、带 Tooltip 等多种形式
 */
function renderText(value) {
    var _a;
    if ((0, isPlainObject_1.default)(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 cn_utils_1.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) }, (0, utils_1.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(cn_ui_1.CnTooltip, { trigger: textDom, triggerType: "hover" }, Array.isArray(value.toolTips)
                ? renderTooltipContent(value.toolTips)
                : (0, utils_1.renderValueHandleEmpty)(value.toolTips)));
        }
        return textDom;
    }
    return (0, utils_1.renderValueHandleEmpty)(value);
}
/**
 * 渲染带 Tooltip 的行
 * @param value 值
 * @param lineNumber 行号（用于样式）
 * @param key React key
 */
function renderLine(value, lineNumber = 1, key) {
    const text = renderText(value);
    return (React.createElement("div", { key: key, className: `ctmt-line ctmt-line-${lineNumber}` },
        React.createElement(cn_ui_1.CnTooltip, { v2: true, delay: 100, align: "t", trigger: React.createElement("span", null, text) }, text)));
}
