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}
        },
        
    
        
        user_photosManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.photo)
        },
        user_photosOneListFormatter(val) {
            if (!val) return ''
            return val.photo
        },
        user_photosManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.photo}
            });
        },
        user_photosOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.photo, id: val.id}
        },
        
    
        
        languagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        languagesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        languagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        languagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        interestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        interestsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        interestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        interestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        matchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.is_active)
        },
        matchesOneListFormatter(val) {
            if (!val) return ''
            return val.is_active
        },
        matchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.is_active}
            });
        },
        matchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.is_active, 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}
        },
        
    
        
    
        
    
        
        reportsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.details)
        },
        reportsOneListFormatter(val) {
            if (!val) return ''
            return val.details
        },
        reportsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.details}
            });
        },
        reportsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.details, id: val.id}
        },
        
    
        
        report_attachmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.content_type)
        },
        report_attachmentsOneListFormatter(val) {
            if (!val) return ''
            return val.content_type
        },
        report_attachmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.content_type}
            });
        },
        report_attachmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.content_type, id: val.id}
        },
        
    
        
    
        
        daily_sparksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.generation_model)
        },
        daily_sparksOneListFormatter(val) {
            if (!val) return ''
            return val.generation_model
        },
        daily_sparksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.generation_model}
            });
        },
        daily_sparksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.generation_model, id: val.id}
        },
        
    
        
    
        
        premium_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        premium_plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        premium_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        premium_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        admin_usersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.display_name)
        },
        admin_usersOneListFormatter(val) {
            if (!val) return ''
            return val.display_name
        },
        admin_usersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.display_name}
            });
        },
        admin_usersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.display_name, id: val.id}
        },
        
    
        
    
}
