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}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        healthcare_providersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_name)
        },
        healthcare_providersOneListFormatter(val) {
            if (!val) return ''
            return val.provider_name
        },
        healthcare_providersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_name}
            });
        },
        healthcare_providersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_name, id: val.id}
        },
        
    
        
        pharmaciesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.pharmacy_name)
        },
        pharmaciesOneListFormatter(val) {
            if (!val) return ''
            return val.pharmacy_name
        },
        pharmaciesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.pharmacy_name}
            });
        },
        pharmaciesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.pharmacy_name, id: val.id}
        },
        
    
        
        medicationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.medication_name)
        },
        medicationsOneListFormatter(val) {
            if (!val) return ''
            return val.medication_name
        },
        medicationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.medication_name}
            });
        },
        medicationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.medication_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
        workoutsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.workout_name)
        },
        workoutsOneListFormatter(val) {
            if (!val) return ''
            return val.workout_name
        },
        workoutsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.workout_name}
            });
        },
        workoutsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.workout_name, id: val.id}
        },
        
    
        
        exercisesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.exercise_name)
        },
        exercisesOneListFormatter(val) {
            if (!val) return ''
            return val.exercise_name
        },
        exercisesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.exercise_name}
            });
        },
        exercisesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.exercise_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        workout_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        workout_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        workout_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        workout_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
        foodsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.food_name)
        },
        foodsOneListFormatter(val) {
            if (!val) return ''
            return val.food_name
        },
        foodsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.food_name}
            });
        },
        foodsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.food_name, id: val.id}
        },
        
    
        
        recipesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.recipe_name)
        },
        recipesOneListFormatter(val) {
            if (!val) return ''
            return val.recipe_name
        },
        recipesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.recipe_name}
            });
        },
        recipesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.recipe_name, id: val.id}
        },
        
    
        
    
        
        mealsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.meal_title)
        },
        mealsOneListFormatter(val) {
            if (!val) return ''
            return val.meal_title
        },
        mealsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.meal_title}
            });
        },
        mealsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.meal_title, id: val.id}
        },
        
    
        
    
        
    
        
        meal_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.dietary_restrictions)
        },
        meal_plansOneListFormatter(val) {
            if (!val) return ''
            return val.dietary_restrictions
        },
        meal_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.dietary_restrictions}
            });
        },
        meal_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.dietary_restrictions, id: val.id}
        },
        
    
        
    
        
        grocery_listsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        grocery_listsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        grocery_listsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        grocery_listsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        ai_chat_threadsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.thread_title)
        },
        ai_chat_threadsOneListFormatter(val) {
            if (!val) return ''
            return val.thread_title
        },
        ai_chat_threadsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.thread_title}
            });
        },
        ai_chat_threadsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.thread_title, id: val.id}
        },
        
    
        
    
        
    
        
        habitsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.habit_name)
        },
        habitsOneListFormatter(val) {
            if (!val) return ''
            return val.habit_name
        },
        habitsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.habit_name}
            });
        },
        habitsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.habit_name, id: val.id}
        },
        
    
        
    
        
    
        
        library_articlesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        library_articlesOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        library_articlesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        library_articlesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        family_groupsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.group_name)
        },
        family_groupsOneListFormatter(val) {
            if (!val) return ''
            return val.group_name
        },
        family_groupsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.group_name}
            });
        },
        family_groupsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.group_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        menstrual_cyclesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        menstrual_cyclesOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        menstrual_cyclesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        menstrual_cyclesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
    
        
        pregnanciesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        pregnanciesOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        pregnanciesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        pregnanciesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        contraction_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        contraction_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        contraction_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        contraction_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
        injuriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.diagnosis)
        },
        injuriesOneListFormatter(val) {
            if (!val) return ''
            return val.diagnosis
        },
        injuriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.diagnosis}
            });
        },
        injuriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.diagnosis, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
}
