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}
        },
        
    
        
        tenantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tenant_name)
        },
        tenantsOneListFormatter(val) {
            if (!val) return ''
            return val.tenant_name
        },
        tenantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tenant_name}
            });
        },
        tenantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tenant_name, id: val.id}
        },
        
    
        
        locationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.location_name)
        },
        locationsOneListFormatter(val) {
            if (!val) return ''
            return val.location_name
        },
        locationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.location_name}
            });
        },
        locationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.location_name, 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}
        },
        
    
        
        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}
        },
        
    
        
        product_variantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.variant_name)
        },
        product_variantsOneListFormatter(val) {
            if (!val) return ''
            return val.variant_name
        },
        product_variantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.variant_name}
            });
        },
        product_variantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.variant_name, id: val.id}
        },
        
    
        
    
        
    
        
        registersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.register_name)
        },
        registersOneListFormatter(val) {
            if (!val) return ''
            return val.register_name
        },
        registersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.register_name}
            });
        },
        registersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.register_name, id: val.id}
        },
        
    
        
        shiftsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        shiftsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        shiftsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        shiftsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
        cartsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.hold_reason)
        },
        cartsOneListFormatter(val) {
            if (!val) return ''
            return val.hold_reason
        },
        cartsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.hold_reason}
            });
        },
        cartsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.hold_reason, id: val.id}
        },
        
    
        
    
        
        ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.order_number)
        },
        ordersOneListFormatter(val) {
            if (!val) return ''
            return val.order_number
        },
        ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.order_number}
            });
        },
        ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.order_number, id: val.id}
        },
        
    
        
    
        
        payment_intentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_reference)
        },
        payment_intentsOneListFormatter(val) {
            if (!val) return ''
            return val.provider_reference
        },
        payment_intentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_reference}
            });
        },
        payment_intentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_reference, id: val.id}
        },
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.payment_status)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.payment_status
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.payment_status}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.payment_status, id: val.id}
        },
        
    
        
    
        
        inventory_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.on_hand_quantity)
        },
        inventory_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.on_hand_quantity
        },
        inventory_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.on_hand_quantity}
            });
        },
        inventory_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.on_hand_quantity, id: val.id}
        },
        
    
        
    
        
        partnersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.partner_name)
        },
        partnersOneListFormatter(val) {
            if (!val) return ''
            return val.partner_name
        },
        partnersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.partner_name}
            });
        },
        partnersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.partner_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
}
