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}
        },
        
    
        
        adminsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        adminsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        adminsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        adminsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        city_doctorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        city_doctorsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        city_doctorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        city_doctorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        rural_doctorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        rural_doctorsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        rural_doctorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        rural_doctorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        patientsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        patientsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        patientsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        patientsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        medical_reportsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.diagnosis)
        },
        medical_reportsOneListFormatter(val) {
            if (!val) return ''
            return val.diagnosis
        },
        medical_reportsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.diagnosis}
            });
        },
        medical_reportsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.diagnosis, id: val.id}
        },
        
    
        
        medicinesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.medicine_name)
        },
        medicinesOneListFormatter(val) {
            if (!val) return ''
            return val.medicine_name
        },
        medicinesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.medicine_name}
            });
        },
        medicinesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.medicine_name, id: val.id}
        },
        
    
        
    
        
        medicine_dispatchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tracking_reference)
        },
        medicine_dispatchesOneListFormatter(val) {
            if (!val) return ''
            return val.tracking_reference
        },
        medicine_dispatchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tracking_reference}
            });
        },
        medicine_dispatchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tracking_reference, id: val.id}
        },
        
    
        
    
        
        medical_campsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.camp_name)
        },
        medical_campsOneListFormatter(val) {
            if (!val) return ''
            return val.camp_name
        },
        medical_campsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.camp_name}
            });
        },
        medical_campsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.camp_name, id: val.id}
        },
        
    
        
    
        
        chat_threadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.thread_title)
        },
        chat_threadsOneListFormatter(val) {
            if (!val) return ''
            return val.thread_title
        },
        chat_threadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.thread_title}
            });
        },
        chat_threadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.thread_title, id: val.id}
        },
        
    
        
    
        
    
        
        trucksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.truck_code)
        },
        trucksOneListFormatter(val) {
            if (!val) return ''
            return val.truck_code
        },
        trucksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.truck_code}
            });
        },
        trucksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.truck_code, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        ai_chat_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.summary)
        },
        ai_chat_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.summary
        },
        ai_chat_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.summary}
            });
        },
        ai_chat_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.summary, id: val.id}
        },
        
    
        
    
        
    
}
