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}
        },
        
    
        
    
        
        connected_systemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.system_name)
        },
        connected_systemsOneListFormatter(val) {
            if (!val) return ''
            return val.system_name
        },
        connected_systemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.system_name}
            });
        },
        connected_systemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.system_name, id: val.id}
        },
        
    
        
        control_frameworksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.framework_name)
        },
        control_frameworksOneListFormatter(val) {
            if (!val) return ''
            return val.framework_name
        },
        control_frameworksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.framework_name}
            });
        },
        control_frameworksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.framework_name, id: val.id}
        },
        
    
        
        control_requirementsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.control_code)
        },
        control_requirementsOneListFormatter(val) {
            if (!val) return ''
            return val.control_code
        },
        control_requirementsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.control_code}
            });
        },
        control_requirementsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.control_code, id: val.id}
        },
        
    
        
        identity_workflowsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.workflow_name)
        },
        identity_workflowsOneListFormatter(val) {
            if (!val) return ''
            return val.workflow_name
        },
        identity_workflowsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.workflow_name}
            });
        },
        identity_workflowsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.workflow_name, id: val.id}
        },
        
    
        
        evidence_modelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.evidence_claim)
        },
        evidence_modelsOneListFormatter(val) {
            if (!val) return ''
            return val.evidence_claim
        },
        evidence_modelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.evidence_claim}
            });
        },
        evidence_modelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.evidence_claim, id: val.id}
        },
        
    
        
        artifactsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.artifact_name)
        },
        artifactsOneListFormatter(val) {
            if (!val) return ''
            return val.artifact_name
        },
        artifactsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.artifact_name}
            });
        },
        artifactsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.artifact_name, id: val.id}
        },
        
    
        
        sampled_subjectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.display_name)
        },
        sampled_subjectsOneListFormatter(val) {
            if (!val) return ''
            return val.display_name
        },
        sampled_subjectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.display_name}
            });
        },
        sampled_subjectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.display_name, id: val.id}
        },
        
    
        
        proof_packetsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.packet_name)
        },
        proof_packetsOneListFormatter(val) {
            if (!val) return ''
            return val.packet_name
        },
        proof_packetsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.packet_name}
            });
        },
        proof_packetsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.packet_name, id: val.id}
        },
        
    
        
    
        
        access_reviewsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.review_name)
        },
        access_reviewsOneListFormatter(val) {
            if (!val) return ''
            return val.review_name
        },
        access_reviewsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.review_name}
            });
        },
        access_reviewsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.review_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
