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}
        },
        
    
        
        subjectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        subjectsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        subjectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        subjectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        grade_levelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        grade_levelsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        grade_levelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        grade_levelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        textbooksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        textbooksOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        textbooksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        textbooksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        chaptersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        chaptersOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        chaptersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        chaptersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        curriculum_standardsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        curriculum_standardsOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        curriculum_standardsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        curriculum_standardsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },
        
    
        
        skillsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        skillsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        skillsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        skillsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        question_banksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        question_banksOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        question_banksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        question_banksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        questionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.content)
        },
        questionsOneListFormatter(val) {
            if (!val) return ''
            return val.content
        },
        questionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.content}
            });
        },
        questionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.content, id: val.id}
        },
        
    
        
    
        
        testsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        testsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        testsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        testsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        test_sectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        test_sectionsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        test_sectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        test_sectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        test_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.override_content)
        },
        test_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.override_content
        },
        test_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.override_content}
            });
        },
        test_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.override_content, id: val.id}
        },
        
    
        
        test_versionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.version_label)
        },
        test_versionsOneListFormatter(val) {
            if (!val) return ''
            return val.version_label
        },
        test_versionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.version_label}
            });
        },
        test_versionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.version_label, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        test_matricesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        test_matricesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        test_matricesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        test_matricesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
    
}
