All files / web/src/arcade-games/memory-quiz/components MemoryQuizGame.tsx

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

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                                                                                                                                                                                                                                                                                                                                                                                                                               
'use client'

import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { PageWithNav } from '@/components/PageWithNav'
import { useGameLayoutMode } from '@/contexts/GameLayoutContext'
import { css } from '../../../../styled-system/css'
import { useMemoryQuiz } from '../Provider'
import { DisplayPhase } from './DisplayPhase'
import { InputPhase } from './InputPhase'
import { ResultsPhase } from './ResultsPhase'
import { SetupPhase } from './SetupPhase'

// CSS animations that need to be global
const globalAnimations = `
@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
  50% { transform: scale(1.05); box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5); }
  100% { transform: scale(1); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
}

@keyframes subtlePageFlash {
  0% { background: linear-gradient(to bottom right, #f0fdf4, #ecfdf5); }
  50% { background: linear-gradient(to bottom right, #dcfce7, #d1fae5); }
  100% { background: linear-gradient(to bottom right, #f0fdf4, #ecfdf5); }
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes explode {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.5);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2) rotate(180deg);
  }
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}
`

export function MemoryQuizGame() {
  const router = useRouter()
  const { state, exitSession, resetGame } = useMemoryQuiz()
  const layoutMode = useGameLayoutMode()

  const phaseContent = (
    <>
      {state.gamePhase === 'setup' && <SetupPhase />}
      {state.gamePhase === 'display' && <DisplayPhase />}
      {state.gamePhase === 'input' && <InputPhase key="input-phase" />}
      {state.gamePhase === 'results' && <ResultsPhase />}
    </>
  )

  // Container mode (practice game break): render without PageWithNav or arcade chrome
  if (layoutMode === 'container') {
    return (
      <div
        style={{
          flex: 1,
          display: 'flex',
          flexDirection: 'column',
          overflow: 'auto',
          background: 'linear-gradient(135deg, #f8fafc, #e2e8f0)',
        }}
      >
        <style dangerouslySetInnerHTML={{ __html: globalAnimations }} />
        <div
          className={css({
            bg: 'white',
            rounded: 'xl',
            shadow: 'xl',
            overflow: 'hidden',
            border: '1px solid',
            borderColor: 'gray.200',
            flex: 1,
            display: 'flex',
            flexDirection: 'column',
            m: '2',
          })}
        >
          <div
            className={css({
              flex: 1,
              display: 'flex',
              flexDirection: 'column',
              overflow: 'auto',
            })}
          >
            {phaseContent}
          </div>
        </div>
      </div>
    )
  }

  return (
    <PageWithNav
      navTitle="Memory Lightning"
      navEmoji="🧠"
      emphasizePlayerSelection={state.gamePhase === 'setup'}
      onExitSession={() => {
        exitSession?.()
        router.push('/arcade')
      }}
      onNewGame={() => {
        resetGame?.()
      }}
    >
      <style dangerouslySetInnerHTML={{ __html: globalAnimations }} />

      <div
        style={{
          flex: 1,
          display: 'flex',
          flexDirection: 'column',
          overflow: 'auto',
          padding: '20px 8px',
          minHeight: '100vh',
          background: 'linear-gradient(135deg, #f8fafc, #e2e8f0)',
        }}
      >
        <div
          style={{
            maxWidth: '100%',
            margin: '0 auto',
            flex: 1,
            display: 'flex',
            flexDirection: 'column',
          }}
        >
          <div
            className={css({
              textAlign: 'center',
              mb: '4',
              flexShrink: 0,
            })}
          >
            <Link
              href="/arcade"
              className={css({
                display: 'inline-flex',
                alignItems: 'center',
                color: 'gray.600',
                textDecoration: 'none',
                mb: '4',
                _hover: { color: 'gray.800' },
              })}
            >
              ← Back to Champion Arena
            </Link>
          </div>

          <div
            className={css({
              bg: 'white',
              rounded: 'xl',
              shadow: 'xl',
              overflow: 'hidden',
              border: '1px solid',
              borderColor: 'gray.200',
              flex: 1,
              display: 'flex',
              flexDirection: 'column',
              maxHeight: '100%',
            })}
          >
            <div
              className={css({
                flex: 1,
                display: 'flex',
                flexDirection: 'column',
                overflow: 'auto',
              })}
            >
              {phaseContent}
            </div>
          </div>
        </div>
      </div>
    </PageWithNav>
  )
}