import { usePageLogger } from 'hooks/usePageLogger'

import { ProfileHeader } from 'features/ProfileHeader'
import { ProfileCard } from 'features/ProfileCard'
import { Matches } from 'features/Matches'
import { UserFavorites } from 'features/UserFavorites'
import {
  PageWrapper,
  Main,
  Content,
} from 'features/PageLayout'

import { useTournamentPage } from './hooks'

import { FavouriteTeamPopup } from '../MatchPage/components/FavouriteTeam'

const TournamentPage = () => {
  usePageLogger()
  const {
    fetchMatches,
    headerImage,
    profile,
    tournamentId,
    user,
  } = useTournamentPage()

  return (
    <PageWrapper>
      <ProfileHeader
        headerImage={headerImage}
        profileId={tournamentId}
      >
        {profile && <ProfileCard profile={profile} />}
      </ProfileHeader>
      <Main>
        <UserFavorites />
        <Content>
          <Matches fetch={fetchMatches} />
        </Content>
      </Main>
      {user && (tournamentId === 131 || tournamentId === 2032) && <FavouriteTeamPopup />}
    </PageWrapper>
  )
}

export default TournamentPage
