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}
        },
        
    
        
    
        
    
        
        teamsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.team_name)
        },
        teamsOneListFormatter(val) {
            if (!val) return ''
            return val.team_name
        },
        teamsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.team_name}
            });
        },
        teamsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.team_name, id: val.id}
        },
        
    
        
    
        
        programsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.program_name)
        },
        programsOneListFormatter(val) {
            if (!val) return ''
            return val.program_name
        },
        programsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.program_name}
            });
        },
        programsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.program_name, id: val.id}
        },
        
    
        
        learning_pathsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.path_name)
        },
        learning_pathsOneListFormatter(val) {
            if (!val) return ''
            return val.path_name
        },
        learning_pathsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.path_name}
            });
        },
        learning_pathsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.path_name, id: val.id}
        },
        
    
        
        missionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.mission_title)
        },
        missionsOneListFormatter(val) {
            if (!val) return ''
            return val.mission_title
        },
        missionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.mission_title}
            });
        },
        missionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.mission_title, id: val.id}
        },
        
    
        
        checklistsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.checklist_name)
        },
        checklistsOneListFormatter(val) {
            if (!val) return ''
            return val.checklist_name
        },
        checklistsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.checklist_name}
            });
        },
        checklistsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.checklist_name, id: val.id}
        },
        
    
        
    
        
        enrollmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.enrollment_status)
        },
        enrollmentsOneListFormatter(val) {
            if (!val) return ''
            return val.enrollment_status
        },
        enrollmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.enrollment_status}
            });
        },
        enrollmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.enrollment_status, id: val.id}
        },
        
    
        
        mission_attemptsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.attempt_status)
        },
        mission_attemptsOneListFormatter(val) {
            if (!val) return ''
            return val.attempt_status
        },
        mission_attemptsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.attempt_status}
            });
        },
        mission_attemptsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.attempt_status, id: val.id}
        },
        
    
        
        quizzesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.quiz_title)
        },
        quizzesOneListFormatter(val) {
            if (!val) return ''
            return val.quiz_title
        },
        quizzesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.quiz_title}
            });
        },
        quizzesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.quiz_title, id: val.id}
        },
        
    
        
        quiz_questionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.prompt)
        },
        quiz_questionsOneListFormatter(val) {
            if (!val) return ''
            return val.prompt
        },
        quiz_questionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.prompt}
            });
        },
        quiz_questionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.prompt, id: val.id}
        },
        
    
        
    
        
        quiz_submissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.submitted_at)
        },
        quiz_submissionsOneListFormatter(val) {
            if (!val) return ''
            return val.submitted_at
        },
        quiz_submissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.submitted_at}
            });
        },
        quiz_submissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.submitted_at, id: val.id}
        },
        
    
        
    
        
        simulationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.simulation_title)
        },
        simulationsOneListFormatter(val) {
            if (!val) return ''
            return val.simulation_title
        },
        simulationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.simulation_title}
            });
        },
        simulationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.simulation_title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        badgesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.badge_name)
        },
        badgesOneListFormatter(val) {
            if (!val) return ''
            return val.badge_name
        },
        badgesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.badge_name}
            });
        },
        badgesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.badge_name, id: val.id}
        },
        
    
        
    
        
    
        
        challengesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.challenge_name)
        },
        challengesOneListFormatter(val) {
            if (!val) return ''
            return val.challenge_name
        },
        challengesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.challenge_name}
            });
        },
        challengesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.challenge_name, id: val.id}
        },
        
    
        
    
        
        reward_catalog_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.item_name)
        },
        reward_catalog_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.item_name
        },
        reward_catalog_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.item_name}
            });
        },
        reward_catalog_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.item_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        kpi_definitionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.kpi_name)
        },
        kpi_definitionsOneListFormatter(val) {
            if (!val) return ''
            return val.kpi_name
        },
        kpi_definitionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.kpi_name}
            });
        },
        kpi_definitionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.kpi_name, id: val.id}
        },
        
    
        
    
        
        qa_evaluationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.interaction_reference)
        },
        qa_evaluationsOneListFormatter(val) {
            if (!val) return ''
            return val.interaction_reference
        },
        qa_evaluationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.interaction_reference}
            });
        },
        qa_evaluationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.interaction_reference, id: val.id}
        },
        
    
        
    
        
        surveysManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.survey_name)
        },
        surveysOneListFormatter(val) {
            if (!val) return ''
            return val.survey_name
        },
        surveysManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.survey_name}
            });
        },
        surveysOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.survey_name, id: val.id}
        },
        
    
        
        survey_questionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.prompt)
        },
        survey_questionsOneListFormatter(val) {
            if (!val) return ''
            return val.prompt
        },
        survey_questionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.prompt}
            });
        },
        survey_questionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.prompt, id: val.id}
        },
        
    
        
        survey_responsesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.overall_comment)
        },
        survey_responsesOneListFormatter(val) {
            if (!val) return ''
            return val.overall_comment
        },
        survey_responsesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.overall_comment}
            });
        },
        survey_responsesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.overall_comment, id: val.id}
        },
        
    
        
    
        
    
        
    
}
