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}
        },
        
    
        
        provincesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        provincesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        provincesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        provincesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        departmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        departmentsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        departmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        departmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        approval_workflowsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        approval_workflowsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        approval_workflowsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        approval_workflowsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        approval_stepsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        approval_stepsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        approval_stepsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        approval_stepsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        fiscal_yearsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        fiscal_yearsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        fiscal_yearsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        fiscal_yearsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        funding_sourcesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        funding_sourcesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        funding_sourcesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        funding_sourcesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        budget_programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        budget_programsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        budget_programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        budget_programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        budget_linesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        budget_linesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        budget_linesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        budget_linesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        procurement_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        procurement_plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        procurement_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        procurement_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        requisitionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.requisition_number)
        },
        requisitionsOneListFormatter(val) {
            if (!val) return ''
            return val.requisition_number
        },
        requisitionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.requisition_number}
            });
        },
        requisitionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.requisition_number, id: val.id}
        },
        
    
        
        tendersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.tender_number)
        },
        tendersOneListFormatter(val) {
            if (!val) return ''
            return val.tender_number
        },
        tendersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.tender_number}
            });
        },
        tendersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.tender_number, id: val.id}
        },
        
    
        
        vendorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        vendorsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        vendorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        vendorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        bidsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.bid_reference)
        },
        bidsOneListFormatter(val) {
            if (!val) return ''
            return val.bid_reference
        },
        bidsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.bid_reference}
            });
        },
        bidsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.bid_reference, id: val.id}
        },
        
    
        
    
        
        awardsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.award_number)
        },
        awardsOneListFormatter(val) {
            if (!val) return ''
            return val.award_number
        },
        awardsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.award_number}
            });
        },
        awardsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.award_number, id: val.id}
        },
        
    
        
        programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        programsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        projectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        projectsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        projectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        projectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        contractsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.contract_number)
        },
        contractsOneListFormatter(val) {
            if (!val) return ''
            return val.contract_number
        },
        contractsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.contract_number}
            });
        },
        contractsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.contract_number, id: val.id}
        },
        
    
        
    
        
    
        
        grantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.call_reference)
        },
        grantsOneListFormatter(val) {
            if (!val) return ''
            return val.call_reference
        },
        grantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.call_reference}
            });
        },
        grantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.call_reference, id: val.id}
        },
        
    
        
        beneficiariesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        beneficiariesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        beneficiariesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        beneficiariesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        grant_applicationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.application_reference)
        },
        grant_applicationsOneListFormatter(val) {
            if (!val) return ''
            return val.application_reference
        },
        grant_applicationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.application_reference}
            });
        },
        grant_applicationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.application_reference, id: val.id}
        },
        
    
        
    
        
    
        
        expense_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        expense_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        expense_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        expense_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoice_number)
        },
        invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoice_number
        },
        invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoice_number}
            });
        },
        invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoice_number, id: val.id}
        },
        
    
        
        payment_requestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.request_number)
        },
        payment_requestsOneListFormatter(val) {
            if (!val) return ''
            return val.request_number
        },
        payment_requestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.request_number}
            });
        },
        payment_requestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.request_number, id: val.id}
        },
        
    
        
        payment_batchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.batch_number)
        },
        payment_batchesOneListFormatter(val) {
            if (!val) return ''
            return val.batch_number
        },
        payment_batchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.batch_number}
            });
        },
        payment_batchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.batch_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
}
