"use strict";
/**
 * NormalFieldDriver —— 普通字段驱动
 *
 * 设计要点：
 * 1. panelKind 未设置（即无配置面板），用户点击后直接创建，无需额外配置。
 * 2. MaterializeMode = 'passive'，runtime.materialize 会直接跳过。
 * 3. remove 当前为空实现，普通字段暂不支持通过 field-system 删除。
 * 4. 通过构造函数 options 支持多种普通字段复用同一 driver 类。
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.NormalFieldDriver = void 0;
class NormalFieldDriver {
    constructor(options) {
        this.options = { order: 200, ...options };
    }
    getMeta() {
        var _a;
        return {
            type: this.options.type,
            label: this.options.label,
            category: 'regular',
            order: (_a = this.options.order) !== null && _a !== void 0 ? _a : 200,
            icon: this.options.icon,
            iconType: this.options.iconType || 'regular',
            iconColor: this.options.iconColor,
            materializeMode: 'passive',
        };
    }
    getUiContribution() {
        const meta = this.getMeta();
        return {
            selectorItem: {
                type: meta.type,
                label: meta.label,
                icon: meta.icon,
                iconType: meta.iconType,
                color: meta.iconColor,
                category: meta.category,
                order: meta.order,
            },
        };
    }
    createDefaultConfig() {
        return {};
    }
    validateConfig() {
        return { valid: true };
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    async persistMeta(config, ctx) {
        const meta = this.getMeta();
        const id = `field_${meta.type}_${Date.now()}`;
        return {
            id,
            type: meta.type,
            name: meta.label,
            config: {},
            runtime: { mode: 'passive' },
        };
    }
    buildColumnDef(record, ctx) {
        const colDef = {
            dataIndex: record.id,
            title: record.name,
            header: record.name,
            accessorKey: record.id,
        };
        ctx.dataModel.addColumn(colDef);
        return colDef;
    }
    attachToView(record, ctx) {
        const viewConfig = ctx.dataModel.getViewConfig(ctx.viewId);
        const currentColumnOrder = viewConfig.columnOrder || [];
        const nextColumnOrder = currentColumnOrder.includes(record.id)
            ? currentColumnOrder
            : [...currentColumnOrder, record.id];
        ctx.dataModel.setViewConfig(ctx.viewId, { columnOrder: nextColumnOrder }, true);
        const newData = ctx.dataModel.rawData.map((row) => ({
            ...row,
            [record.id]: '',
        }));
        ctx.dataModel.setRawData(newData);
    }
    async materializeData() {
        // passive — noop
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    async remove(columnId, ctx) {
        // 当前普通字段不支持删除
    }
}
exports.NormalFieldDriver = NormalFieldDriver;
