import type { KeyboardEvent } from 'react' import { useLocation, useRouteMatch } from 'react-router' import getUnixTime from 'date-fns/getUnixTime' import { ProfileTypes, PAGES } from 'config' import { client, isLffClient } from 'config/clients' import type { LiveScore } from 'requests' import { getCardColor } from 'helpers/getCardColor' import type { Match } from 'features/Matches' import { useMatchSwitchesStore } from 'features/MatchSwitches' import { useName } from 'features/Name' import { T9n } from 'features/T9n' import { MatchAccess } from 'features/Matches/helpers/getMatchClickAction' import { useUserFavoritesStore } from 'features/UserFavorites/store' import { TournamentSubtitle } from 'features/TournamentSubtitle' import { NoAccessMessage } from '../NoAccessMessage' import { Score } from '../Score' import { CardWrapperOuter, CardWrapper, Info, LiveSign, MatchDate, MatchTimeInfo, Preview, PreviewWrapper, Team, TeamName, Teams, Time, TeamLogos, TeamLogo, BuyMatchBadge, BuyMatchBadgeCustom, FavoriteSign, NameSignWrapper, HoverFrame, } from '../styled' import { useCardPreview } from './hooks' import { getPrepareTimeFormat } from '../helpers' import { getPrepareDateFormat } from '../helpers/getPrepareDateFormat' import { Icon } from '../../Icon' type Props = { isNeedFormatTimeChanged: boolean, match: Match, onClick: () => void, onKeyPress: (e: KeyboardEvent) => void, score?: LiveScore, } export const CardFrontside = ({ isNeedFormatTimeChanged, match, onClick, onKeyPress, score, }: Props) => { const location = useLocation() const { access, countryId, countryInfo, date, group, live, preview, previewURL, sportInfo, sportType, team1, team2, time, tournament, } = match const isHomePage = useRouteMatch(PAGES.home)?.isExact const isMatchPage = location.pathname.includes(PAGES.match) const tournamentName = useName(tournament) const { isInFavorites } = useUserFavoritesStore() const { isScoreHidden } = useMatchSwitchesStore() const isInFuture = getUnixTime(date) > getUnixTime(new Date()) const showScore = !( isInFuture || isScoreHidden ) || (live && !isScoreHidden) const team1InFavorites = isInFavorites(ProfileTypes.TEAMS, team1.id) const team2InFavorites = isInFavorites(ProfileTypes.TEAMS, team2.id) const { previewImage } = useCardPreview({ preview, previewURL, }) const prepareTime = getPrepareTimeFormat({ date, isNeedFormatTimeChanged, time, }) const prepareDate = getPrepareDateFormat({ date, isNeedFormatTimeChanged, }) return ( {!isLffClient && previewImage && ( )} {access === MatchAccess.NoCountryAccess ? : ( )} {access === MatchAccess.CanBuyMatch && !isMatchPage && ( )} {access === MatchAccess.CanBuyMatch && isMatchPage && ( )} {isHomePage || isMatchPage ? null : prepareDate} {live && ( )} {isMatchPage && ( )} {team1InFavorites && } {isMatchPage && ( )} {team2InFavorites && } {!isMatchPage && ( )} ) }