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}
        },
        
    
        
        suppliersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.supplier_name)
        },
        suppliersOneListFormatter(val) {
            if (!val) return ''
            return val.supplier_name
        },
        suppliersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.supplier_name}
            });
        },
        suppliersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.supplier_name, id: val.id}
        },
        
    
        
        customersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.customer_name)
        },
        customersOneListFormatter(val) {
            if (!val) return ''
            return val.customer_name
        },
        customersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.customer_name}
            });
        },
        customersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.customer_name, id: val.id}
        },
        
    
        
        uomsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.uom_name)
        },
        uomsOneListFormatter(val) {
            if (!val) return ''
            return val.uom_name
        },
        uomsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.uom_name}
            });
        },
        uomsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.uom_name, id: val.id}
        },
        
    
        
        item_categoriesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.category_name)
        },
        item_categoriesOneListFormatter(val) {
            if (!val) return ''
            return val.category_name
        },
        item_categoriesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.category_name}
            });
        },
        item_categoriesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.category_name, id: val.id}
        },
        
    
        
        itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.item_name)
        },
        itemsOneListFormatter(val) {
            if (!val) return ''
            return val.item_name
        },
        itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.item_name}
            });
        },
        itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.item_name, id: val.id}
        },
        
    
        
        warehousesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.warehouse_name)
        },
        warehousesOneListFormatter(val) {
            if (!val) return ''
            return val.warehouse_name
        },
        warehousesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.warehouse_name}
            });
        },
        warehousesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.warehouse_name, id: val.id}
        },
        
    
        
        locationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.location_name)
        },
        locationsOneListFormatter(val) {
            if (!val) return ''
            return val.location_name
        },
        locationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.location_name}
            });
        },
        locationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.location_name, id: val.id}
        },
        
    
        
        lotsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.lot_code)
        },
        lotsOneListFormatter(val) {
            if (!val) return ''
            return val.lot_code
        },
        lotsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.lot_code}
            });
        },
        lotsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.lot_code, id: val.id}
        },
        
    
        
    
        
        bomsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.bom_name)
        },
        bomsOneListFormatter(val) {
            if (!val) return ''
            return val.bom_name
        },
        bomsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.bom_name}
            });
        },
        bomsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.bom_name, id: val.id}
        },
        
    
        
    
        
        routesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.route_name)
        },
        routesOneListFormatter(val) {
            if (!val) return ''
            return val.route_name
        },
        routesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.route_name}
            });
        },
        routesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.route_name, id: val.id}
        },
        
    
        
        operationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.operation_name)
        },
        operationsOneListFormatter(val) {
            if (!val) return ''
            return val.operation_name
        },
        operationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.operation_name}
            });
        },
        operationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.operation_name, id: val.id}
        },
        
    
        
        machinesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.machine_name)
        },
        machinesOneListFormatter(val) {
            if (!val) return ''
            return val.machine_name
        },
        machinesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.machine_name}
            });
        },
        machinesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.machine_name, id: val.id}
        },
        
    
        
    
        
        work_centersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.work_center_name)
        },
        work_centersOneListFormatter(val) {
            if (!val) return ''
            return val.work_center_name
        },
        work_centersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.work_center_name}
            });
        },
        work_centersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.work_center_name, id: val.id}
        },
        
    
        
        production_linesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.line_name)
        },
        production_linesOneListFormatter(val) {
            if (!val) return ''
            return val.line_name
        },
        production_linesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.line_name}
            });
        },
        production_linesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.line_name, id: val.id}
        },
        
    
        
        work_ordersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.work_order_number)
        },
        work_ordersOneListFormatter(val) {
            if (!val) return ''
            return val.work_order_number
        },
        work_ordersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.work_order_number}
            });
        },
        work_ordersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.work_order_number, id: val.id}
        },
        
    
        
    
        
        material_issuesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.issue_number)
        },
        material_issuesOneListFormatter(val) {
            if (!val) return ''
            return val.issue_number
        },
        material_issuesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.issue_number}
            });
        },
        material_issuesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.issue_number, id: val.id}
        },
        
    
        
    
        
        receiptsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.receipt_number)
        },
        receiptsOneListFormatter(val) {
            if (!val) return ''
            return val.receipt_number
        },
        receiptsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.receipt_number}
            });
        },
        receiptsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.receipt_number, id: val.id}
        },
        
    
        
    
        
        shipmentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.shipment_number)
        },
        shipmentsOneListFormatter(val) {
            if (!val) return ''
            return val.shipment_number
        },
        shipmentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.shipment_number}
            });
        },
        shipmentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.shipment_number, id: val.id}
        },
        
    
        
    
        
        qa_inspection_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.plan_name)
        },
        qa_inspection_plansOneListFormatter(val) {
            if (!val) return ''
            return val.plan_name
        },
        qa_inspection_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.plan_name}
            });
        },
        qa_inspection_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.plan_name, id: val.id}
        },
        
    
        
        qa_characteristicsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.characteristic_name)
        },
        qa_characteristicsOneListFormatter(val) {
            if (!val) return ''
            return val.characteristic_name
        },
        qa_characteristicsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.characteristic_name}
            });
        },
        qa_characteristicsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.characteristic_name, id: val.id}
        },
        
    
        
        qa_inspectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.inspection_number)
        },
        qa_inspectionsOneListFormatter(val) {
            if (!val) return ''
            return val.inspection_number
        },
        qa_inspectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.inspection_number}
            });
        },
        qa_inspectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.inspection_number, id: val.id}
        },
        
    
        
    
        
    
        
    
}
