"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllSupportFormat = exports.registerFormat = void 0;
const cn_ui_common_1 = require("@cainiaofe/cn-ui-common");
// CnFormat.registerFormat('CnArrayView', (props: CnFormatProps) => React.ReactNode)
/**
 * 注册格式
 * @param name 格式名称
 * @param render 渲染函数
 * @param lowcode 低代码配置
 */
const registerFormat = (name, render, lowcode) => {
    cn_ui_common_1.pluginManager.registerPlugin([
        {
            componentName: 'CnFormat',
            plugins: [
                {
                    name: `CnFormatPlugin-${name}`,
                    sourceCode: (props, context) => {
                        const { format } = props;
                        if ((format === null || format === void 0 ? void 0 : format.toLowerCase()) === (name === null || name === void 0 ? void 0 : name.toLowerCase()) && !(props === null || props === void 0 ? void 0 : props.cell)) {
                            props.cell = render;
                        }
                        return { props, context };
                    },
                    lowCode: lowcode || {
                        getPrototypeList: () => { },
                    },
                },
            ],
        },
    ]);
};
exports.registerFormat = registerFormat;
/**
 * 获取所有支持的格式
 * @returns 所有支持的格式
 */
const getAllSupportFormat = () => {
    // 先确保插件已加载到 registeredPlugin 中
    cn_ui_common_1.pluginManager.loadPlugins('CnFormat');
    const allGlobalPlugins = cn_ui_common_1.pluginManager.getPluginsByComponentName('CnFormat');
    const allSupportFormat = [];
    allGlobalPlugins.forEach((plugin) => {
        const { name } = plugin;
        allSupportFormat.push(name.replace('CnFormatPlugin-', '').toLowerCase());
    });
    return allSupportFormat;
};
exports.getAllSupportFormat = getAllSupportFormat;
