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}
        },
        
    
        
        tenantsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        tenantsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        tenantsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        tenantsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        propertiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        propertiesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        propertiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        propertiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, 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}
        },
        
    
        
        unit_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        unit_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        unit_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        unit_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        unitsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.unit_number)
        },
        unitsOneListFormatter(val) {
            if (!val) return ''
            return val.unit_number
        },
        unitsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.unit_number}
            });
        },
        unitsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.unit_number, id: val.id}
        },
        
    
        
        unit_availability_blocksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reason)
        },
        unit_availability_blocksOneListFormatter(val) {
            if (!val) return ''
            return val.reason
        },
        unit_availability_blocksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reason}
            });
        },
        unit_availability_blocksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reason, id: val.id}
        },
        
    
        
    
        
        booking_requestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.request_code)
        },
        booking_requestsOneListFormatter(val) {
            if (!val) return ''
            return val.request_code
        },
        booking_requestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.request_code}
            });
        },
        booking_requestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.request_code, id: val.id}
        },
        
    
        
        booking_request_travelersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        booking_request_travelersOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        booking_request_travelersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        booking_request_travelersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        approval_stepsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.decision_notes)
        },
        approval_stepsOneListFormatter(val) {
            if (!val) return ''
            return val.decision_notes
        },
        approval_stepsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.decision_notes}
            });
        },
        approval_stepsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.decision_notes, id: val.id}
        },
        
    
        
        reservationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reservation_code)
        },
        reservationsOneListFormatter(val) {
            if (!val) return ''
            return val.reservation_code
        },
        reservationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reservation_code}
            });
        },
        reservationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reservation_code, id: val.id}
        },
        
    
        
        reservation_guestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.full_name)
        },
        reservation_guestsOneListFormatter(val) {
            if (!val) return ''
            return val.full_name
        },
        reservation_guestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.full_name}
            });
        },
        reservation_guestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.full_name, id: val.id}
        },
        
    
        
        service_requestsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.summary)
        },
        service_requestsOneListFormatter(val) {
            if (!val) return ''
            return val.summary
        },
        service_requestsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.summary}
            });
        },
        service_requestsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.summary, id: val.id}
        },
        
    
        
        invoicesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.invoice_number)
        },
        invoicesOneListFormatter(val) {
            if (!val) return ''
            return val.invoice_number
        },
        invoicesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.invoice_number}
            });
        },
        invoicesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.invoice_number, id: val.id}
        },
        
    
        
        invoice_line_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.description)
        },
        invoice_line_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.description
        },
        invoice_line_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.description}
            });
        },
        invoice_line_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.description, id: val.id}
        },
        
    
        
        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reference)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.reference
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reference}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reference, id: val.id}
        },
        
    
        
        documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.file_name)
        },
        documentsOneListFormatter(val) {
            if (!val) return ''
            return val.file_name
        },
        documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.file_name}
            });
        },
        documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.file_name, id: val.id}
        },
        
    
        
        audit_logsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.action)
        },
        audit_logsOneListFormatter(val) {
            if (!val) return ''
            return val.action
        },
        audit_logsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.action}
            });
        },
        audit_logsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.action, id: val.id}
        },
        
    
        
    
        
        activity_commentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.body)
        },
        activity_commentsOneListFormatter(val) {
            if (!val) return ''
            return val.body
        },
        activity_commentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.body}
            });
        },
        activity_commentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.body, id: val.id}
        },
        
    
        
        checklistsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        checklistsOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        checklistsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        checklistsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
        checklist_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        checklist_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        checklist_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        checklist_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
}
