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}
        },
        
    
        
    
        
        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}
        },
        
    
        
        categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        brandsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        brandsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        brandsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        brandsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        productsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        productsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        productsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        productsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        product_variantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        product_variantsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        product_variantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        product_variantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        collectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        collectionsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        collectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        collectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        product_reviewsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        product_reviewsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        product_reviewsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        product_reviewsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
        compare_listsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        compare_listsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        compare_listsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        compare_listsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        compare_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.added_at)
        },
        compare_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.added_at
        },
        compare_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.added_at}
            });
        },
        compare_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.added_at, id: val.id}
        },
        
    
        
        cartsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.session_key)
        },
        cartsOneListFormatter(val) {
            if (!val) return ''
            return val.session_key
        },
        cartsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.session_key}
            });
        },
        cartsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.session_key, id: val.id}
        },
        
    
        
        cart_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.line_total_iqd)
        },
        cart_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.line_total_iqd
        },
        cart_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.line_total_iqd}
            });
        },
        cart_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.line_total_iqd, 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}
        },
        
    
        
        shipping_carriersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        shipping_carriersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        shipping_carriersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        shipping_carriersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, 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}
        },
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_reference)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.provider_reference
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_reference}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_reference, 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}
        },
        
    
        
        coupon_redemptionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.redeemed_at)
        },
        coupon_redemptionsOneListFormatter(val) {
            if (!val) return ''
            return val.redeemed_at
        },
        coupon_redemptionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.redeemed_at}
            });
        },
        coupon_redemptionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.redeemed_at, id: val.id}
        },
        
    
        
    
        
    
        
        frequently_bought_together_groupsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        frequently_bought_together_groupsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        frequently_bought_together_groupsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        frequently_bought_together_groupsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        frequently_bought_together_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.sort_order)
        },
        frequently_bought_together_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.sort_order
        },
        frequently_bought_together_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.sort_order}
            });
        },
        frequently_bought_together_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.sort_order, id: val.id}
        },
        
    
        
        ad_placementsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        ad_placementsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        ad_placementsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        ad_placementsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        adsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        adsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        adsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        adsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        footer_content_blocksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.store_description_ar)
        },
        footer_content_blocksOneListFormatter(val) {
            if (!val) return ''
            return val.store_description_ar
        },
        footer_content_blocksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.store_description_ar}
            });
        },
        footer_content_blocksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.store_description_ar, 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_ar)
        },
        footer_linksOneListFormatter(val) {
            if (!val) return ''
            return val.label_ar
        },
        footer_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label_ar}
            });
        },
        footer_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label_ar, id: val.id}
        },
        
    
        
        payment_badgesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        payment_badgesOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        payment_badgesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        payment_badgesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        seo_entriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.entity_key)
        },
        seo_entriesOneListFormatter(val) {
            if (!val) return ''
            return val.entity_key
        },
        seo_entriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.entity_key}
            });
        },
        seo_entriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.entity_key, id: val.id}
        },
        
    
}
