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}
        },
        
    
        
    
        
    
        
        mattersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        mattersOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        mattersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        mattersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        filesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.file_name)
        },
        filesOneListFormatter(val) {
            if (!val) return ''
            return val.file_name
        },
        filesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.file_name}
            });
        },
        filesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.file_name, id: val.id}
        },
        
    
        
    
        
        assistant_threadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        assistant_threadsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        assistant_threadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        assistant_threadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
        legal_templatesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.template_name)
        },
        legal_templatesOneListFormatter(val) {
            if (!val) return ''
            return val.template_name
        },
        legal_templatesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.template_name}
            });
        },
        legal_templatesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.template_name, id: val.id}
        },
        
    
        
    
        
        generated_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.document_title)
        },
        generated_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.document_title
        },
        generated_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.document_title}
            });
        },
        generated_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.document_title, id: val.id}
        },
        
    
        
    
        
        research_queriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.jurisdiction)
        },
        research_queriesOneListFormatter(val) {
            if (!val) return ''
            return val.jurisdiction
        },
        research_queriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.jurisdiction}
            });
        },
        research_queriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.jurisdiction, id: val.id}
        },
        
    
        
        legal_sourcesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        legal_sourcesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        legal_sourcesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        legal_sourcesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
        mock_trialsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.session_title)
        },
        mock_trialsOneListFormatter(val) {
            if (!val) return ''
            return val.session_title
        },
        mock_trialsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.session_title}
            });
        },
        mock_trialsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.session_title, id: val.id}
        },
        
    
        
        mock_trial_rolesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.display_name)
        },
        mock_trial_rolesOneListFormatter(val) {
            if (!val) return ''
            return val.display_name
        },
        mock_trial_rolesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.display_name}
            });
        },
        mock_trial_rolesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.display_name, id: val.id}
        },
        
    
        
    
        
    
        
        medical_chronology_reportsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.report_title)
        },
        medical_chronology_reportsOneListFormatter(val) {
            if (!val) return ''
            return val.report_title
        },
        medical_chronology_reportsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.report_title}
            });
        },
        medical_chronology_reportsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.report_title, id: val.id}
        },
        
    
        
    
        
    
        
    
}
