export const sanitizeField = (f)=>{
    const field = {
        ...f
    };
    const serverOnlyFieldProperties = [
        'hooks',
        'access',
        'validate',
        'defaultValue',
        'label',
        // This is a `richText` only property
        'editor'
    ];
    serverOnlyFieldProperties.forEach((key)=>{
        if (key in field) {
            delete field[key];
        }
    });
    if ('fields' in field) {
        field.fields = sanitizeFields(field.fields);
    }
    if ('blocks' in field) {
        field.blocks = field.blocks.map((block)=>{
            const sanitized = {
                ...block
            };
            sanitized.fields = sanitizeFields(sanitized.fields);
            return sanitized;
        });
    }
    if ('tabs' in field) {
        // @ts-expect-error
        field.tabs = field.tabs.map((tab)=>sanitizeField(tab));
    }
    if ('admin' in field) {
        field.admin = {
            ...field.admin
        };
        const serverOnlyFieldAdminProperties = [
            'components',
            'condition',
            'description'
        ];
        serverOnlyFieldAdminProperties.forEach((key)=>{
            if (key in field.admin) {
                delete field.admin[key];
            }
        });
    }
    return field;
};
const sanitizeCollections = (collections)=>collections.map((collection)=>{
        const sanitized = {
            ...collection
        };
        sanitized.fields = sanitizeFields(sanitized.fields);
        const serverOnlyCollectionProperties = [
            'hooks',
            'access',
            'endpoints'
        ];
        serverOnlyCollectionProperties.forEach((key)=>{
            if (key in sanitized) {
                delete sanitized[key];
            }
        });
        if ('upload' in sanitized && typeof sanitized.upload === 'object') {
            sanitized.upload = {
                ...sanitized.upload
            };
            delete sanitized.upload.handlers;
        }
        if ('admin' in sanitized) {
            sanitized.admin = {
                ...sanitized.admin
            };
            const serverOnlyCollectionAdminProperties = [
                'components',
                'hidden',
                'preview'
            ];
            serverOnlyCollectionAdminProperties.forEach((key)=>{
                if (key in sanitized.admin) {
                    delete sanitized.admin[key];
                }
            });
        }
        return sanitized;
    });
const sanitizeGlobals = (globals)=>globals.map((global)=>{
        const sanitized = {
            ...global
        };
        sanitized.fields = sanitizeFields(sanitized.fields);
        const serverOnlyProperties = [
            'hooks',
            'access',
            'endpoints'
        ];
        serverOnlyProperties.forEach((key)=>{
            if (key in sanitized) {
                delete sanitized[key];
            }
        });
        if ('admin' in sanitized) {
            sanitized.admin = {
                ...sanitized.admin
            };
            const serverOnlyProperties = [
                'components',
                'hidden',
                'preview'
            ];
            serverOnlyProperties.forEach((key)=>{
                if (key in sanitized.admin) {
                    delete sanitized.admin[key];
                }
            });
        }
        return sanitized;
    });
export const sanitizeFields = (fields)=>fields.map(sanitizeField);
export const createClientConfig = async (configPromise)=>{
    const config = await configPromise;
    const clientConfig = {
        ...config
    };
    const serverOnlyConfigProperties = [
        'endpoints',
        'db',
        'editor',
        'plugins',
        'sharp'
    ];
    serverOnlyConfigProperties.forEach((key)=>{
        if (key in clientConfig) {
            delete clientConfig[key];
        }
    });
    if ('localization' in clientConfig && clientConfig.localization) {
        clientConfig.localization = {
            ...clientConfig.localization
        };
        clientConfig.localization.locales.forEach((locale)=>{
            delete locale.toString;
        });
    }
    if ('admin' in clientConfig) {
        clientConfig.admin = {
            ...clientConfig.admin
        };
        const serverOnlyAdminProperties = [
            'components'
        ];
        serverOnlyAdminProperties.forEach((key)=>{
            if (key in clientConfig.admin) {
                delete clientConfig.admin[key];
            }
        });
    }
    clientConfig.onInit = undefined;
    clientConfig.collections = sanitizeCollections(clientConfig.collections);
    clientConfig.globals = sanitizeGlobals(clientConfig.globals);
    return clientConfig;
};

//# sourceMappingURL=createClientConfig.js.map