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}
        },
        
    
        
    
        
    
        
    
        
    
        
        categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.category_name)
        },
        categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.category_name
        },
        categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.category_name}
            });
        },
        categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.category_name, id: val.id}
        },
        
    
        
        brandsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.brand_name)
        },
        brandsOneListFormatter(val) {
            if (!val) return ''
            return val.brand_name
        },
        brandsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.brand_name}
            });
        },
        brandsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.brand_name, 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}
        },
        
    
        
        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}
        },
        
    
        
        variant_attributesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.attribute_name)
        },
        variant_attributesOneListFormatter(val) {
            if (!val) return ''
            return val.attribute_name
        },
        variant_attributesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.attribute_name}
            });
        },
        variant_attributesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.attribute_name, id: val.id}
        },
        
    
        
        seo_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.meta_title)
        },
        seo_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.meta_title
        },
        seo_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.meta_title}
            });
        },
        seo_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.meta_title, id: val.id}
        },
        
    
        
        product_reviewsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.review_title)
        },
        product_reviewsOneListFormatter(val) {
            if (!val) return ''
            return val.review_title
        },
        product_reviewsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.review_title}
            });
        },
        product_reviewsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.review_title, id: val.id}
        },
        
    
        
    
        
    
        
        cartsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.guest_token)
        },
        cartsOneListFormatter(val) {
            if (!val) return ''
            return val.guest_token
        },
        cartsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.guest_token}
            });
        },
        cartsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.guest_token, id: val.id}
        },
        
    
        
        cart_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.cart)
        },
        cart_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.cart
        },
        cart_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.cart}
            });
        },
        cart_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.cart, id: val.id}
        },
        
    
        
        couponsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        couponsOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        couponsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        couponsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },
        
    
        
        user_addressesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        user_addressesOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        user_addressesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        user_addressesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },
        
    
        
        shipping_carriersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.carrier_name)
        },
        shipping_carriersOneListFormatter(val) {
            if (!val) return ''
            return val.carrier_name
        },
        shipping_carriersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.carrier_name}
            });
        },
        shipping_carriersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.carrier_name, id: val.id}
        },
        
    
        
        shipping_methodsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.method_name)
        },
        shipping_methodsOneListFormatter(val) {
            if (!val) return ''
            return val.method_name
        },
        shipping_methodsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.method_name}
            });
        },
        shipping_methodsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.method_name, 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}
        },
        
    
        
        order_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.product_name_snapshot)
        },
        order_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.product_name_snapshot
        },
        order_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.product_name_snapshot}
            });
        },
        order_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.product_name_snapshot, id: val.id}
        },
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.transaction_reference)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.transaction_reference
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.transaction_reference}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.transaction_reference, id: val.id}
        },
        
    
        
        shipmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tracking_number)
        },
        shipmentsOneListFormatter(val) {
            if (!val) return ''
            return val.tracking_number
        },
        shipmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tracking_number}
            });
        },
        shipmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tracking_number, id: val.id}
        },
        
    
        
        ad_placementsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.placement_name)
        },
        ad_placementsOneListFormatter(val) {
            if (!val) return ''
            return val.placement_name
        },
        ad_placementsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.placement_name}
            });
        },
        ad_placementsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.placement_name, id: val.id}
        },
        
    
        
        adsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.ad_name)
        },
        adsOneListFormatter(val) {
            if (!val) return ''
            return val.ad_name
        },
        adsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.ad_name}
            });
        },
        adsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.ad_name, id: val.id}
        },
        
    
        
    
        
    
        
        cms_pagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.page_title)
        },
        cms_pagesOneListFormatter(val) {
            if (!val) return ''
            return val.page_title
        },
        cms_pagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.page_title}
            });
        },
        cms_pagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.page_title, id: val.id}
        },
        
    
        
        footer_settingsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.copyright_text)
        },
        footer_settingsOneListFormatter(val) {
            if (!val) return ''
            return val.copyright_text
        },
        footer_settingsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.copyright_text}
            });
        },
        footer_settingsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.copyright_text, id: val.id}
        },
        
    
        
        social_linksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.url)
        },
        social_linksOneListFormatter(val) {
            if (!val) return ''
            return val.url
        },
        social_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.url}
            });
        },
        social_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.url, id: val.id}
        },
        
    
        
        footer_linksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        footer_linksOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        footer_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        footer_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },
        
    
        
    
        
        payment_iconsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.method)
        },
        payment_iconsOneListFormatter(val) {
            if (!val) return ''
            return val.method
        },
        payment_iconsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.method}
            });
        },
        payment_iconsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.method, id: val.id}
        },
        
    
        
    
        
    
}
