"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.createAiGenerateFormat = exports.AI_GENERATING_MARKER = void 0;
const i18n_1 = __importDefault(require("../../../../../../../../locales/i18n.js"));
const React = __importStar(require("react"));
const isNil_1 = __importDefault(require("lodash/isNil"));
const cn_ui_1 = require("@cainiaofe/cn-ui");
const stark_data_1 = require("@ice/stark-data");
const cn_ai_list_event_context_1 = require("../../../../../../../../cn-ai-agent/context/cn-ai-list-event-context");
const ai_cell_constants_1 = require("../../../../../../../../cn-ai-table/view/constants/ai-cell-constants");
Object.defineProperty(exports, "AI_GENERATING_MARKER", { enumerable: true, get: function () { return ai_cell_constants_1.AI_GENERATING_MARKER; } });
const icons_1 = require("../../../../../../../../cn-ai-table/view/components/icons");
const arms_hot_tag_log_1 = require("../../../../../../../../utils/arms/arms-hot-tag-log.js");
require("../styles/index.scss");
function AiGenerateTrigger({ columnCode, aiConfig, record, rowIndex, }) {
    const eventNames = (0, cn_ai_list_event_context_1.useCnAiListEventNames)();
    const handleGenerate = (e) => {
        e.stopPropagation();
        (0, arms_hot_tag_log_1.armsHottagLog)({
            hottag: 'cn-ai-table.aiField.generate',
            name: i18n_1.default.get({ id: 'GenerateImmediately', dm: '立即生成' }),
            c6: String(rowIndex),
            c7: columnCode,
        });
        stark_data_1.event.emit(eventNames.SUBMIT_SINGLE_CELL_AI_TASK, {
            columnCode,
            aiConfig,
            record,
            rowIndex,
        });
    };
    return (React.createElement("div", { className: "cn-table-cell-format-ai-generate" },
        React.createElement(cn_ui_1.CnButton, { type: "normal", size: "small", onClick: handleGenerate, style: {
                padding: '0 8px',
                height: '24px',
                fontSize: '12px',
            } }, i18n_1.default.get({ id: 'GenerateImmediately', dm: '立即生成' }))));
}
/**
 * AI 字段（generate-text）格式化工厂函数
 * - 空值时显示"生成"按钮，点击触发 AI 生成任务
 * - 生成中时显示 loading 状态
 * - 有值时正常显示文本（带 Tooltip）
 */
const createAiGenerateFormat = (column) => {
    const { dataIndex, aiConfig } = column;
    const columnCode = dataIndex || column.accessorKey;
    return {
        cell(value, rowIndex, record) {
            // 生成中状态：显示 loading
            if (value === ai_cell_constants_1.AI_GENERATING_MARKER) {
                return (React.createElement("div", { className: "cn-table-cell-format-ai-generating" },
                    React.createElement("div", { className: "cn-table-cell-format-ai-generating-content" },
                        React.createElement(icons_1.SvgIcon, { name: "aiSparkle", size: 16 }),
                        React.createElement("span", { style: { color: '#999', fontSize: '12px' } }, i18n_1.default.get({ id: 'Generating', dm: '生成中' })))));
            }
            // 空值时显示"生成"按钮
            if ((0, isNil_1.default)(value) || value === '') {
                if (!columnCode) {
                    return null;
                }
                return (React.createElement(AiGenerateTrigger, { columnCode: columnCode, aiConfig: aiConfig, record: record, rowIndex: rowIndex }));
            }
            // 有值时显示文本（带 Tooltip）
            const textValue = typeof value === 'string' ? value : String(value);
            return React.createElement("span", null, textValue);
        },
    };
};
exports.createAiGenerateFormat = createAiGenerateFormat;
exports.default = exports.createAiGenerateFormat;
