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}
        },
        
    
        
        tenantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tenant_name)
        },
        tenantsOneListFormatter(val) {
            if (!val) return ''
            return val.tenant_name
        },
        tenantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tenant_name}
            });
        },
        tenantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tenant_name, id: val.id}
        },
        
    
        
    
        
        tenant_locationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.location_name)
        },
        tenant_locationsOneListFormatter(val) {
            if (!val) return ''
            return val.location_name
        },
        tenant_locationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.location_name}
            });
        },
        tenant_locationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.location_name, id: val.id}
        },
        
    
        
        pondsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.pond_name)
        },
        pondsOneListFormatter(val) {
            if (!val) return ''
            return val.pond_name
        },
        pondsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.pond_name}
            });
        },
        pondsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.pond_name, id: val.id}
        },
        
    
        
        speciesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.species_name)
        },
        speciesOneListFormatter(val) {
            if (!val) return ''
            return val.species_name
        },
        speciesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.species_name}
            });
        },
        speciesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.species_name, id: val.id}
        },
        
    
        
        batchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.batch_code)
        },
        batchesOneListFormatter(val) {
            if (!val) return ''
            return val.batch_code
        },
        batchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.batch_code}
            });
        },
        batchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.batch_code, id: val.id}
        },
        
    
        
        feed_productsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.product_name)
        },
        feed_productsOneListFormatter(val) {
            if (!val) return ''
            return val.product_name
        },
        feed_productsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.product_name}
            });
        },
        feed_productsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.product_name, id: val.id}
        },
        
    
        
        inventory_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.item_name)
        },
        inventory_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.item_name
        },
        inventory_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.item_name}
            });
        },
        inventory_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.item_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        harvestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        harvestsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        harvestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        harvestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
        marketplace_listingsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.listing_title)
        },
        marketplace_listingsOneListFormatter(val) {
            if (!val) return ''
            return val.listing_title
        },
        marketplace_listingsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.listing_title}
            });
        },
        marketplace_listingsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.listing_title, 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}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        webhook_endpointsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.endpoint_name)
        },
        webhook_endpointsOneListFormatter(val) {
            if (!val) return ''
            return val.endpoint_name
        },
        webhook_endpointsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.endpoint_name}
            });
        },
        webhook_endpointsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.endpoint_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
