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}
        },
        
    
        
    
        
    
        
        school_yearsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        school_yearsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        school_yearsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        school_yearsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        gradesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        gradesOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        gradesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        gradesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },
        
    
        
        streamsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        streamsOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        streamsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        streamsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },
        
    
        
        subjectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        subjectsOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        subjectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        subjectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },
        
    
        
    
        
        staff_membersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        staff_membersOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        staff_membersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        staff_membersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        studentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        studentsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        studentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        studentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        class_sectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        class_sectionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        class_sectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        class_sectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        termsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.term_name)
        },
        termsOneListFormatter(val) {
            if (!val) return ''
            return val.term_name
        },
        termsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.term_name}
            });
        },
        termsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.term_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        examsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        examsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        examsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        examsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        attendance_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.note)
        },
        attendance_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.note
        },
        attendance_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.note}
            });
        },
        attendance_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.note, id: val.id}
        },
        
    
        
    
        
    
        
        assignmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        assignmentsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        assignmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        assignmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
