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}
        },
        
    
        
        creator_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.handle)
        },
        creator_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.handle
        },
        creator_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.handle}
            });
        },
        creator_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.handle, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        profile_stylesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.style_name)
        },
        profile_stylesOneListFormatter(val) {
            if (!val) return ''
            return val.style_name
        },
        profile_stylesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.style_name}
            });
        },
        profile_stylesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.style_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        playlistsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        playlistsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        playlistsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        playlistsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        tip_pagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.slug)
        },
        tip_pagesOneListFormatter(val) {
            if (!val) return ''
            return val.slug
        },
        tip_pagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.slug}
            });
        },
        tip_pagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.slug, id: val.id}
        },
        
    
        
    
        
        alert_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.profile_name)
        },
        alert_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.profile_name
        },
        alert_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.profile_name}
            });
        },
        alert_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.profile_name, id: val.id}
        },
        
    
        
    
        
        overlay_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        overlay_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        overlay_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        overlay_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        widget_catalog_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        widget_catalog_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        widget_catalog_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        widget_catalog_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        overlay_widgetsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.instance_name)
        },
        overlay_widgetsOneListFormatter(val) {
            if (!val) return ''
            return val.instance_name
        },
        overlay_widgetsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.instance_name}
            });
        },
        overlay_widgetsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.instance_name, id: val.id}
        },
        
    
        
        merch_storesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.store_name)
        },
        merch_storesOneListFormatter(val) {
            if (!val) return ''
            return val.store_name
        },
        merch_storesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.store_name}
            });
        },
        merch_storesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.store_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}
        },
        
    
        
        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}
        },
        
    
        
        ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.currency)
        },
        ordersOneListFormatter(val) {
            if (!val) return ''
            return val.currency
        },
        ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.currency}
            });
        },
        ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.currency, id: val.id}
        },
        
    
        
    
        
    
        
        private_mailboxesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.public_label)
        },
        private_mailboxesOneListFormatter(val) {
            if (!val) return ''
            return val.public_label
        },
        private_mailboxesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.public_label}
            });
        },
        private_mailboxesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.public_label, id: val.id}
        },
        
    
        
    
        
    
        
        demo_walletsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.currency)
        },
        demo_walletsOneListFormatter(val) {
            if (!val) return ''
            return val.currency
        },
        demo_walletsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.currency}
            });
        },
        demo_walletsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.currency, id: val.id}
        },
        
    
        
    
}
