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}
        },
        
    
        
    
        
        postsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.caption)
        },
        postsOneListFormatter(val) {
            if (!val) return ''
            return val.caption
        },
        postsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.caption}
            });
        },
        postsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.caption, id: val.id}
        },
        
    
        
        post_commentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.body)
        },
        post_commentsOneListFormatter(val) {
            if (!val) return ''
            return val.body
        },
        post_commentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.body}
            });
        },
        post_commentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.body, id: val.id}
        },
        
    
        
    
        
    
        
        save_collectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        save_collectionsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        save_collectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        save_collectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        hashtagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tag)
        },
        hashtagsOneListFormatter(val) {
            if (!val) return ''
            return val.tag
        },
        hashtagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tag}
            });
        },
        hashtagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tag, id: val.id}
        },
        
    
        
    
        
        storiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.caption)
        },
        storiesOneListFormatter(val) {
            if (!val) return ''
            return val.caption
        },
        storiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.caption}
            });
        },
        storiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.caption, id: val.id}
        },
        
    
        
    
        
        highlightsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        highlightsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        highlightsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        highlightsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        reelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.caption)
        },
        reelsOneListFormatter(val) {
            if (!val) return ''
            return val.caption
        },
        reelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.caption}
            });
        },
        reelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.caption, id: val.id}
        },
        
    
        
    
        
        reel_commentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.body)
        },
        reel_commentsOneListFormatter(val) {
            if (!val) return ''
            return val.body
        },
        reel_commentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.body}
            });
        },
        reel_commentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.body, id: val.id}
        },
        
    
        
        conversationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        conversationsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        conversationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        conversationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        messagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.body)
        },
        messagesOneListFormatter(val) {
            if (!val) return ''
            return val.body
        },
        messagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.body}
            });
        },
        messagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.body, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
}
