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}
        },
        
    
        
    
        
    
        
        membership_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plan_name)
        },
        membership_plansOneListFormatter(val) {
            if (!val) return ''
            return val.plan_name
        },
        membership_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plan_name}
            });
        },
        membership_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plan_name, id: val.id}
        },
        
    
        
        membershipsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.stripe_subscription_ref)
        },
        membershipsOneListFormatter(val) {
            if (!val) return ''
            return val.stripe_subscription_ref
        },
        membershipsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.stripe_subscription_ref}
            });
        },
        membershipsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.stripe_subscription_ref, id: val.id}
        },
        
    
        
    
        
        coursesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.course_title)
        },
        coursesOneListFormatter(val) {
            if (!val) return ''
            return val.course_title
        },
        coursesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.course_title}
            });
        },
        coursesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.course_title, id: val.id}
        },
        
    
        
        lessonsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.lesson_title)
        },
        lessonsOneListFormatter(val) {
            if (!val) return ''
            return val.lesson_title
        },
        lessonsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.lesson_title}
            });
        },
        lessonsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.lesson_title, id: val.id}
        },
        
    
        
    
        
    
        
        artifactsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        artifactsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        artifactsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        artifactsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
        trophiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.trophy_name)
        },
        trophiesOneListFormatter(val) {
            if (!val) return ''
            return val.trophy_name
        },
        trophiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.trophy_name}
            });
        },
        trophiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.trophy_name, id: val.id}
        },
        
    
        
    
        
        ai_gatewaysManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.gateway_name)
        },
        ai_gatewaysOneListFormatter(val) {
            if (!val) return ''
            return val.gateway_name
        },
        ai_gatewaysManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.gateway_name}
            });
        },
        ai_gatewaysOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.gateway_name, id: val.id}
        },
        
    
        
    
        
        ai_tasksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.task_name)
        },
        ai_tasksOneListFormatter(val) {
            if (!val) return ''
            return val.task_name
        },
        ai_tasksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.task_name}
            });
        },
        ai_tasksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.task_name, id: val.id}
        },
        
    
        
        ai_requestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.model_used)
        },
        ai_requestsOneListFormatter(val) {
            if (!val) return ''
            return val.model_used
        },
        ai_requestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.model_used}
            });
        },
        ai_requestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.model_used, id: val.id}
        },
        
    
        
    
        
        coaching_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.topic)
        },
        coaching_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.topic
        },
        coaching_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.topic}
            });
        },
        coaching_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.topic, id: val.id}
        },
        
    
        
    
        
        resume_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.document_name)
        },
        resume_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.document_name
        },
        resume_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.document_name}
            });
        },
        resume_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.document_name, id: val.id}
        },
        
    
        
    
        
    
}
