export const getDefaultState = () => ({
  orders: [],
  order: {
    id: null,
    shippingType: '',
    address: '',
    bankAccountId: '',
    customerId: '',
    email: '',
    name: '',
    paymentSlip: '',
    promotionCode: '',
    salePageDomain: '',
    shippop: false,
    taxable: false,
    taxId: '',
    tel: '',
    transferredAt: '',
    purchases: [],
    setPurchases: [],
    net: 0
  }
})
const state = getDefaultState()
const mutations = {
  SET_ORDERS (state, payload) {
    state.orders = payload
  },
  SET_ORDER (state, payload) {
    state.order = payload
  },
  CLEAR_ORDER (state, payload) {
    state.order = payload
  }
}

const actions = {
  setOrders ({ commit }, payload) {
    commit('SET_ORDERS', payload)
  },
  setOrder ({ commit }, payload) {
    commit('SET_ORDER', payload)
  },
  clearOrder ({ commit }) {
    const defaultState = getDefaultState()
    commit('CLEAR_ORDER', defaultState.order)
  }
}

const getters = {
  orders: (state) => state.orders,
  order: (state) => state.order
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
}
