import {
  CONFIRM_ORDER_STEP,
  CANCEL_ORDER_STEP,
  SET_COLLECTION_POINT_STATE,
  SET_COLLECTION_POINT_CITY,
  SET_CART_LIST,
  SET_EWALLET_PAYMENT,
  SET_SHIPPING_METHOD_USED,
  SET_PAYMENT_METHOD_USED,
  SET_RECIPIENT_DETAIL,
  SET_SHIPPING_ADDRESS,
  ESHOP_ORDER_SET_SHIPPING_DATA,
  SET_PAYMENT_DOCUMENT_DETAILS,
  CLEAR_LOADED_DATA,
  SET_PAYMENT_STEP_STATUS,
} from '../../../utils/types'

export default {
  [SET_CART_LIST](state, data) {
    state.cartList = data
  },
  [SET_COLLECTION_POINT_STATE](state, data) {
    state.collPointState = data
  },
  [SET_COLLECTION_POINT_CITY](state, data) {
    state.collPointCity = data
  },
  [SET_EWALLET_PAYMENT](state, data) {
    state.ewalletAmount = data
  },
  [SET_SHIPPING_METHOD_USED](state, data) {
    state.shippingMethodUsed = data
  },
  [SET_SHIPPING_ADDRESS](state, data) {
    state.existingAddresses = data
  },
  [SET_PAYMENT_METHOD_USED](state, data) {
    state.paymentMethodUsed = data
  },
  [SET_RECIPIENT_DETAIL](state, data) {
    state.recipientDetail = data
  },
  [CONFIRM_ORDER_STEP](state, data) {
    state.orderReviewStep = data
    if (data === 'orderPayment') {
      state.orderSummaryPromo = ''
      state.reviewAndShipping['active-step'] = true
      state.makePayment['active-step'] = true
    } else if (data === 'orderReviewAndShipping') {
      state.orderSummaryPromo = 'orderSummaryPromo'
      state.reviewAndShipping['active-step'] = true
      state.makePayment['active-step'] = false
      state.orderCompleted['active-step'] = false
    } else {
      // Go to step 3
      state.orderItems = ''
      state.orderSummary = ''
      state.reviewAndShipping['active-step'] = true
      state.makePayment['active-step'] = true
      state.orderCompleted['active-step'] = true
    }
  },
  [CANCEL_ORDER_STEP](state, data) {
    state.orderReviewStep = data
    state.orderItems = 'orderReviewItems'
    state.orderSummary = 'orderSummary'
    if (data === 'orderReviewAndShipping') {
      state.orderSummaryPromo = 'orderSummaryPromo'
      state.reviewAndShipping['active-step'] = true
      state.makePayment['active-step'] = false
    } else {
      // Back to step 2
      state.makePayment['active-step'] = true
      state.orderCompleted['active-step'] = false
    }
  },
  [ESHOP_ORDER_SET_SHIPPING_DATA](state, data) {
    state.shippingData = data
  },
  [SET_PAYMENT_DOCUMENT_DETAILS](state, data) {
    if (data !== undefined && data !== null) {
      state.paymentDocumentDetails = data
      state.paymentDocumentDetails.document_data = JSON.parse(data.document_data)
    }
  },
  [SET_PAYMENT_STEP_STATUS](state, data) {
    state.paymentStepStatus = data
  },
  [CLEAR_LOADED_DATA](state, type) {
    if (type === 'order' || !type) {
      state.shippingData = null
      state.paymentStepStatus = { validated: false }
    }
  },
}
