import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_data_source_DataSourceManagerProvider_mjs__ from "../../data-source/data-source/DataSourceManagerProvider.mjs";
const getOptions = (fieldInterfaces, fieldGroups)=>Object.keys(fieldGroups).map((groupName)=>{
        const group = fieldGroups[groupName];
        return {
            ...group,
            key: groupName,
            children: Object.keys(fieldInterfaces[groupName] || {}).map((type)=>{
                const field = fieldInterfaces[groupName][type];
                return {
                    value: type,
                    label: field.title,
                    name: type,
                    ...fieldInterfaces[groupName][type]
                };
            }).sort((a, b)=>a.order - b.order)
        };
    }).sort((a, b)=>a.order - b.order);
const useFieldInterfaceOptions = ()=>{
    const dm = (0, __WEBPACK_EXTERNAL_MODULE__data_source_data_source_DataSourceManagerProvider_mjs__.useDataSourceManager)();
    return (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        const fieldInterfaceInstances = dm.collectionFieldInterfaceManager.getFieldInterfaces();
        const fieldGroups = dm.collectionFieldInterfaceManager.getFieldInterfaceGroups();
        const fieldInterfaceInstancesByGroups = fieldInterfaceInstances.reduce((memo, fieldInterface)=>{
            const group = fieldInterface.group || 'basic';
            if (!memo[group]) memo[group] = [];
            memo[group].push(fieldInterface);
            return memo;
        }, {});
        return getOptions(fieldInterfaceInstancesByGroups, fieldGroups);
    }, [
        dm
    ]);
};
export { getOptions, useFieldInterfaceOptions };
