All files / web/src/components InteractiveNotFound.tsx

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

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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
'use client'

import { useState, useEffect, useRef } from 'react'
import { AbacusReact, useAbacusDisplay } from '@soroban/abacus-react'
import { PageWithNav } from '@/components/PageWithNav'
import { css } from '../../styled-system/css'
import { stack } from '../../styled-system/patterns'

// Local type definitions to avoid TypeScript module resolution issues
// These match the types from @soroban/abacus-react
interface CustomBeadContext {
  type: 'heaven' | 'earth'
  value: number
  active: boolean
  position: number
  placeValue: number
  color: string
  size: number
}

type CustomBeadContent =
  | { type: 'emoji'; value: string }
  | { type: 'emoji-function'; value: (bead: CustomBeadContext) => string }

// HTTP Status Code Easter Eggs with dynamic bead rendering and themed backgrounds
const STATUS_CODE_EASTER_EGGS: Record<
  number,
  {
    customBeadContent: CustomBeadContent
    message: string
    bgGradient?: string
    textColor?: string
    glowColor?: string
  }
> = {
  200: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.active ? '✅' : '⭕'),
    },
    message: "Everything's counting perfectly!",
    bgGradient: 'linear-gradient(135deg, #059669 0%, #10b981 100%)',
    textColor: '#d1fae5',
    glowColor: 'rgba(16, 185, 129, 0.3)',
  },
  201: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.type === 'heaven' ? 'ðŸĨš' : 'ðŸĢ'),
    },
    message: 'Something new has been counted into existence!',
    bgGradient: 'linear-gradient(135deg, #fef3c7 0%, #fde68a 100%)',
    textColor: '#78350f',
    glowColor: 'rgba(253, 230, 138, 0.4)',
  },
  301: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.active ? '🚚' : 'ðŸ“Ķ'),
    },
    message: 'These numbers have permanently relocated!',
    bgGradient: 'linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%)',
    textColor: '#3730a3',
    glowColor: 'rgba(199, 210, 254, 0.4)',
  },
  400: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.active ? '❌' : '❓'),
    },
    message: "Those numbers don't make sense!",
    bgGradient: 'linear-gradient(135deg, #fee2e2 0%, #fecaca 100%)',
    textColor: '#991b1b',
    glowColor: 'rgba(254, 202, 202, 0.4)',
  },
  401: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.active ? '🔒' : '🔑'),
    },
    message: 'These numbers are classified!',
    bgGradient: 'linear-gradient(135deg, #1f2937 0%, #374151 100%)',
    textColor: '#fbbf24',
    glowColor: 'rgba(251, 191, 36, 0.3)',
  },
  403: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.type === 'heaven' ? 'ðŸšŦ' : '⛔'),
    },
    message: "You're not allowed to count these numbers!",
    bgGradient: 'linear-gradient(135deg, #450a0a 0%, #7f1d1d 100%)',
    textColor: '#fef2f2',
    glowColor: 'rgba(127, 29, 29, 0.5)',
  },
  418: {
    customBeadContent: { type: 'emoji', value: 'ðŸŦ–' },
    message: "Perhaps you're pouring in the wrong direction?",
    bgGradient: 'linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%)',
    textColor: '#064e3b',
    glowColor: 'rgba(167, 243, 208, 0.4)',
  },
  420: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const emojis = ['ðŸŒŋ', '🍃', 'ðŸŒą', 'ðŸŠī']
        return emojis[bead.position % emojis.length] || 'ðŸŒŋ'
      },
    },
    message: 'Whoa dude, these numbers are like... relative, man',
    bgGradient: 'linear-gradient(135deg, #6ee7b7 20%, #34d399 50%, #10b981 80%)',
    textColor: '#022c22',
    glowColor: 'rgba(52, 211, 153, 0.6)',
  },
  451: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => (bead.active ? 'ðŸĪ' : '▓'),
    },
    message: '[REDACTED] - This number has been removed by the Ministry of Mathematics',
    bgGradient: 'linear-gradient(135deg, #111827 0%, #1f2937 100%)',
    textColor: '#9ca3af',
    glowColor: 'rgba(156, 163, 175, 0.2)',
  },
  500: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const fireEmojis = ['ðŸ”Ĩ', 'ðŸ’Ĩ', '⚠ïļ']
        return bead.active ? fireEmojis[bead.position % fireEmojis.length] || 'ðŸ”Ĩ' : 'ðŸ’Ļ'
      },
    },
    message: 'The abacus has caught fire!',
    bgGradient: 'linear-gradient(135deg, #dc2626 0%, #ef4444 50%, #f97316 100%)',
    textColor: '#fff7ed',
    glowColor: 'rgba(239, 68, 68, 0.6)',
  },
  503: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const tools = ['🔧', 'ðŸ”Ļ', '🊛', '⚙ïļ']
        return bead.active ? tools[bead.placeValue % tools.length] || '🔧' : '⚩'
      },
    },
    message: "Pardon our dust, we're upgrading the beads!",
    bgGradient: 'linear-gradient(135deg, #fef3c7 0%, #fde047 100%)',
    textColor: '#713f12',
    glowColor: 'rgba(253, 224, 71, 0.4)',
  },
  666: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const demons = ['😈', 'ðŸ‘đ', '👚', '💀']
        return bead.active ? demons[bead.position % demons.length] || '😈' : 'ðŸ”Ĩ'
      },
    },
    message: 'Your soul now belongs to arithmetic!',
    bgGradient: 'linear-gradient(135deg, #7c2d12 0%, #991b1b 50%, #450a0a 100%)',
    textColor: '#fef2f2',
    glowColor: 'rgba(153, 27, 27, 0.7)',
  },
  777: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const lucky = ['🎰', '🍀', '💰', 'ðŸŽē', '⭐']
        return bead.active ? lucky[bead.placeValue % lucky.length] || '🎰' : '⚩'
      },
    },
    message: "Jackpot! You've mastered the soroban!",
    bgGradient: 'linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%)',
    textColor: '#422006',
    glowColor: 'rgba(251, 191, 36, 0.6)',
  },
  911: {
    customBeadContent: {
      type: 'emoji-function',
      value: (bead) => {
        const emergency = ['ðŸšĻ', '🚑', '🚒', 'ðŸ‘Ū']
        return bead.active ? emergency[bead.position % emergency.length] || 'ðŸšĻ' : 'âšŦ'
      },
    },
    message: 'EMERGENCY: Someone needs help with their math homework!',
    bgGradient: 'linear-gradient(135deg, #dc2626 0%, #b91c1c 100%)',
    textColor: '#fef2f2',
    glowColor: 'rgba(220, 38, 38, 0.5)',
  },
}

