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}
        },
        
    
        
        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}
        },
        
    
        
    
        
        collectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.collection_name)
        },
        collectionsOneListFormatter(val) {
            if (!val) return ''
            return val.collection_name
        },
        collectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.collection_name}
            });
        },
        collectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.collection_name, id: val.id}
        },
        
    
        
        productsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.product_title)
        },
        productsOneListFormatter(val) {
            if (!val) return ''
            return val.product_title
        },
        productsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.product_title}
            });
        },
        productsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.product_title, id: val.id}
        },
        
    
        
        product_variantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.variant_title)
        },
        product_variantsOneListFormatter(val) {
            if (!val) return ''
            return val.variant_title
        },
        product_variantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.variant_title}
            });
        },
        product_variantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.variant_title, id: val.id}
        },
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.email)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.email
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.email}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.email, 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}
        },
        
    
        
    
        
    
        
        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}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        chat_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.session_key)
        },
        chat_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.session_key
        },
        chat_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.session_key}
            });
        },
        chat_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.session_key, id: val.id}
        },
        
    
        
    
        
    
        
    
}
