/**
 * 行选择插件注册
 *
 * priority 10：在操作列之前执行，保证行选择状态先就绪。
 * 数据源统一读取 pipeline context 中的 visibleData（筛选后），
 * 由 NormalTableView 在 runPlugins 前注入。
 */
import { registerPlugin } from '../../pipeline';
import { rowSelectionPlugin } from './index';
import { EVENT_NAMES } from '../../../../../../../cn-ai-agent/constants/event-constants';
import { DEFAULT_PRIMARY_KEY } from '../../../../../../../cn-ai-table/view/utils/primary-key';
registerPlugin('RowSelection', (props, pipeline, context) => {
    var _a, _b, _c;
    const { rowSelectionProps } = props;
    const { dataModel } = context;
    if (!(rowSelectionProps === null || rowSelectionProps === void 0 ? void 0 : rowSelectionProps.hasSelect)) {
        return;
    }
    // 优先使用调用方预注入的 visibleData（筛选后），兜底 rawData
    const visibleData = (_a = pipeline.getContext('visibleData')) !== null && _a !== void 0 ? _a : dataModel.rawData;
    const disabledRowKeys = (_b = pipeline.getContext('disabledRowKeys')) !== null && _b !== void 0 ? _b : new Set();
    const plugin = rowSelectionPlugin({
        enabled: rowSelectionProps.hasSelect,
        selectionType: rowSelectionProps.selectionType || 'multiple',
        selectedKeys: rowSelectionProps.selectKeys || [],
        primaryKey: rowSelectionProps.primaryKey || DEFAULT_PRIMARY_KEY,
        dataSource: visibleData,
        setSelectKeys: rowSelectionProps.setSelectKeys,
        disabledRowKeys,
        eventNames: (_c = props.cnAiListEventNames) !== null && _c !== void 0 ? _c : EVENT_NAMES,
    });
    plugin(pipeline);
}, 10);
