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}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        companiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.trade_name)
        },
        companiesOneListFormatter(val) {
            if (!val) return ''
            return val.trade_name
        },
        companiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.trade_name}
            });
        },
        companiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.trade_name, id: val.id}
        },
        
    
        
        branchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.branch_name)
        },
        branchesOneListFormatter(val) {
            if (!val) return ''
            return val.branch_name
        },
        branchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.branch_name}
            });
        },
        branchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.branch_name, id: val.id}
        },
        
    
        
    
        
    
        
        product_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.category_name)
        },
        product_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.category_name
        },
        product_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.category_name}
            });
        },
        product_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.category_name, id: val.id}
        },
        
    
        
        productsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.product_name)
        },
        productsOneListFormatter(val) {
            if (!val) return ''
            return val.product_name
        },
        productsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.product_name}
            });
        },
        productsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.product_name, id: val.id}
        },
        
    
        
        price_listsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.price_list_name)
        },
        price_listsOneListFormatter(val) {
            if (!val) return ''
            return val.price_list_name
        },
        price_listsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.price_list_name}
            });
        },
        price_listsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.price_list_name, id: val.id}
        },
        
    
        
    
        
        warehousesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.warehouse_name)
        },
        warehousesOneListFormatter(val) {
            if (!val) return ''
            return val.warehouse_name
        },
        warehousesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.warehouse_name}
            });
        },
        warehousesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.warehouse_name, id: val.id}
        },
        
    
        
        inventory_batchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.batch_code)
        },
        inventory_batchesOneListFormatter(val) {
            if (!val) return ''
            return val.batch_code
        },
        inventory_batchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.batch_code}
            });
        },
        inventory_batchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.batch_code, id: val.id}
        },
        
    
        
    
        
        stock_adjustmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.adjustment_number)
        },
        stock_adjustmentsOneListFormatter(val) {
            if (!val) return ''
            return val.adjustment_number
        },
        stock_adjustmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.adjustment_number}
            });
        },
        stock_adjustmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.adjustment_number, id: val.id}
        },
        
    
        
    
        
        interbranch_transfersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.transfer_number)
        },
        interbranch_transfersOneListFormatter(val) {
            if (!val) return ''
            return val.transfer_number
        },
        interbranch_transfersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.transfer_number}
            });
        },
        interbranch_transfersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.transfer_number, id: val.id}
        },
        
    
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.supplier_name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.supplier_name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.supplier_name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.supplier_name, id: val.id}
        },
        
    
        
    
        
        purchase_ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.po_number)
        },
        purchase_ordersOneListFormatter(val) {
            if (!val) return ''
            return val.po_number
        },
        purchase_ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.po_number}
            });
        },
        purchase_ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.po_number, id: val.id}
        },
        
    
        
    
        
        goods_receiptsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.grn_number)
        },
        goods_receiptsOneListFormatter(val) {
            if (!val) return ''
            return val.grn_number
        },
        goods_receiptsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.grn_number}
            });
        },
        goods_receiptsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.grn_number, id: val.id}
        },
        
    
        
    
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.customer_name)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.customer_name
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.customer_name}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.customer_name, id: val.id}
        },
        
    
        
    
        
        pos_registersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.register_name)
        },
        pos_registersOneListFormatter(val) {
            if (!val) return ''
            return val.register_name
        },
        pos_registersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.register_name}
            });
        },
        pos_registersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.register_name, id: val.id}
        },
        
    
        
        pos_shiftsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.shift_number)
        },
        pos_shiftsOneListFormatter(val) {
            if (!val) return ''
            return val.shift_number
        },
        pos_shiftsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.shift_number}
            });
        },
        pos_shiftsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.shift_number, id: val.id}
        },
        
    
        
        salesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.receipt_number)
        },
        salesOneListFormatter(val) {
            if (!val) return ''
            return val.receipt_number
        },
        salesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.receipt_number}
            });
        },
        salesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.receipt_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        store_checklistsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.checklist_name)
        },
        store_checklistsOneListFormatter(val) {
            if (!val) return ''
            return val.checklist_name
        },
        store_checklistsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.checklist_name}
            });
        },
        store_checklistsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.checklist_name, id: val.id}
        },
        
    
        
        checklist_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.item_text)
        },
        checklist_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.item_text
        },
        checklist_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.item_text}
            });
        },
        checklist_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.item_text, id: val.id}
        },
        
    
        
        checklist_runsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        checklist_runsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        checklist_runsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        checklist_runsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
    
        
    
        
        departmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.department_name)
        },
        departmentsOneListFormatter(val) {
            if (!val) return ''
            return val.department_name
        },
        departmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.department_name}
            });
        },
        departmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.department_name, id: val.id}
        },
        
    
        
        employeesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.employee_number)
        },
        employeesOneListFormatter(val) {
            if (!val) return ''
            return val.employee_number
        },
        employeesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.employee_number}
            });
        },
        employeesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.employee_number, id: val.id}
        },
        
    
        
        work_shiftsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.shift_name)
        },
        work_shiftsOneListFormatter(val) {
            if (!val) return ''
            return val.shift_name
        },
        work_shiftsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.shift_name}
            });
        },
        work_shiftsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.shift_name, id: val.id}
        },
        
    
        
    
        
    
        
        payroll_runsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.payroll_name)
        },
        payroll_runsOneListFormatter(val) {
            if (!val) return ''
            return val.payroll_name
        },
        payroll_runsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.payroll_name}
            });
        },
        payroll_runsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.payroll_name, id: val.id}
        },
        
    
        
    
        
    
        
        chart_accountsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.account_name)
        },
        chart_accountsOneListFormatter(val) {
            if (!val) return ''
            return val.account_name
        },
        chart_accountsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.account_name}
            });
        },
        chart_accountsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.account_name, id: val.id}
        },
        
    
        
        journal_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.entry_number)
        },
        journal_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.entry_number
        },
        journal_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.entry_number}
            });
        },
        journal_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.entry_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        marketing_campaignsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.campaign_name)
        },
        marketing_campaignsOneListFormatter(val) {
            if (!val) return ''
            return val.campaign_name
        },
        marketing_campaignsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.campaign_name}
            });
        },
        marketing_campaignsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.campaign_name, id: val.id}
        },
        
    
        
    
        
    
}
