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}
        },
        
    
        
    
        
        contact_locationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        contact_locationsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        contact_locationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        contact_locationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
    
        
    
        
        stone_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        stone_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        stone_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        stone_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        stone_colorsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        stone_colorsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        stone_colorsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        stone_colorsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        finishesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        finishesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        finishesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        finishesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        applicationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        applicationsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        applicationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        applicationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        stonesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        stonesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        stonesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        stonesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        stone_variantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.sku)
        },
        stone_variantsOneListFormatter(val) {
            if (!val) return ''
            return val.sku
        },
        stone_variantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.sku}
            });
        },
        stone_variantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.sku, id: val.id}
        },
        
    
        
    
        
        servicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        servicesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        servicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        servicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
        technologiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        technologiesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        technologiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        technologiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
    
        
        projectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        projectsOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        projectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        projectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
    
        
    
        
        blog_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_ar)
        },
        blog_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.name_ar
        },
        blog_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_ar}
            });
        },
        blog_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_ar, id: val.id}
        },
        
    
        
    
        
        lead_requestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        lead_requestsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        lead_requestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        lead_requestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
