import omitBy from 'lodash/omitBy'
import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'

import type { MatchSubscription, SubscriptionType } from 'features/BuyMatchPopup/types'

type PaymentTab = {
  tabLexic: string,
  type: SubscriptionType,
}

const getTabLexic = (type: string) => {
  switch (type) {
    case 'month':
      return 'for_month'
    case 'year':
      return 'for_year'
    case 'pay_per_view':
      return 'for_view'
    default:
      return ''
  }
}

export const getCorrectPaymentTabs = (matchSubscriptions: MatchSubscription) => {
  const matchSubscriptionsWithValues = omitBy(matchSubscriptions.packages, isEmpty)
  return map(matchSubscriptionsWithValues, (matchSubscription, key) => ({
    tabLexic: getTabLexic(key),
    type: key,
  })) as Array<PaymentTab>
}
