import helpers from '@/helpers'

export default {
  getRemainingDay: () => endDate => {
    let oneDay = 24 * 60 * 60 * 1000 // hours*minutes*seconds*milliseconds
    let mStarDate = new Date()
    let mEndDate = new Date(endDate)
    let result = Math.round((mEndDate.getTime() - mStarDate.getTime()) / oneDay)
    return result < 0 ? 0 : result
  },
  getCountriesList: state => {
    return state.countriesList
  },
  getSelectedCountryId: state => {
    return state.selectedCountryId
  },
  getMyAccountMemberDetails: state => {
    return state.memberDetails
  },
  getGenderList: state => {
    return state.genderList
  },
  getCityByCountryIdStateId: state => (countryId, stateId) => {
    if (state.citiesList !== null) {
      let result = []
      state.citiesList.forEach(item => {
        if (parseInt(item.country_id) === parseInt(countryId) && parseInt(item.state_id) === parseInt(stateId)) {
          result.push({
            value: item.id,
            text: item.name,
          })
        }
      })
      return result
    }
  },
  getExpiryMonthRange: state => {
    return state.expiryMonthRange
  },
  getExpiryYearRange: state => {
    return state.expiryYearRange
  },
  getAvatarFile: state => {
    return state.avatarFile
  },
  getEthnicGroupList: state => {
    return state.ethnicGroupList
  },
  getMaritalStatusList: state => {
    return state.maritalStatusList
  },
  getPreferredContactList: state => {
    return state.preferredContactList
  },
  getPreferredContactNameById: state => id => {
    let res = ''
    state.preferredContactList.forEach(item => {
      if (item.value === id) {
        res = item.text
      }
    })
    return res
  },
  getMyAccountIsPreferredContactType: state => type => {
    let memberContentType = helpers.getValue(state.contact_info, 'preferred_contact_id')
    if (memberContentType) {
      return memberContentType === type
    }
    return false
  },
  getDependentList: (state, getters, rootState) => {
    let data = helpers.getValue(rootState, 'locationModule.countryRelation.data.member_dependent_config', [])
    return data.map(opt => ({
      text: opt.status_code.title + ' - ' + opt.status_description.title,
      value: opt.id,
    }))
  },
  getPlacementPreference: state => {
    return state.placementPreference
  },
  getAmpAccumulations: state => {
    return state.ampAccumulations
  },
}
