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}
        },
        
    
        
        commentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.body)
        },
        commentsOneListFormatter(val) {
            if (!val) return ''
            return val.body
        },
        commentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.body}
            });
        },
        commentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.body, id: val.id}
        },
        
    
        
    
        
        storiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.text_overlay)
        },
        storiesOneListFormatter(val) {
            if (!val) return ''
            return val.text_overlay
        },
        storiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.text_overlay}
            });
        },
        storiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.text_overlay, id: val.id}
        },
        
    
        
        conversationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        conversationsOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        conversationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        conversationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, 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}
        },
        
    
        
        groupsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_text)
        },
        groupsOneListFormatter(val) {
            if (!val) return ''
            return val.name_text
        },
        groupsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_text}
            });
        },
        groupsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_text, id: val.id}
        },
        
    
        
        eventsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        eventsOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        eventsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        eventsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
        ticketsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.ticket_code)
        },
        ticketsOneListFormatter(val) {
            if (!val) return ''
            return val.ticket_code
        },
        ticketsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.ticket_code}
            });
        },
        ticketsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.ticket_code, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        hashtagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tag_text)
        },
        hashtagsOneListFormatter(val) {
            if (!val) return ''
            return val.tag_text
        },
        hashtagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tag_text}
            });
        },
        hashtagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tag_text, id: val.id}
        },
        
    
        
    
        
    
        
        live_streamsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        live_streamsOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        live_streamsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        live_streamsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        gamification_badgesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_text)
        },
        gamification_badgesOneListFormatter(val) {
            if (!val) return ''
            return val.name_text
        },
        gamification_badgesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_text}
            });
        },
        gamification_badgesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_text, id: val.id}
        },
        
    
        
    
}
