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}
        },
        
    
        
        skillsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        skillsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        skillsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        skillsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        service_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        service_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        service_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        service_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.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}
        },
        
    
        
    
        
        jobsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        jobsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        jobsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        jobsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        job_attachmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.caption)
        },
        job_attachmentsOneListFormatter(val) {
            if (!val) return ''
            return val.caption
        },
        job_attachmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.caption}
            });
        },
        job_attachmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.caption, id: val.id}
        },
        
    
        
        proposalsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.cover_letter)
        },
        proposalsOneListFormatter(val) {
            if (!val) return ''
            return val.cover_letter
        },
        proposalsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.cover_letter}
            });
        },
        proposalsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.cover_letter, id: val.id}
        },
        
    
        
        contractsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.terms)
        },
        contractsOneListFormatter(val) {
            if (!val) return ''
            return val.terms
        },
        contractsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.terms}
            });
        },
        contractsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.terms, id: val.id}
        },
        
    
        
        milestonesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        milestonesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        milestonesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        milestonesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        conversationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        conversationsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        conversationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        conversationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
    
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_reference)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.provider_reference
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_reference}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_reference, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        ai_toolsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        ai_toolsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        ai_toolsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        ai_toolsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
}
