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}
        },
        
    
        
        driversManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.driver_name)
        },
        driversOneListFormatter(val) {
            if (!val) return ''
            return val.driver_name
        },
        driversManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.driver_name}
            });
        },
        driversOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.driver_name, id: val.id}
        },
        
    
        
        vehiclesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plate_no)
        },
        vehiclesOneListFormatter(val) {
            if (!val) return ''
            return val.plate_no
        },
        vehiclesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plate_no}
            });
        },
        vehiclesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plate_no, id: val.id}
        },
        
    
        
        agreementsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.agreement_number)
        },
        agreementsOneListFormatter(val) {
            if (!val) return ''
            return val.agreement_number
        },
        agreementsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.agreement_number}
            });
        },
        agreementsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.agreement_number, 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}
        },
        
    
        
        chart_of_accountsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.account_name)
        },
        chart_of_accountsOneListFormatter(val) {
            if (!val) return ''
            return val.account_name
        },
        chart_of_accountsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.account_name}
            });
        },
        chart_of_accountsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.account_name, id: val.id}
        },
        
    
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.payment_ref)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.payment_ref
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.payment_ref}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.payment_ref, id: val.id}
        },
        
    
        
    
        
        vendorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.vendor_name)
        },
        vendorsOneListFormatter(val) {
            if (!val) return ''
            return val.vendor_name
        },
        vendorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.vendor_name}
            });
        },
        vendorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.vendor_name, id: val.id}
        },
        
    
        
        vehicle_expensesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.expense_no)
        },
        vehicle_expensesOneListFormatter(val) {
            if (!val) return ''
            return val.expense_no
        },
        vehicle_expensesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.expense_no}
            });
        },
        vehicle_expensesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.expense_no, id: val.id}
        },
        
    
        
    
        
        billsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.bill_no)
        },
        billsOneListFormatter(val) {
            if (!val) return ''
            return val.bill_no
        },
        billsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.bill_no}
            });
        },
        billsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.bill_no, id: val.id}
        },
        
    
        
    
        
    
        
        ledger_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.entry_no)
        },
        ledger_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.entry_no
        },
        ledger_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.entry_no}
            });
        },
        ledger_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.entry_no, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
