import groupBy from 'lodash/groupBy'
import map from 'lodash/map'

import { ProfileTypes } from 'config'
import { useUserFavoritesStore } from 'features/UserFavorites/store'

export const useFavoritesMobilePopup = () => {
  const { userFavorites } = useUserFavoritesStore()

  const getTypeLexic = (typeLexic: number) => {
    switch (typeLexic) {
      case ProfileTypes.TOURNAMENTS:
        return 'tournament'
      case ProfileTypes.TEAMS:
        return 'team'
      case ProfileTypes.PLAYERS:
        return 'player'
      default:
        return ''
    }
  }

  const groupedFavorites = map(
    groupBy(userFavorites, 'type'),
    (item) => ({ items: item, typeLexic: getTypeLexic(item[0].type) }),
  )

  return { groupedFavorites }
}
