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}
        },
        
    
        
        schoolsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        schoolsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        schoolsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        schoolsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        grade_levelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.grade_name)
        },
        grade_levelsOneListFormatter(val) {
            if (!val) return ''
            return val.grade_name
        },
        grade_levelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.grade_name}
            });
        },
        grade_levelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.grade_name, id: val.id}
        },
        
    
        
        subjectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.subject_name)
        },
        subjectsOneListFormatter(val) {
            if (!val) return ''
            return val.subject_name
        },
        subjectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.subject_name}
            });
        },
        subjectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.subject_name, id: val.id}
        },
        
    
        
        classroomsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.classroom_name)
        },
        classroomsOneListFormatter(val) {
            if (!val) return ''
            return val.classroom_name
        },
        classroomsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.classroom_name}
            });
        },
        classroomsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.classroom_name, id: val.id}
        },
        
    
        
    
        
    
        
        homeworksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.homework_title)
        },
        homeworksOneListFormatter(val) {
            if (!val) return ''
            return val.homework_title
        },
        homeworksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.homework_title}
            });
        },
        homeworksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.homework_title, id: val.id}
        },
        
    
        
        homework_rubricsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.criterion_title)
        },
        homework_rubricsOneListFormatter(val) {
            if (!val) return ''
            return val.criterion_title
        },
        homework_rubricsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.criterion_title}
            });
        },
        homework_rubricsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.criterion_title, id: val.id}
        },
        
    
        
    
        
        homework_submissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.submission_status)
        },
        homework_submissionsOneListFormatter(val) {
            if (!val) return ''
            return val.submission_status
        },
        homework_submissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.submission_status}
            });
        },
        homework_submissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.submission_status, id: val.id}
        },
        
    
        
        submission_gradesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.grade_status)
        },
        submission_gradesOneListFormatter(val) {
            if (!val) return ''
            return val.grade_status
        },
        submission_gradesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.grade_status}
            });
        },
        submission_gradesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.grade_status, id: val.id}
        },
        
    
        
    
        
        gradebooksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.gradebook_name)
        },
        gradebooksOneListFormatter(val) {
            if (!val) return ''
            return val.gradebook_name
        },
        gradebooksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.gradebook_name}
            });
        },
        gradebooksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.gradebook_name, id: val.id}
        },
        
    
        
        gradebook_columnsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.column_name)
        },
        gradebook_columnsOneListFormatter(val) {
            if (!val) return ''
            return val.column_name
        },
        gradebook_columnsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.column_name}
            });
        },
        gradebook_columnsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.column_name, id: val.id}
        },
        
    
        
    
        
    
        
        announcementsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.announcement_title)
        },
        announcementsOneListFormatter(val) {
            if (!val) return ''
            return val.announcement_title
        },
        announcementsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.announcement_title}
            });
        },
        announcementsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.announcement_title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