export function InteractiveNotFound() {
  const [abacusValue, setAbacusValue] = useState(404)
  const [activeEasterEgg, setActiveEasterEgg] = useState<number | null>(null)
  const [fadeKey, setFadeKey] = useState(0)
  const { config, updateConfig, resetToDefaults } = useAbacusDisplay()
  const originalConfigRef = useRef<typeof config | null>(null)

  // Save original config and restore on page unload
  useEffect(() => {
    // Save the config state before any easter eggs are activated
    // Only save once on mount
    if (originalConfigRef.current === null) {
      originalConfigRef.current = { ...config }
    }

    // Restore original config when user reloads page or closes tab
    const handleBeforeUnload = () => {
      if (originalConfigRef.current) {
        updateConfig(originalConfigRef.current)
      }
    }

    window.addEventListener('beforeunload', handleBeforeUnload)
    return () => window.removeEventListener('beforeunload', handleBeforeUnload)
  }, [config, updateConfig])

  // Easter egg activation - update global abacus config when special codes are entered
  useEffect(() => {
    const easterEgg = STATUS_CODE_EASTER_EGGS[abacusValue]

    if (easterEgg && activeEasterEgg !== abacusValue) {
      setActiveEasterEgg(abacusValue)
      setFadeKey((prev) => prev + 1) // Trigger fade animation

      // Update global abacus display config to use custom beads
      // This affects ALL abaci rendered in the app until page reload!
      updateConfig({
        beadShape: 'custom',
        customBeadContent: easterEgg.customBeadContent,
      })

      // Store active easter egg in window so it persists across navigation
      ;(window as unknown as { __easterEggMode: number | null }).__easterEggMode = abacusValue
    } else if (!easterEgg && activeEasterEgg !== null) {
      // User changed away from an easter egg code - reset to defaults
      setActiveEasterEgg(null)
      setFadeKey((prev) => prev + 1) // Trigger fade animation
      resetToDefaults()
      ;(window as unknown as { __easterEggMode: number | null }).__easterEggMode = null
    }
  }, [abacusValue, activeEasterEgg, updateConfig, resetToDefaults])

  // Get current theme
  const currentTheme = activeEasterEgg ? STATUS_CODE_EASTER_EGGS[activeEasterEgg] : null

  return (
    <PageWithNav>
      <style>
        {`
          @keyframes fadeInText {
            from {
              opacity: 0;
              transform: translateY(-10px);
            }
            to {
              opacity: 1;
              transform: translateY(0);
            }
          }
        `}
      </style>
      <div
        className={css({
          minHeight: '100vh',
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          background: currentTheme?.bgGradient || 'bg.canvas',
          padding: { base: '1rem', sm: '2rem' },
          paddingTop: { base: '10rem', sm: '12rem', md: '14rem', lg: '16rem' },
          transition: 'background 0.6s ease-in-out',
          position: 'relative',
          overflow: 'hidden',
        })}
      >
        {/* Animated glow effect */}
        {currentTheme?.glowColor && (
          <div
            className={css({
              position: 'absolute',
              inset: 0,
              background: `radial-gradient(circle at 50% 40%, ${currentTheme.glowColor} 0%, transparent 70%)`,
              animation: 'pulse 3s ease-in-out infinite',
              pointerEvents: 'none',
            })}
          />
        )}

        <div
          className={stack({
            gap: { base: '1.5rem', sm: '2rem', md: '3rem' },
            alignItems: 'center',
            textAlign: 'center',
            maxWidth: '900px',
            width: '100%',
            position: 'relative',
            zIndex: 1,
          })}
        >
          {/* Interactive Abacus */}
          <div
            className={css({
              position: 'relative',
              width: '100%',
              maxWidth: { base: '90vw', sm: '500px', md: '600px', lg: '700px' },
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'center',
            })}
          >
            <div
              className={css({
                transform: {
                  base: 'scale(1.5)',
                  sm: 'scale(2)',
                  md: 'scale(2.5)',
                  lg: 'scale(3)',
                },
                transformOrigin: 'center',
              })}
            >
              <AbacusReact
                value={abacusValue}
                columns={3}
                showNumbers={false}
                onValueChange={(v) => setAbacusValue(Number(v))}
              />
            </div>
          </div>

          {/* Main message */}
          <div
            className={stack({
              gap: '1rem',
              marginTop: { base: '2rem', sm: '3rem', md: '4rem' },
            })}
          >
            <h1
              key={fadeKey}
              className={css({
                fontSize: {
                  base: '1.75rem',
                  sm: '2.5rem',
                  md: '3.5rem',
                  lg: '4rem',
                },
                fontWeight: 'black',
                color: currentTheme?.textColor || 'text.primary',
                lineHeight: '1.1',
                textShadow: currentTheme?.glowColor
                  ? `0 0 20px ${currentTheme.glowColor}, 0 0 40px ${currentTheme.glowColor}`
                  : 'none',
                transition: 'color 0.6s ease-in-out, text-shadow 0.6s ease-in-out',
                letterSpacing: '-0.02em',
                px: { base: '1rem', sm: '2rem' },
                minHeight: {
                  base: 'calc(1.75rem * 1.1 * 2)',
                  sm: 'calc(2.5rem * 1.1 * 2)',
                  md: 'calc(3.5rem * 1.1 * 2)',
                  lg: 'calc(4rem * 1.1 * 2)',
                },
                display: 'flex',
                alignItems: 'center',
                justifyContent: 'center',
              })}
              style={{
                animation: 'fadeInText 0.5s ease-out',
              }}
            >
              {activeEasterEgg
                ? STATUS_CODE_EASTER_EGGS[activeEasterEgg].message
                : "Oops! We've lost count."}
            </h1>
          </div>
        </div>
      </div>
    </PageWithNav>
  )
}