import { getValue } from '@/helpers/variable-handling'

const fullName = new Map([
  ['iwb', 'Common.Terminology.InfinityWelcomeBonus'],
  ['tvc', 'Common.Terminology.TeamValueCommission'],
  ['mb', 'Common.Terminology.MatchingBonus'],
])

export function weekDataPostProcessor(data) {
  if (getValue(data, 'commissions_and_bonuses.weeks')) {
    let tempData = data.commissions_and_bonuses.weeks
    let values = []

    tempData[0].value.forEach(value => {
      let hasIcon = ['iwb', 'tvc', 'mb'].indexOf(value.key) !== -1

      values.push({
        value: value.title,
        key: value.key,
        iconName: hasIcon ? 'info-circle-icon' : null,
        tooltips: hasIcon ? fullName.get(value.key) : null,
      })
    })

    let newItem = {
      key: 'title',
      title: ' ',
      value: values,
    }
    tempData.unshift(newItem)

    data.commissions_and_bonuses.weeks = tempData
  }
  return data
}
