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}
        },
        
    
        
        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}
        },
        
    
        
        guarantorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        guarantorsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        guarantorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        guarantorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        doctorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        doctorsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        doctorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        doctorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        visitsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.visit_number)
        },
        visitsOneListFormatter(val) {
            if (!val) return ''
            return val.visit_number
        },
        visitsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.visit_number}
            });
        },
        visitsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.visit_number, id: val.id}
        },
        
    
        
        ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.order_number)
        },
        ordersOneListFormatter(val) {
            if (!val) return ''
            return val.order_number
        },
        ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.order_number}
            });
        },
        ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.order_number, id: val.id}
        },
        
    
        
        radiology_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        radiology_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        radiology_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        radiology_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        ct_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        ct_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        ct_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        ct_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        lab_testsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        lab_testsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        lab_testsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        lab_testsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        lab_ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.lab_order_number)
        },
        lab_ordersOneListFormatter(val) {
            if (!val) return ''
            return val.lab_order_number
        },
        lab_ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.lab_order_number}
            });
        },
        lab_ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.lab_order_number, id: val.id}
        },
        
    
        
    
        
    
        
        surgery_casesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.case_number)
        },
        surgery_casesOneListFormatter(val) {
            if (!val) return ''
            return val.case_number
        },
        surgery_casesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.case_number}
            });
        },
        surgery_casesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.case_number, id: val.id}
        },
        
    
        
        surgery_consumablesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        surgery_consumablesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        surgery_consumablesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        surgery_consumablesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        nursing_staffManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        nursing_staffOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        nursing_staffManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        nursing_staffOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        inpatient_roomsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.room_number)
        },
        inpatient_roomsOneListFormatter(val) {
            if (!val) return ''
            return val.room_number
        },
        inpatient_roomsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.room_number}
            });
        },
        inpatient_roomsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.room_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
