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}
        },
        
    
        
        addressesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        addressesOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        addressesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        addressesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },
        
    
        
        merchant_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.business_name)
        },
        merchant_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.business_name
        },
        merchant_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.business_name}
            });
        },
        merchant_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.business_name, id: val.id}
        },
        
    
        
        storesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.store_name)
        },
        storesOneListFormatter(val) {
            if (!val) return ''
            return val.store_name
        },
        storesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.store_name}
            });
        },
        storesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.store_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}
        },
        
    
        
        cartsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        cartsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        cartsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        cartsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, 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}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        languagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.language_name)
        },
        languagesOneListFormatter(val) {
            if (!val) return ''
            return val.language_name
        },
        languagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.language_name}
            });
        },
        languagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.language_name, id: val.id}
        },
        
    
        
        translation_keysManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.key_name)
        },
        translation_keysOneListFormatter(val) {
            if (!val) return ''
            return val.key_name
        },
        translation_keysManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.key_name}
            });
        },
        translation_keysOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.key_name, id: val.id}
        },
        
    
        
    
}
