import { useEffect } from 'react'

import find from 'lodash/find'

import { useMatchPageStore } from 'features/MatchPage/store'

export const useTeamsStatsTable = () => {
  const {
    plaingOrder,
    profile,
    setCircleAnimation,
    teamsStats,
  } = useMatchPageStore()

  const getStatItemById = (paramId: number) => {
    if (!profile) return null

    return find(teamsStats[profile?.team2.id], ({ param1 }) => param1.id === paramId) || null
  }

  useEffect(() => {
    setCircleAnimation((state) => ({
      ...state,
      plaingOrder,
    }))
  }, [setCircleAnimation, plaingOrder])

  return {
    getStatItemById,
  }
}
