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}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        companiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.company_name)
        },
        companiesOneListFormatter(val) {
            if (!val) return ''
            return val.company_name
        },
        companiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.company_name}
            });
        },
        companiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.company_name, id: val.id}
        },
        
    
        
    
        
        branchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.branch_name)
        },
        branchesOneListFormatter(val) {
            if (!val) return ''
            return val.branch_name
        },
        branchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.branch_name}
            });
        },
        branchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.branch_name, id: val.id}
        },
        
    
        
        departmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.department_name)
        },
        departmentsOneListFormatter(val) {
            if (!val) return ''
            return val.department_name
        },
        departmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.department_name}
            });
        },
        departmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.department_name, id: val.id}
        },
        
    
        
        compliance_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.category_name)
        },
        compliance_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.category_name
        },
        compliance_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.category_name}
            });
        },
        compliance_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.category_name, id: val.id}
        },
        
    
        
        compliance_templatesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.template_name)
        },
        compliance_templatesOneListFormatter(val) {
            if (!val) return ''
            return val.template_name
        },
        compliance_templatesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.template_name}
            });
        },
        compliance_templatesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.template_name, id: val.id}
        },
        
    
        
        company_compliancesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.compliance_title)
        },
        company_compliancesOneListFormatter(val) {
            if (!val) return ''
            return val.compliance_title
        },
        company_compliancesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.compliance_title}
            });
        },
        company_compliancesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.compliance_title, id: val.id}
        },
        
    
        
        tasksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.task_title)
        },
        tasksOneListFormatter(val) {
            if (!val) return ''
            return val.task_title
        },
        tasksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.task_title}
            });
        },
        tasksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.task_title, id: val.id}
        },
        
    
        
        documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.document_title)
        },
        documentsOneListFormatter(val) {
            if (!val) return ''
            return val.document_title
        },
        documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.document_title}
            });
        },
        documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.document_title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        subscription_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plan_name)
        },
        subscription_plansOneListFormatter(val) {
            if (!val) return ''
            return val.plan_name
        },
        subscription_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plan_name}
            });
        },
        subscription_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plan_name, id: val.id}
        },
        
    
        
        company_subscriptionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.status)
        },
        company_subscriptionsOneListFormatter(val) {
            if (!val) return ''
            return val.status
        },
        company_subscriptionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.status}
            });
        },
        company_subscriptionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.status, id: val.id}
        },
        
    
        
    
        
        ai_chat_sessionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.session_title)
        },
        ai_chat_sessionsOneListFormatter(val) {
            if (!val) return ''
            return val.session_title
        },
        ai_chat_sessionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.session_title}
            });
        },
        ai_chat_sessionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.session_title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
