All files / web/src/arcade-games/know-your-world/components ResultsPhase.tsx

0% Statements 0/257
0% Branches 0/1
0% Functions 0/1
0% Lines 0/257

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
'use client'

import { css } from '@styled/css'
import { useTheme } from '@/contexts/ThemeContext'
import { useKnowYourWorld } from '../Provider'
import { WORLD_MAP, USA_MAP } from '../maps'

export function ResultsPhase() {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  const { state, nextRound } = useKnowYourWorld()

  const mapData = state.selectedMap === 'world' ? WORLD_MAP : USA_MAP
  const totalRegions = mapData.regions.length
  const elapsedTime = state.endTime ? state.endTime - state.startTime : 0
  const minutes = Math.floor(elapsedTime / 60000)
  const seconds = Math.floor((elapsedTime % 60000) / 1000)

  // Sort players by score
  const sortedPlayers = state.activePlayers
    .map((playerId) => ({
      playerId,
      name: state.playerMetadata[playerId]?.name || playerId,
      emoji: state.playerMetadata[playerId]?.emoji || '👤',
      score: state.scores[playerId] || 0,
      attempts: state.attempts[playerId] || 0,
    }))
    .sort((a, b) => b.score - a.score)

  const winner = sortedPlayers[0]

  return (
    <div
      data-component="results-phase"
      className={css({
        display: 'flex',
        flexDirection: 'column',
        gap: '6',
        maxWidth: '800px',
        margin: '0 auto',
        paddingTop: '20',
        paddingX: '6',
        paddingBottom: '6',
      })}
    >
      {/* Victory Banner */}
      <div
        data-section="victory-banner"
        className={css({
          textAlign: 'center',
          padding: '8',
          bg: 'linear-gradient(135deg, #fbbf24, #f59e0b)',
          rounded: 'xl',
          shadow: 'xl',
        })}
      >
        <div className={css({ fontSize: '6xl', marginBottom: '4' })}>🎉</div>
        <div
          className={css({
            fontSize: '3xl',
            fontWeight: 'bold',
            color: 'white',
          })}
        >
          {state.gameMode === 'cooperative' ? 'Great Teamwork!' : 'Winner!'}
        </div>
        {state.gameMode !== 'cooperative' && winner && (
          <div className={css({ fontSize: '2xl', color: 'white', marginTop: '2' })}>
            {winner.emoji} {winner.name}
          </div>
        )}
      </div>

      {/* Stats */}
      <div
        data-section="game-stats"
        className={css({
          bg: isDark ? 'gray.800' : 'white',
          rounded: 'xl',
          padding: '6',
          shadow: 'lg',
        })}
      >
        <h2
          className={css({
            fontSize: '2xl',
            fontWeight: 'bold',
            marginBottom: '4',
            color: isDark ? 'gray.100' : 'gray.900',
          })}
        >
          Game Statistics
        </h2>
        <div
          className={css({
            display: 'grid',
            gridTemplateColumns: 'repeat(2, 1fr)',
            gap: '4',
          })}
        >
          <div>
            <div
              className={css({
                fontSize: 'sm',
                color: isDark ? 'gray.400' : 'gray.600',
              })}
            >
              Regions Found
            </div>
            <div
              className={css({
                fontSize: '2xl',
                fontWeight: 'bold',
                color: 'green.500',
              })}
            >
              {totalRegions} / {totalRegions}
            </div>
          </div>
          <div>
            <div
              className={css({
                fontSize: 'sm',
                color: isDark ? 'gray.400' : 'gray.600',
              })}
            >
              Time
            </div>
            <div
              className={css({
                fontSize: '2xl',
                fontWeight: 'bold',
                color: 'blue.500',
              })}
            >
              {minutes}:{seconds.toString().padStart(2, '0')}
            </div>
          </div>
        </div>
      </div>

      {/* Player Scores */}
      <div
        data-section="player-scores"
        className={css({
          bg: isDark ? 'gray.800' : 'white',
          rounded: 'xl',
          padding: '6',
          shadow: 'lg',
        })}
      >
        <h2
          className={css({
            fontSize: '2xl',
            fontWeight: 'bold',
            marginBottom: '4',
            color: isDark ? 'gray.100' : 'gray.900',
          })}
        >
          {state.gameMode === 'cooperative' ? 'Team Score' : 'Leaderboard'}
        </h2>
        <div
          className={css({
            display: 'flex',
            flexDirection: 'column',
            gap: '3',
          })}
        >
          {sortedPlayers.map((player, index) => (
            <div
              key={player.playerId}
              data-element="player-score"
              className={css({
                display: 'flex',
                alignItems: 'center',
                gap: '4',
                padding: '4',
                bg:
                  index === 0
                    ? isDark
                      ? 'yellow.900'
                      : 'yellow.50'
                    : isDark
                      ? 'gray.700'
                      : 'gray.100',
                rounded: 'lg',
                border: '2px solid',
                borderColor: index === 0 ? 'yellow.500' : 'transparent',
              })}
            >
              <div className={css({ fontSize: '3xl' })}>{player.emoji}</div>
              <div className={css({ flex: '1' })}>
                <div
                  className={css({
                    fontWeight: 'bold',
                    fontSize: 'lg',
                    color: isDark ? 'gray.100' : 'gray.900',
                  })}
                >
                  {player.name}
                </div>
                <div
                  className={css({
                    fontSize: 'sm',
                    color: isDark ? 'gray.400' : 'gray.600',
                  })}
                >
                  {player.attempts} wrong clicks
                </div>
              </div>
              <div
                className={css({
                  fontSize: '2xl',
                  fontWeight: 'bold',
                  color: 'green.500',
                })}
              >
                {player.score} pts
              </div>
            </div>
          ))}
        </div>
      </div>

      {/* Action Buttons */}
      <div
        className={css({
          display: 'grid',
          gridTemplateColumns: 'repeat(1, 1fr)',
          gap: '4',
        })}
      >
        <button
          data-action="play-again"
          onClick={nextRound}
          className={css({
            padding: '4',
            rounded: 'xl',
            bg: 'blue.600',
            color: 'white',
            fontSize: 'xl',
            fontWeight: 'bold',
            cursor: 'pointer',
            transition: 'all 0.2s',
            _hover: {
              bg: 'blue.700',
              transform: 'translateY(-2px)',
              shadow: 'lg',
            },
          })}
        >
          🔄 Play Again
        </button>
      </div>
    </div>
  )
}