import { createClientFields } from '../../fields/config/client.js';
import { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js';
const serverOnlyCollectionProperties = [
    'hooks',
    'access',
    'endpoints',
    'custom',
    'joins'
];
const serverOnlyUploadProperties = [
    'adminThumbnail',
    'externalFileHeaderFilter',
    'handlers',
    'modifyResponseHeaders',
    'withMetadata'
];
const serverOnlyCollectionAdminProperties = [
    'hidden',
    'baseListFilter',
    'components'
];
export const createClientCollectionConfig = ({ collection, defaultIDType, i18n, importMap })=>{
    const clientCollection = deepCopyObjectSimple(collection, true);
    clientCollection.fields = createClientFields({
        clientFields: clientCollection?.fields || [],
        defaultIDType,
        fields: collection.fields,
        i18n,
        importMap
    });
    serverOnlyCollectionProperties.forEach((key)=>{
        if (key in clientCollection) {
            delete clientCollection[key];
        }
    });
    if ('upload' in clientCollection && typeof clientCollection.upload === 'object') {
        serverOnlyUploadProperties.forEach((key)=>{
            if (key in clientCollection.upload) {
                delete clientCollection.upload[key];
            }
        });
        if ('imageSizes' in clientCollection.upload && clientCollection.upload.imageSizes.length) {
            clientCollection.upload.imageSizes = clientCollection.upload.imageSizes.map((size)=>{
                const sanitizedSize = {
                    ...size
                };
                if ('generateImageName' in sanitizedSize) {
                    delete sanitizedSize.generateImageName;
                }
                return sanitizedSize;
            });
        }
    }
    if ('auth' in clientCollection && typeof clientCollection.auth === 'object') {
        delete clientCollection.auth.strategies;
        delete clientCollection.auth.forgotPassword;
        delete clientCollection.auth.verify;
    }
    if (collection.labels) {
        Object.entries(collection.labels).forEach(([labelType, collectionLabel])=>{
            if (typeof collectionLabel === 'function') {
                clientCollection.labels[labelType] = collectionLabel({
                    t: i18n.t
                });
            }
        });
    }
    if (!clientCollection.admin) {
        clientCollection.admin = {};
    }
    serverOnlyCollectionAdminProperties.forEach((key)=>{
        if (key in clientCollection.admin) {
            delete clientCollection.admin[key];
        }
    });
    if (collection.admin.preview) {
        clientCollection.admin.preview = true;
    }
    let description = undefined;
    if (collection.admin?.description) {
        if (typeof collection.admin?.description === 'string' || typeof collection.admin?.description === 'object') {
            description = collection.admin.description;
        } else if (typeof collection.admin?.description === 'function') {
            description = collection.admin?.description({
                t: i18n.t
            });
        }
    }
    if (description) {
        clientCollection.admin.description = description;
    }
    if ('livePreview' in clientCollection.admin && clientCollection.admin.livePreview && 'url' in clientCollection.admin.livePreview) {
        delete clientCollection.admin.livePreview.url;
    }
    return clientCollection;
};
export const createClientCollectionConfigs = ({ collections, defaultIDType, i18n, importMap })=>{
    const clientCollections = new Array(collections.length);
    for(let i = 0; i < collections.length; i++){
        const collection = collections[i];
        clientCollections[i] = createClientCollectionConfig({
            collection,
            defaultIDType,
            i18n,
            importMap
        });
    }
    return clientCollections;
};

//# sourceMappingURL=client.js.map