import { LOGGED_IN_USER } from '../../utils/localStorageKeys'

export default {
  getEsacCountryId: state => {
    if (state.esacMemberData !== null && state.esacMemberData.details !== null) {
      return state.esacMemberData.details.country_id
    }
  },
  getEsacUserId: state => {
    if (localStorage.getItem(LOGGED_IN_USER) !== null) {
      return JSON.parse(localStorage.getItem(LOGGED_IN_USER)).id
    }
  },
  getEsacProductSearchPaginationSize: state => {
    return state.esacProductSearchPaginationSize
  },
  getEsacVoucherListPaginationSize: state => {
    return state.esacVoucherListPaginationSize
  },
  getEsacVoucherListTotalRows: state => {
    return state.esacVoucherListTotalRows
  },
  getEsacVoucherListSearchText: state => {
    return state.esacVoucherListSearchText
  },
  getEsacRouterData: state => {
    return state.esacRouterData
  },
  getEsacComponentName: state => {
    let componentName = ''
    let currentStep = state.esacRouterData.currentStep
    if (currentStep === 'SelectProduct') {
      componentName = 'ProductSelection'
    } else if (currentStep === 'ReviewAndShipping') {
      componentName = 'ReviewAndShipping'
    } else if (currentStep === 'MakePayment') {
      componentName = 'MakePayment'
    } else if (currentStep === 'OrderCompleted') {
      componentName = 'OrderCompleted'
    }
    return componentName
  },
  getEsacVoucherData: state => {
    return state.esacRedemptionData.voucherData
  },
  getEsacProductCategoryData: state => {
    return state.esacRedemptionData.productCategoryData
  },
  getEsacProductData: state => {
    return state.esacRedemptionData.productData
  },
  getEsacProductSearchVisible: state => {
    return state.esacRedemptionData.productSearchVisible
  },
  // getEsacShippingData: state => {
  //   return state.esacRedemptionData.shippingDataData
  // },
  getEsacSaleCreationData: state => {
    return state.esacRedemptionData.saleCreationData
  },
  getEsacSaleData: state => {
    return state.esacRedemptionData.saleData
  },
  getEsacPaymentData: state => {
    return state.esacRedemptionData.paymentData
  },
  getEsacVisibleVoucherCount: state => {
    let visibleVoucherCount = 0
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.visible === true) {
        visibleVoucherCount++
      }
    })
    return visibleVoucherCount
  },
  getEsacSelectedVoucherCount: state => {
    let selectedVoucherCount = 0
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.selected === true) {
        selectedVoucherCount++
      }
    })
    return selectedVoucherCount
  },
  getEntitledByProductCategory: state => {
    let entitledByProductCategory = false
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.selected === true && item.esac_promotion_entitled_by === 'C') {
        entitledByProductCategory = true
      }
    })
    return entitledByProductCategory
  },
  getEsacMaxPurchaseQuantity: state => {
    let maxPurchaseQty = 0
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.selected === true) {
        maxPurchaseQty += parseFloat(item.max_purchase_qty)
      }
    })
    return maxPurchaseQty
  },
  getEsacMinPurchaseAmount: state => {
    let minPurchaseAmount = 0
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.selected === true) {
        minPurchaseAmount += parseFloat(item.min_purchase_amount)
      }
    })
    return minPurchaseAmount
  },
  getEsacTotalVoucherValue: state => {
    let totalVoucherValue = 0
    state.esacRedemptionData.voucherData.forEach(item => {
      if (item.selected === true) {
        totalVoucherValue += parseFloat(item.voucher_value)
      }
    })
    return totalVoucherValue
  },
  getEsacTotalPurchaseQuantity: state => {
    let totalPurchaseQuantity = 0
    state.esacRedemptionData.productData.forEach(item => {
      if (item.selected === true) {
        totalPurchaseQuantity += item.quantity
      }
    })
    return totalPurchaseQuantity
  },
  getEsacTotalPurchaseAmount: state => {
    let totalPurchaseAmount = 0
    state.esacRedemptionData.productData.forEach(item => {
      if (item.selected === true) {
        totalPurchaseAmount += item.amount
      }
    })
    return totalPurchaseAmount
  },
  getEsacTotalSearchQuantity: state => {
    let totalSearchQuantity = 0
    state.esacRedemptionData.productData.forEach(item => {
      if (item.searched === true) {
        totalSearchQuantity += item.searchQuantity
      }
    })
    return totalSearchQuantity
  },
  getEsacProductSearchTotalItem: state => {
    let totalSearchItem = 0
    state.esacRedemptionData.productData.forEach(item => {
      if (item.searched === true) {
        totalSearchItem++
      }
    })
    return totalSearchItem
  },
  getEsacCurrencyCode: state => {
    if (
      state.esacCountryRelationData !== null &&
      state.esacCountryRelationData.currency !== undefined &&
      state.esacCountryRelationData.currency.code !== null
    ) {
      return state.esacCountryRelationData.currency.code
    } else {
      return ''
    }
  },
  getEsacCwSchedulesData: state => {
    return state.esacCwScheduleData
  },
  getEsacActiveCountryData: state => {
    return state.esacActiveCountryData
  },
  getEsacCountryRelationData: state => {
    return state.esacCountryRelationData
  },
  getEsacAddressFormatData: state => {
    return state.esacAddressFormatData
  },
  getEsacMemberData: state => {
    return state.esacMemberData
  },
  getEsacStateCityData: state => {
    return state.esacStateCityData
  },
  getEsacLocationAddressData: state => {
    return state.esacLocationAddressData
  },
  getEsacTransactionLocationId: state => {
    return state.esacTransactionLocationId
  },
  getEsacStockLocationId: state => countryId => {
    return state.esacStockLocationId
  },
  getEsacPaymentModeSettingData: state => {
    return state.esacPaymentModeSettingData
  },
  getEsacDownloadInvoiceData: state => {
    return state.esacDownloadInvoiceData
  },
  getEsacPaymentSaleId: state => {
    return state.esacRedemptionData.paymentSaleId
  },
  getEsacCompletedSaleId: state => {
    return state.esacRedemptionData.completedSaleId
  },
}
