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}
        },
        
    
        
    
        
        gdpr_consentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.consent_version)
        },
        gdpr_consentsOneListFormatter(val) {
            if (!val) return ''
            return val.consent_version
        },
        gdpr_consentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.consent_version}
            });
        },
        gdpr_consentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.consent_version, id: val.id}
        },
        
    
        
    
        
    
        
        hotelsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        hotelsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        hotelsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        hotelsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        room_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        room_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        room_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        room_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        roomsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.room_number)
        },
        roomsOneListFormatter(val) {
            if (!val) return ''
            return val.room_number
        },
        roomsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.room_number}
            });
        },
        roomsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.room_number, id: val.id}
        },
        
    
        
        amenitiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        amenitiesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        amenitiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        amenitiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        room_featuresManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        room_featuresOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        room_featuresManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        room_featuresOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        rate_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        rate_plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        rate_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        rate_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        guestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.email)
        },
        guestsOneListFormatter(val) {
            if (!val) return ''
            return val.email
        },
        guestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.email}
            });
        },
        guestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.email, id: val.id}
        },
        
    
        
        bookingsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.booking_code)
        },
        bookingsOneListFormatter(val) {
            if (!val) return ''
            return val.booking_code
        },
        bookingsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.booking_code}
            });
        },
        bookingsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.booking_code, id: val.id}
        },
        
    
        
        booking_guestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.guest_role)
        },
        booking_guestsOneListFormatter(val) {
            if (!val) return ''
            return val.guest_role
        },
        booking_guestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.guest_role}
            });
        },
        booking_guestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.guest_role, id: val.id}
        },
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.provider_reference)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.provider_reference
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.provider_reference}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.provider_reference, id: val.id}
        },
        
    
        
    
        
        messagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.subject)
        },
        messagesOneListFormatter(val) {
            if (!val) return ''
            return val.subject
        },
        messagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.subject}
            });
        },
        messagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.subject, id: val.id}
        },
        
    
        
        promo_codesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        promo_codesOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        promo_codesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        promo_codesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
}
