import $i18n from '../../../../../locales/i18n.js';
import React from 'react';
/**
 * 卡片渲染 Hook
 * 提取卡片内容和标题的渲染逻辑
 */
export function useCardRender({ displayColumns, showFieldTitle, renderCellValue, }) {
    // 渲染卡片内容
    const renderCardContent = React.useCallback((item, rowIndex) => {
        return (React.createElement("div", { className: "card-description" }, displayColumns.map((col) => {
            const value = item[col.dataIndex];
            const displayValue = renderCellValue(col, value, rowIndex, item);
            const hasTitle = showFieldTitle;
            return (React.createElement("div", { key: col.dataIndex, className: `card-description-item ${hasTitle ? 'card-description-item-with-title' : 'card-description-item-no-title'}` },
                hasTitle && React.createElement("div", { className: "card-description-label" }, col.title),
                React.createElement("div", { className: `card-description-value ${hasTitle
                        ? 'card-description-value-with-title'
                        : 'card-description-value-no-title'}` }, displayValue)));
        })));
    }, [displayColumns, renderCellValue, showFieldTitle]);
    // 渲染卡片标题
    const renderCardTitle = React.useCallback((item, rowIndex) => {
        const titleField = displayColumns.find((col) => {
            const value = item[col.dataIndex];
            return value !== null && value !== undefined && value !== '';
        });
        if (!titleField) {
            return $i18n.get({ id: 'Untitled', dm: '无标题' });
        }
        const titleValue = item[titleField.dataIndex];
        const displayContent = renderCellValue(titleField, titleValue, rowIndex, item);
        // 提取纯文本用于 title 属性（悬浮显示完整内容）
        const titleText = typeof titleValue === 'string' ? titleValue : String(titleValue !== null && titleValue !== void 0 ? titleValue : '');
        return React.createElement("span", { title: titleText }, displayContent);
    }, [displayColumns, renderCellValue]);
    return {
        renderCardContent,
        renderCardTitle,
    };
}
