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}
        },
        
    
        
        workspacesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        workspacesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        workspacesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        workspacesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        data_connectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_name)
        },
        data_connectionsOneListFormatter(val) {
            if (!val) return ''
            return val.provider_name
        },
        data_connectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_name}
            });
        },
        data_connectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_name, id: val.id}
        },
        
    
        
        financial_accountsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.account_name)
        },
        financial_accountsOneListFormatter(val) {
            if (!val) return ''
            return val.account_name
        },
        financial_accountsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.account_name}
            });
        },
        financial_accountsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.account_name, id: val.id}
        },
        
    
        
        vendorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.vendor_name)
        },
        vendorsOneListFormatter(val) {
            if (!val) return ''
            return val.vendor_name
        },
        vendorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.vendor_name}
            });
        },
        vendorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.vendor_name, id: val.id}
        },
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.customer_name)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.customer_name
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.customer_name}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.customer_name, id: val.id}
        },
        
    
        
        transactionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.merchant_name)
        },
        transactionsOneListFormatter(val) {
            if (!val) return ''
            return val.merchant_name
        },
        transactionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.merchant_name}
            });
        },
        transactionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.merchant_name, id: val.id}
        },
        
    
        
        budgetsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.budget_name)
        },
        budgetsOneListFormatter(val) {
            if (!val) return ''
            return val.budget_name
        },
        budgetsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.budget_name}
            });
        },
        budgetsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.budget_name, id: val.id}
        },
        
    
        
    
        
        forecastsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.forecast_name)
        },
        forecastsOneListFormatter(val) {
            if (!val) return ''
            return val.forecast_name
        },
        forecastsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.forecast_name}
            });
        },
        forecastsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.forecast_name, id: val.id}
        },
        
    
        
    
        
    
        
        anomaliesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.summary)
        },
        anomaliesOneListFormatter(val) {
            if (!val) return ''
            return val.summary
        },
        anomaliesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.summary}
            });
        },
        anomaliesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.summary, id: val.id}
        },
        
    
        
    
        
    
        
        chat_threadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.thread_title)
        },
        chat_threadsOneListFormatter(val) {
            if (!val) return ''
            return val.thread_title
        },
        chat_threadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.thread_title}
            });
        },
        chat_threadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.thread_title, id: val.id}
        },
        
    
        
        chat_messagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.message_kind)
        },
        chat_messagesOneListFormatter(val) {
            if (!val) return ''
            return val.message_kind
        },
        chat_messagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.message_kind}
            });
        },
        chat_messagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.message_kind, id: val.id}
        },
        
    
        
        message_citationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.source_label)
        },
        message_citationsOneListFormatter(val) {
            if (!val) return ''
            return val.source_label
        },
        message_citationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.source_label}
            });
        },
        message_citationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.source_label, id: val.id}
        },
        
    
        
    
        
    
}
