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}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        cost_centersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        cost_centersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        cost_centersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        cost_centersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        departmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        departmentsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        departmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        departmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        positionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        positionsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        positionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        positionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        shiftsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        shiftsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        shiftsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        shiftsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        employeesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.employeeCode)
        },
        employeesOneListFormatter(val) {
            if (!val) return ''
            return val.employeeCode
        },
        employeesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.employeeCode}
            });
        },
        employeesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.employeeCode, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        leave_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        leave_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        leave_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        leave_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        employee_loansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.loanSource)
        },
        employee_loansOneListFormatter(val) {
            if (!val) return ''
            return val.loanSource
        },
        employee_loansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.loanSource}
            });
        },
        employee_loansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.loanSource, id: val.id}
        },
        
    
        
    
        
        payroll_runsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        payroll_runsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        payroll_runsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        payroll_runsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
        payroll_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.payslipHash)
        },
        payroll_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.payslipHash
        },
        payroll_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.payslipHash}
            });
        },
        payroll_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.payslipHash, 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}
        },
        
    
        
        journal_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.entryNumber)
        },
        journal_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.entryNumber
        },
        journal_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.entryNumber}
            });
        },
        journal_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.entryNumber, id: val.id}
        },
        
    
        
    
        
        vendorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.vendorName)
        },
        vendorsOneListFormatter(val) {
            if (!val) return ''
            return val.vendorName
        },
        vendorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.vendorName}
            });
        },
        vendorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.vendorName, id: val.id}
        },
        
    
        
        ap_invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoiceNumber)
        },
        ap_invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoiceNumber
        },
        ap_invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoiceNumber}
            });
        },
        ap_invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoiceNumber, id: val.id}
        },
        
    
        
        ap_paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.bankName)
        },
        ap_paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.bankName
        },
        ap_paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.bankName}
            });
        },
        ap_paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.bankName, id: val.id}
        },
        
    
        
        ap_payment_linesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.amountPaid)
        },
        ap_payment_linesOneListFormatter(val) {
            if (!val) return ''
            return val.amountPaid
        },
        ap_payment_linesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.amountPaid}
            });
        },
        ap_payment_linesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.amountPaid, id: val.id}
        },
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.customerName)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.customerName
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.customerName}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.customerName, id: val.id}
        },
        
    
        
        ar_invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoiceNumber)
        },
        ar_invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoiceNumber
        },
        ar_invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoiceNumber}
            });
        },
        ar_invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoiceNumber, id: val.id}
        },
        
    
        
    
        
        job_requisitionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.positionTitle)
        },
        job_requisitionsOneListFormatter(val) {
            if (!val) return ''
            return val.positionTitle
        },
        job_requisitionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.positionTitle}
            });
        },
        job_requisitionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.positionTitle, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
