import { cache } from 'react';
import { buildClientFieldSchemaMap } from './buildClientFieldSchemaMap/index.js';
let cachedClientSchemaMap = global._payload_clientSchemaMap;
if (!cachedClientSchemaMap) {
    cachedClientSchemaMap = global._payload_clientSchemaMap = null;
}
export const getClientSchemaMap = cache((args)=>{
    const { collectionSlug, config, globalSlug, i18n, payload, schemaMap, widgetSlug } = args;
    if (!cachedClientSchemaMap || global._payload_doNotCacheClientSchemaMap) {
        cachedClientSchemaMap = new Map();
    }
    const cacheKey = collectionSlug || globalSlug || `widget:${widgetSlug}`;
    let cachedEntityClientFieldMap = cachedClientSchemaMap.get(cacheKey);
    if (cachedEntityClientFieldMap) {
        return cachedEntityClientFieldMap;
    }
    cachedEntityClientFieldMap = new Map();
    const { clientFieldSchemaMap: entityClientFieldMap } = buildClientFieldSchemaMap({
        collectionSlug,
        config,
        globalSlug,
        i18n: i18n,
        payload,
        schemaMap,
        widgetSlug
    });
    cachedClientSchemaMap.set(cacheKey, entityClientFieldMap);
    global._payload_clientSchemaMap = cachedClientSchemaMap;
    global._payload_doNotCacheClientSchemaMap = false;
    return entityClientFieldMap;
});

//# sourceMappingURL=getClientSchemaMap.js.map