import { pluginManager } from '@cainiaofe/cn-ui-common';
// CnFormat.registerFormat('CnArrayView', (props: CnFormatProps) => React.ReactNode)
/**
 * 注册格式
 * @param name 格式名称
 * @param render 渲染函数
 * @param lowcode 低代码配置
 */
export const registerFormat = (name, render, lowcode) => {
    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: () => { },
                    },
                },
            ],
        },
    ]);
};
/**
 * 获取所有支持的格式
 * @returns 所有支持的格式
 */
export const getAllSupportFormat = () => {
    // 先确保插件已加载到 registeredPlugin 中
    pluginManager.loadPlugins('CnFormat');
    const allGlobalPlugins = pluginManager.getPluginsByComponentName('CnFormat');
    const allSupportFormat = [];
    allGlobalPlugins.forEach((plugin) => {
        const { name } = plugin;
        allSupportFormat.push(name.replace('CnFormatPlugin-', '').toLowerCase());
    });
    return allSupportFormat;
};
