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}
        },
        
    
        
        accountsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        accountsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        accountsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        accountsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        patientsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.last_name)
        },
        patientsOneListFormatter(val) {
            if (!val) return ''
            return val.last_name
        },
        patientsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.last_name}
            });
        },
        patientsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.last_name, id: val.id}
        },
        
    
        
    
        
        medicationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.medication_name)
        },
        medicationsOneListFormatter(val) {
            if (!val) return ''
            return val.medication_name
        },
        medicationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.medication_name}
            });
        },
        medicationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.medication_name, id: val.id}
        },
        
    
        
    
        
        calendar_eventsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        calendar_eventsOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        calendar_eventsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        calendar_eventsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
    
        
        cognitive_programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.program_name)
        },
        cognitive_programsOneListFormatter(val) {
            if (!val) return ''
            return val.program_name
        },
        cognitive_programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.program_name}
            });
        },
        cognitive_programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.program_name, id: val.id}
        },
        
    
        
        cognitive_exercisesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.exercise_name)
        },
        cognitive_exercisesOneListFormatter(val) {
            if (!val) return ''
            return val.exercise_name
        },
        cognitive_exercisesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.exercise_name}
            });
        },
        cognitive_exercisesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.exercise_name, id: val.id}
        },
        
    
        
        cognitive_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.completion_status)
        },
        cognitive_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.completion_status
        },
        cognitive_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.completion_status}
            });
        },
        cognitive_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.completion_status, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        iot_devicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.device_label)
        },
        iot_devicesOneListFormatter(val) {
            if (!val) return ''
            return val.device_label
        },
        iot_devicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.device_label}
            });
        },
        iot_devicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.device_label, id: val.id}
        },
        
    
        
        iot_telemetry_eventsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.event_kind)
        },
        iot_telemetry_eventsOneListFormatter(val) {
            if (!val) return ''
            return val.event_kind
        },
        iot_telemetry_eventsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.event_kind}
            });
        },
        iot_telemetry_eventsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.event_kind, id: val.id}
        },
        
    
        
    
        
        alertsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        alertsOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        alertsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        alertsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
    
        
    
        
        scientific_articlesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        scientific_articlesOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        scientific_articlesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        scientific_articlesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
    
        
    
        
    
}
