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}
        },
        
    
        
    
        
    
        
        walletsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.wallet_code)
        },
        walletsOneListFormatter(val) {
            if (!val) return ''
            return val.wallet_code
        },
        walletsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.wallet_code}
            });
        },
        walletsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.wallet_code, id: val.id}
        },
        
    
        
        wallet_transactionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reference_code)
        },
        wallet_transactionsOneListFormatter(val) {
            if (!val) return ''
            return val.reference_code
        },
        wallet_transactionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reference_code}
            });
        },
        wallet_transactionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reference_code, id: val.id}
        },
        
    
        
        chatsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.chat_title)
        },
        chatsOneListFormatter(val) {
            if (!val) return ''
            return val.chat_title
        },
        chatsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.chat_title}
            });
        },
        chatsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.chat_title, id: val.id}
        },
        
    
        
        chat_participantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.role)
        },
        chat_participantsOneListFormatter(val) {
            if (!val) return ''
            return val.role
        },
        chat_participantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.role}
            });
        },
        chat_participantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.role, 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}
        },
        
    
        
        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}
        },
        
    
        
        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}
        },
        
    
        
        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}
        },
        
    
        
    
        
    
        
    
        
    
        
        postsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.caption)
        },
        postsOneListFormatter(val) {
            if (!val) return ''
            return val.caption
        },
        postsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.caption}
            });
        },
        postsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.caption, id: val.id}
        },
        
    
        
        deep_dive_linksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title_text)
        },
        deep_dive_linksOneListFormatter(val) {
            if (!val) return ''
            return val.title_text
        },
        deep_dive_linksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title_text}
            });
        },
        deep_dive_linksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title_text, id: val.id}
        },
        
    
        
        citationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.source_title)
        },
        citationsOneListFormatter(val) {
            if (!val) return ''
            return val.source_title
        },
        citationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.source_title}
            });
        },
        citationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.source_title, id: val.id}
        },
        
    
        
    
        
    
        
        forum_spacesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.space_name)
        },
        forum_spacesOneListFormatter(val) {
            if (!val) return ''
            return val.space_name
        },
        forum_spacesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.space_name}
            });
        },
        forum_spacesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.space_name, id: val.id}
        },
        
    
        
        forum_threadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.thread_title)
        },
        forum_threadsOneListFormatter(val) {
            if (!val) return ''
            return val.thread_title
        },
        forum_threadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.thread_title}
            });
        },
        forum_threadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.thread_title, id: val.id}
        },
        
    
        
    
        
        job_companiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.company_name)
        },
        job_companiesOneListFormatter(val) {
            if (!val) return ''
            return val.company_name
        },
        job_companiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.company_name}
            });
        },
        job_companiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.company_name, id: val.id}
        },
        
    
        
        job_listingsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.job_title)
        },
        job_listingsOneListFormatter(val) {
            if (!val) return ''
            return val.job_title
        },
        job_listingsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.job_title}
            });
        },
        job_listingsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.job_title, id: val.id}
        },
        
    
        
    
        
    
        
        affiliate_programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.program_name)
        },
        affiliate_programsOneListFormatter(val) {
            if (!val) return ''
            return val.program_name
        },
        affiliate_programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.program_name}
            });
        },
        affiliate_programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.program_name, id: val.id}
        },
        
    
        
        affiliate_membershipsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.referral_code)
        },
        affiliate_membershipsOneListFormatter(val) {
            if (!val) return ''
            return val.referral_code
        },
        affiliate_membershipsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.referral_code}
            });
        },
        affiliate_membershipsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.referral_code, id: val.id}
        },
        
    
        
    
        
    
        
        facta_queriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.query_text)
        },
        facta_queriesOneListFormatter(val) {
            if (!val) return ''
            return val.query_text
        },
        facta_queriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.query_text}
            });
        },
        facta_queriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.query_text, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
