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}
        },
        
    
        
        companiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        companiesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        companiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        companiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        company_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        company_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        company_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        company_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        company_document_versionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.number)
        },
        company_document_versionsOneListFormatter(val) {
            if (!val) return ''
            return val.number
        },
        company_document_versionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.number}
            });
        },
        company_document_versionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.number, id: val.id}
        },
        
    
        
        employeesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.last_name)
        },
        employeesOneListFormatter(val) {
            if (!val) return ''
            return val.last_name
        },
        employeesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.last_name}
            });
        },
        employeesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.last_name, id: val.id}
        },
        
    
        
    
        
    
        
        driver_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.driver_notes)
        },
        driver_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.driver_notes
        },
        driver_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.driver_notes}
            });
        },
        driver_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.driver_notes, id: val.id}
        },
        
    
        
        driver_compliancesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.license_number)
        },
        driver_compliancesOneListFormatter(val) {
            if (!val) return ''
            return val.license_number
        },
        driver_compliancesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.license_number}
            });
        },
        driver_compliancesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.license_number, id: val.id}
        },
        
    
        
    
        
        documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        documentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        document_versionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.number)
        },
        document_versionsOneListFormatter(val) {
            if (!val) return ''
            return val.number
        },
        document_versionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.number}
            });
        },
        document_versionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.number, id: val.id}
        },
        
    
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        vendorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        vendorsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        vendorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        vendorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        vehiclesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plate_number)
        },
        vehiclesOneListFormatter(val) {
            if (!val) return ''
            return val.plate_number
        },
        vehiclesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plate_number}
            });
        },
        vehiclesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plate_number, id: val.id}
        },
        
    
        
        trailersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plate_number)
        },
        trailersOneListFormatter(val) {
            if (!val) return ''
            return val.plate_number
        },
        trailersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plate_number}
            });
        },
        trailersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plate_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        vehicle_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        vehicle_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        vehicle_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        vehicle_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        vehicle_document_versionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.number)
        },
        vehicle_document_versionsOneListFormatter(val) {
            if (!val) return ''
            return val.number
        },
        vehicle_document_versionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.number}
            });
        },
        vehicle_document_versionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.number, id: val.id}
        },
        
    
        
    
        
        ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.order_no)
        },
        ordersOneListFormatter(val) {
            if (!val) return ''
            return val.order_no
        },
        ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.order_no}
            });
        },
        ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.order_no, id: val.id}
        },
        
    
        
        loadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.load_no)
        },
        loadsOneListFormatter(val) {
            if (!val) return ''
            return val.load_no
        },
        loadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.load_no}
            });
        },
        loadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.load_no, id: val.id}
        },
        
    
        
        load_stopsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        load_stopsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        load_stopsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        load_stopsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        tripsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.trip_no)
        },
        tripsOneListFormatter(val) {
            if (!val) return ''
            return val.trip_no
        },
        tripsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.trip_no}
            });
        },
        tripsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.trip_no, id: val.id}
        },
        
    
        
    
        
    
        
        invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoice_no)
        },
        invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoice_no
        },
        invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoice_no}
            });
        },
        invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoice_no, id: val.id}
        },
        
    
        
    
        
    
        
        cost_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reference)
        },
        cost_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.reference
        },
        cost_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reference}
            });
        },
        cost_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reference, id: val.id}
        },
        
    
        
    
        
        fuel_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.station_name)
        },
        fuel_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.station_name
        },
        fuel_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.station_name}
            });
        },
        fuel_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.station_name, id: val.id}
        },
        
    
        
        toll_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.toll_ref)
        },
        toll_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.toll_ref
        },
        toll_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.toll_ref}
            });
        },
        toll_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.toll_ref, id: val.id}
        },
        
    
}
