|
1 | 1 | import { css } from '@emotion/react'; |
2 | | -import { from } from '@guardian/source/foundations'; |
3 | | -import { type FootballMatchStats } from '../footballMatchStats'; |
| 2 | +import type { |
| 3 | + FootballMatchStats, |
| 4 | + FootballMatchTeamWithStats, |
| 5 | +} from '../footballMatchStats'; |
| 6 | +import type { FootballTable as FootballTableData } from '../footballTables'; |
4 | 7 | import { grid } from '../grid'; |
5 | | -import { palette } from '../palette'; |
| 8 | +import { FootballMatchStat } from './FootballMatchStat'; |
| 9 | +import { LeagueTable } from './LeagueTable'; |
6 | 10 | import { Lineups } from './Lineups'; |
7 | 11 |
|
8 | | -const gridStyles = css` |
9 | | - ${grid.paddedContainer} |
10 | | - position: relative; |
11 | | - ${from.tablet} { |
12 | | - &::before, |
13 | | - &::after { |
14 | | - content: ''; |
15 | | - position: absolute; |
16 | | - border-left: 1px solid ${palette('--article-border')}; |
17 | | - z-index: 1; |
18 | | - top: 0; |
19 | | - bottom: 0; |
20 | | - } |
21 | | -
|
22 | | - &::after { |
23 | | - right: 0; |
24 | | - } |
25 | | - } |
26 | | -`; |
27 | | - |
28 | 12 | type Props = { |
29 | 13 | match: FootballMatchStats; |
| 14 | + table?: FootballTableData; |
30 | 15 | }; |
31 | 16 |
|
32 | | -export const FootballMatchInfo = ({ match }: Props) => ( |
33 | | - <main id="maincontent" css={gridStyles}> |
34 | | - <div |
35 | | - css={css` |
36 | | - ${grid.column.centre} |
37 | | - `} |
38 | | - > |
39 | | - <Lineups matchStats={match} /> |
40 | | - </div> |
41 | | - </main> |
| 17 | +function teamHasStats({ |
| 18 | + shotsOffTarget, |
| 19 | + shotsOnTarget, |
| 20 | + fouls, |
| 21 | + corners, |
| 22 | +}: FootballMatchTeamWithStats) { |
| 23 | + return !( |
| 24 | + shotsOffTarget === 0 && |
| 25 | + shotsOnTarget === 0 && |
| 26 | + fouls === 0 && |
| 27 | + corners === 0 |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +export const FootballMatchInfo = ({ match, table }: Props) => { |
| 32 | + const showStats = |
| 33 | + teamHasStats(match.homeTeam) && teamHasStats(match.awayTeam); |
| 34 | + const showLineups = |
| 35 | + match.homeTeam.players.length > 0 && match.awayTeam.players.length > 0; |
| 36 | + return ( |
| 37 | + <section aria-label={'match-info'}> |
| 38 | + {showStats && ( |
| 39 | + <> |
| 40 | + <StatsContainer |
| 41 | + label="Possession" |
| 42 | + match={match} |
| 43 | + homeValue={match.homeTeam.possession} |
| 44 | + awayValue={match.awayTeam.possession} |
| 45 | + /> |
| 46 | + {/* Add Goal Attempts here */} |
| 47 | + <StatsContainer |
| 48 | + label="Corrners" |
| 49 | + match={match} |
| 50 | + homeValue={match.homeTeam.corners} |
| 51 | + awayValue={match.awayTeam.corners} |
| 52 | + /> |
| 53 | + <StatsContainer |
| 54 | + label="Fouls" |
| 55 | + match={match} |
| 56 | + homeValue={match.homeTeam.fouls} |
| 57 | + awayValue={match.awayTeam.fouls} |
| 58 | + /> |
| 59 | + </> |
| 60 | + )} |
| 61 | + |
| 62 | + {showLineups && ( |
| 63 | + <div |
| 64 | + css={css` |
| 65 | + padding-bottom: 10px; |
| 66 | + `} |
| 67 | + > |
| 68 | + <Lineups matchStats={match} /> |
| 69 | + </div> |
| 70 | + )} |
| 71 | + {table && ( |
| 72 | + <div |
| 73 | + css={css` |
| 74 | + padding-bottom: 10px; |
| 75 | + `} |
| 76 | + > |
| 77 | + <LeagueTable table={table} /> |
| 78 | + </div> |
| 79 | + )} |
| 80 | + </section> |
| 81 | + ); |
| 82 | +}; |
| 83 | + |
| 84 | +const StatsContainer = ({ |
| 85 | + label, |
| 86 | + match, |
| 87 | + homeValue, |
| 88 | + awayValue, |
| 89 | +}: { |
| 90 | + label: string; |
| 91 | + match: FootballMatchStats; |
| 92 | + homeValue: number; |
| 93 | + awayValue: number; |
| 94 | +}) => ( |
| 95 | + <div |
| 96 | + css={css` |
| 97 | + ${grid.column.centre} |
| 98 | + padding-bottom: 10px; |
| 99 | + `} |
| 100 | + > |
| 101 | + <FootballMatchStat |
| 102 | + label={label} |
| 103 | + home={{ |
| 104 | + teamName: match.homeTeam.name, |
| 105 | + teamColour: match.homeTeam.statsColour, |
| 106 | + value: homeValue, |
| 107 | + }} |
| 108 | + away={{ |
| 109 | + teamName: match.awayTeam.name, |
| 110 | + teamColour: match.awayTeam.statsColour, |
| 111 | + value: awayValue, |
| 112 | + }} |
| 113 | + /> |
| 114 | + </div> |
42 | 115 | ); |
0 commit comments