
/* eslint-disable no-alert, no-console ,  no-debugger */
import { doFetchOrderHistory } from '@/services/product.service';
import { getField, updateField } from 'vuex-map-fields';
import humps from 'lodash-humps';

export const orderlist = {
    namespaced: true,
    state: {
        inProgress: true,
        OrderHistory: {},
       
        // orderNumber: "",
        // createdDate: "",
        // toDate: "",
        // purchaseOrderNumber: "",

    },
    getters: {
        getField,

    },
    mutations: {
        updateField,
        inProgress(state, yesOrNo) {
            state.inProgress = yesOrNo
        },
        // SetOrderlist(state, orderItem) {
        // // console.log(state.orderNumber=orderItem)
        // }  ,
        setOrderHistory(state, orderhistorydata) {
            state.OrderHistory = orderhistorydata
        },
    },

    actions: {
        searchOrder: ({ commit }, orderItem) => {
            commit('SetOrderlist', orderItem);
        },
        fetchOrderList: async ({ commit },customerId) => {
            try {
                commit('inProgress', true);
                let OrderHistory = await doFetchOrderHistory(customerId);
                if (OrderHistory) {
                    commit('inProgress', false);
                    commit('setOrderHistory', humps(OrderHistory));
                }
            }
            catch (error) {
                commit('inProgress', false);
                throw error
            }
        },
       
       
    }
}




