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}
        },
        
    
        
        document_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        document_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        document_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        document_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        standardsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.short_name)
        },
        standardsOneListFormatter(val) {
            if (!val) return ''
            return val.short_name
        },
        standardsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.short_name}
            });
        },
        standardsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.short_name, id: val.id}
        },
        
    
        
        clausesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.clause_code)
        },
        clausesOneListFormatter(val) {
            if (!val) return ''
            return val.clause_code
        },
        clausesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.clause_code}
            });
        },
        clausesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.clause_code, id: val.id}
        },
        
    
        
        document_templatesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.template_name)
        },
        document_templatesOneListFormatter(val) {
            if (!val) return ''
            return val.template_name
        },
        document_templatesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.template_name}
            });
        },
        document_templatesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.template_name, id: val.id}
        },
        
    
        
        documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        documentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, 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.step_name)
        },
        approval_stepsOneListFormatter(val) {
            if (!val) return ''
            return val.step_name
        },
        approval_stepsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.step_name}
            });
        },
        approval_stepsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.step_name, id: val.id}
        },
        
    
        
    
        
    
        
        training_coursesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.course_name)
        },
        training_coursesOneListFormatter(val) {
            if (!val) return ''
            return val.course_name
        },
        training_coursesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.course_name}
            });
        },
        training_coursesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.course_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}
        },
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.supplier_name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.supplier_name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.supplier_name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.supplier_name, id: val.id}
        },
        
    
        
        batchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.batch_number)
        },
        batchesOneListFormatter(val) {
            if (!val) return ''
            return val.batch_number
        },
        batchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.batch_number}
            });
        },
        batchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.batch_number, id: val.id}
        },
        
    
        
    
        
    
        
        risk_assessmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.risk_file_name)
        },
        risk_assessmentsOneListFormatter(val) {
            if (!val) return ''
            return val.risk_file_name
        },
        risk_assessmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.risk_file_name}
            });
        },
        risk_assessmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.risk_file_name, id: val.id}
        },
        
    
        
    
        
        capasManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.capa_number)
        },
        capasOneListFormatter(val) {
            if (!val) return ''
            return val.capa_number
        },
        capasManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.capa_number}
            });
        },
        capasOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.capa_number, id: val.id}
        },
        
    
        
    
        
    
        
        auditsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.audit_number)
        },
        auditsOneListFormatter(val) {
            if (!val) return ''
            return val.audit_number
        },
        auditsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.audit_number}
            });
        },
        auditsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.audit_number, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
