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}
        },

        branchesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        branchesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        branchesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        branchesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        client_statusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        client_statusOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        client_statusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        client_statusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        clientsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        clientsOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        clientsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        clientsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        communesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        communesOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        communesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        communesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        depositsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.deposit_amount)
        },
        depositsOneListFormatter(val) {
            if (!val) return ''
            return val.deposit_amount
        },
        depositsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.deposit_amount}
            });
        },
        depositsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.deposit_amount, id: val.id}
        },

        districtsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        districtsOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        districtsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        districtsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        document_typeManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        document_typeOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        document_typeManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        document_typeOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        expense_itemsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.description)
        },
        expense_itemsOneListFormatter(val) {
            if (!val) return ''
            return val.description
        },
        expense_itemsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.description}
            });
        },
        expense_itemsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.description, id: val.id}
        },

        expense_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        expense_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        expense_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        expense_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        group_menusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        group_menusOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        group_menusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        group_menusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        interest_ratesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        interest_ratesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        interest_ratesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        interest_ratesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        loan_statusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        loan_statusOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        loan_statusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        loan_statusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        loan_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        loan_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        loan_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        loan_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        loansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        loansOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        loansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        loansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },

        menusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.label)
        },
        menusOneListFormatter(val) {
            if (!val) return ''
            return val.label
        },
        menusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.label}
            });
        },
        menusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.label, id: val.id}
        },

        payment_revenuesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.transaction_date)
        },
        payment_revenuesOneListFormatter(val) {
            if (!val) return ''
            return val.transaction_date
        },
        payment_revenuesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.transaction_date}
            });
        },
        payment_revenuesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.transaction_date, id: val.id}
        },

        payment_statusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        payment_statusOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        payment_statusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        payment_statusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        paymentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.remark)
        },
        paymentsOneListFormatter(val) {
            if (!val) return ''
            return val.remark
        },
        paymentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.remark}
            });
        },
        paymentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.remark, id: val.id}
        },

        provincesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        provincesOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        provincesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        provincesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        sexesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        sexesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        sexesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        sexesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        shareholdersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        shareholdersOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        shareholdersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        shareholdersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        staff_statusManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        staff_statusOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        staff_statusManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        staff_statusOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        staffsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        staffsOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        staffsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        staffsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

        urlsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.uri)
        },
        urlsOneListFormatter(val) {
            if (!val) return ''
            return val.uri
        },
        urlsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.uri}
            });
        },
        urlsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.uri, id: val.id}
        },

        user_typesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        user_typesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        user_typesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        user_typesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },

        villagesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name_en)
        },
        villagesOneListFormatter(val) {
            if (!val) return ''
            return val.name_en
        },
        villagesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name_en}
            });
        },
        villagesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name_en, id: val.id}
        },

}
