import { ProfileTypes } from 'config'

import type { UserFavorite } from 'requests/getUserSportFavs'
import { getName } from 'features/Name'

export const getFavoriteItemNames = (item: UserFavorite, suffix: string) => {
  const { info, type } = item

  const currentName = {
    name_eng: info.name_eng || info.nickname_eng,
    name_rus: info.name_rus || info.nickname_rus,
  }

  const countryOrTeamParams = () => {
    switch (type) {
      case ProfileTypes.TOURNAMENTS:
      case ProfileTypes.TEAMS:
        return {
          id: info.country?.id,
          name_eng: info.country?.name_eng,
          name_rus: info.country?.name_rus,
        }
      case ProfileTypes.PLAYERS:
        return {
          id: info.country?.id,
          name_eng: info.team?.name_eng,
          name_rus: info.team?.name_rus,
        }
      default:
        return {}
    }
  }

  const name = getName({ nameObj: currentName, suffix })
  const countryOrTeam = getName({ nameObj: countryOrTeamParams(), suffix })

  return {
    countryOrTeam,
    name,
  }
}
