import dayjs from 'dayjs';
import _ from 'lodash';

export default {
    filesFormatter(arr) {
        if (!arr || !arr.length) return [];
        return arr.map((item) => item);
    },
    imageFormatter(arr) {
        if (!arr || !arr.length) return []
        return arr.map(item => ({
            publicUrl: item.publicUrl || ''
        }))
    },
    oneImageFormatter(arr) {
        if (!arr || !arr.length) return ''
        return arr[0].publicUrl || ''
    },
    dateFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD')
    },
    dateTimeFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD HH:mm')
    },
    booleanFormatter(val) {
        return val ? 'Yes' : 'No'
    },
    dataGridEditFormatter(obj) {
        return _.transform(obj, (result, value, key) => {
            if (_.isArray(value)) {
                result[key] = _.map(value, 'id');
            } else if (_.isObject(value)) {
                result[key] = value.id;
            } else {
                result[key] = value;
            }
        });
    },
    
        
        usersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.firstName)
        },
        usersOneListFormatter(val) {
            if (!val) return ''
            return val.firstName
        },
        usersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.firstName}
            });
        },
        usersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.firstName, id: val.id}
        },
        
    
        
        rolesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        rolesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        rolesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        rolesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        permissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        permissionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        permissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        permissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        membershipsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        membershipsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        membershipsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        membershipsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
        eventsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        eventsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        eventsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        eventsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        albumsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        albumsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        albumsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        albumsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        album_collaboratorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.role)
        },
        album_collaboratorsOneListFormatter(val) {
            if (!val) return ''
            return val.role
        },
        album_collaboratorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.role}
            });
        },
        album_collaboratorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.role, id: val.id}
        },
        
    
        
        access_rulesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.permission)
        },
        access_rulesOneListFormatter(val) {
            if (!val) return ''
            return val.permission
        },
        access_rulesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.permission}
            });
        },
        access_rulesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.permission, id: val.id}
        },
        
    
        
        media_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        media_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        media_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        media_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        storage_bucketsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.bucket_name)
        },
        storage_bucketsOneListFormatter(val) {
            if (!val) return ''
            return val.bucket_name
        },
        storage_bucketsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.bucket_name}
            });
        },
        storage_bucketsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.bucket_name, id: val.id}
        },
        
    
        
        storage_objectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.object_key)
        },
        storage_objectsOneListFormatter(val) {
            if (!val) return ''
            return val.object_key
        },
        storage_objectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.object_key}
            });
        },
        storage_objectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.object_key, id: val.id}
        },
        
    
        
        upload_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        upload_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        upload_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        upload_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
        upload_filesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.file_name)
        },
        upload_filesOneListFormatter(val) {
            if (!val) return ''
            return val.file_name
        },
        upload_filesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.file_name}
            });
        },
        upload_filesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.file_name, id: val.id}
        },
        
    
        
        tagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        tagsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        tagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        tagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        media_ai_tagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.source)
        },
        media_ai_tagsOneListFormatter(val) {
            if (!val) return ''
            return val.source
        },
        media_ai_tagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.source}
            });
        },
        media_ai_tagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.source, id: val.id}
        },
        
    
        
        media_user_tagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tagged_by)
        },
        media_user_tagsOneListFormatter(val) {
            if (!val) return ''
            return val.tagged_by
        },
        media_user_tagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tagged_by}
            });
        },
        media_user_tagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tagged_by, id: val.id}
        },
        
    
        
        likesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.liked_at)
        },
        likesOneListFormatter(val) {
            if (!val) return ''
            return val.liked_at
        },
        likesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.liked_at}
            });
        },
        likesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.liked_at, id: val.id}
        },
        
    
        
        favouritesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.saved_at)
        },
        favouritesOneListFormatter(val) {
            if (!val) return ''
            return val.saved_at
        },
        favouritesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.saved_at}
            });
        },
        favouritesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.saved_at, id: val.id}
        },
        
    
        
        commentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.content)
        },
        commentsOneListFormatter(val) {
            if (!val) return ''
            return val.content
        },
        commentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.content}
            });
        },
        commentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.content, id: val.id}
        },
        
    
        
        mentionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.mentioned_user)
        },
        mentionsOneListFormatter(val) {
            if (!val) return ''
            return val.mentioned_user
        },
        mentionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.mentioned_user}
            });
        },
        mentionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.mentioned_user, id: val.id}
        },
        
    
        
    
        
    
        
        sharesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.token)
        },
        sharesOneListFormatter(val) {
            if (!val) return ''
            return val.token
        },
        sharesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.token}
            });
        },
        sharesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.token, id: val.id}
        },
        
    
        
        download_jobsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        download_jobsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        download_jobsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        download_jobsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
        watermark_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        watermark_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        watermark_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        watermark_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        ai_modelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        ai_modelsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        ai_modelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        ai_modelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        ai_embeddingsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.vector_ref)
        },
        ai_embeddingsOneListFormatter(val) {
            if (!val) return ''
            return val.vector_ref
        },
        ai_embeddingsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.vector_ref}
            });
        },
        ai_embeddingsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.vector_ref, id: val.id}
        },
        
    
        
        face_detectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.confidence)
        },
        face_detectionsOneListFormatter(val) {
            if (!val) return ''
            return val.confidence
        },
        face_detectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.confidence}
            });
        },
        face_detectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.confidence, id: val.id}
        },
        
    
        
        selfie_referencesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        selfie_referencesOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        selfie_referencesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        selfie_referencesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        storiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        storiesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        storiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        storiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        story_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.layout)
        },
        story_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.layout
        },
        story_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.layout}
            });
        },
        story_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.layout, id: val.id}
        },
        
    
        
    
        
    
}
