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}
        },
        
    
        
    
        
        tax_ratesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        tax_ratesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        tax_ratesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        tax_ratesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        payment_termsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        payment_termsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        payment_termsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        payment_termsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        clientsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.display_name)
        },
        clientsOneListFormatter(val) {
            if (!val) return ''
            return val.display_name
        },
        clientsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.display_name}
            });
        },
        clientsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.display_name, id: val.id}
        },
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.display_name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.display_name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.display_name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.display_name, id: val.id}
        },
        
    
        
        product_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        product_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        product_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        product_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        unitsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        unitsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        unitsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        unitsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        productsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        productsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        productsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        productsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        warehousesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        warehousesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        warehousesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        warehousesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        quotesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.quote_number)
        },
        quotesOneListFormatter(val) {
            if (!val) return ''
            return val.quote_number
        },
        quotesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.quote_number}
            });
        },
        quotesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.quote_number, id: val.id}
        },
        
    
        
    
        
        sales_ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.order_number)
        },
        sales_ordersOneListFormatter(val) {
            if (!val) return ''
            return val.order_number
        },
        sales_ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.order_number}
            });
        },
        sales_ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.order_number, id: val.id}
        },
        
    
        
    
        
        delivery_notesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.delivery_note_number)
        },
        delivery_notesOneListFormatter(val) {
            if (!val) return ''
            return val.delivery_note_number
        },
        delivery_notesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.delivery_note_number}
            });
        },
        delivery_notesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.delivery_note_number, id: val.id}
        },
        
    
        
    
        
        invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoice_number)
        },
        invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoice_number
        },
        invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoice_number}
            });
        },
        invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoice_number, id: val.id}
        },
        
    
        
    
        
    
        
        credit_notesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.credit_note_number)
        },
        credit_notesOneListFormatter(val) {
            if (!val) return ''
            return val.credit_note_number
        },
        credit_notesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.credit_note_number}
            });
        },
        credit_notesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.credit_note_number, id: val.id}
        },
        
    
        
    
        
        purchase_ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.purchase_order_number)
        },
        purchase_ordersOneListFormatter(val) {
            if (!val) return ''
            return val.purchase_order_number
        },
        purchase_ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.purchase_order_number}
            });
        },
        purchase_ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.purchase_order_number, id: val.id}
        },
        
    
        
    
        
        stock_receptionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reception_number)
        },
        stock_receptionsOneListFormatter(val) {
            if (!val) return ''
            return val.reception_number
        },
        stock_receptionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reception_number}
            });
        },
        stock_receptionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reception_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        inventory_countsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.inventory_number)
        },
        inventory_countsOneListFormatter(val) {
            if (!val) return ''
            return val.inventory_number
        },
        inventory_countsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.inventory_number}
            });
        },
        inventory_countsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.inventory_number, id: val.id}
        },
        
    
        
    
        
    
        
    
}
