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}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        doctor_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.specialization)
        },
        doctor_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.specialization
        },
        doctor_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.specialization}
            });
        },
        doctor_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.specialization, id: val.id}
        },
        
    
        
        patient_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.patient_identifier)
        },
        patient_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.patient_identifier
        },
        patient_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.patient_identifier}
            });
        },
        patient_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.patient_identifier, 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}
        },
        
    
        
        appointmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reason)
        },
        appointmentsOneListFormatter(val) {
            if (!val) return ''
            return val.reason
        },
        appointmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reason}
            });
        },
        appointmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reason, id: val.id}
        },
        
    
        
        consultationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.chief_complaint)
        },
        consultationsOneListFormatter(val) {
            if (!val) return ''
            return val.chief_complaint
        },
        consultationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.chief_complaint}
            });
        },
        consultationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.chief_complaint, 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}
        },
        
    
        
    
        
        prescriptionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        prescriptionsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        prescriptionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        prescriptionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
        prescription_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.frequency)
        },
        prescription_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.frequency
        },
        prescription_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.frequency}
            });
        },
        prescription_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.frequency, id: val.id}
        },
        
    
        
    
        
        vaccinationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.vaccine_name)
        },
        vaccinationsOneListFormatter(val) {
            if (!val) return ''
            return val.vaccine_name
        },
        vaccinationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.vaccine_name}
            });
        },
        vaccinationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.vaccine_name, id: val.id}
        },
        
    
        
        patient_vaccinationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        patient_vaccinationsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        patient_vaccinationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        patient_vaccinationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
        chat_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.session_status)
        },
        chat_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.session_status
        },
        chat_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.session_status}
            });
        },
        chat_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.session_status, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
