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}
        },
        
    
        
        campusesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        campusesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        campusesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        campusesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        camp_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        camp_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        camp_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        camp_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        age_groupsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        age_groupsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        age_groupsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        age_groupsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        pricing_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        pricing_plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        pricing_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        pricing_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        guardiansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.primary_phone)
        },
        guardiansOneListFormatter(val) {
            if (!val) return ''
            return val.primary_phone
        },
        guardiansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.primary_phone}
            });
        },
        guardiansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.primary_phone, id: val.id}
        },
        
    
        
        campersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.first_name)
        },
        campersOneListFormatter(val) {
            if (!val) return ''
            return val.first_name
        },
        campersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.first_name}
            });
        },
        campersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.first_name, id: val.id}
        },
        
    
        
        enrollmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        enrollmentsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        enrollmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        enrollmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
        waiver_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        waiver_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        waiver_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        waiver_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        field_trip_catalogManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        field_trip_catalogOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        field_trip_catalogManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        field_trip_catalogOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        field_trip_eventsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        field_trip_eventsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        field_trip_eventsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        field_trip_eventsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
    
        
    
        
        end_of_summer_trip_optionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        end_of_summer_trip_optionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        end_of_summer_trip_optionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        end_of_summer_trip_optionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        curriculum_subjectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        curriculum_subjectsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        curriculum_subjectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        curriculum_subjectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
}
