'use client'
import * as Select from '@radix-ui/react-select'
import { useTheme } from '@/contexts/ThemeContext'
import { css } from '../../../../styled-system/css'
import { useStartPracticeModal } from '../StartPracticeModalContext'
export function GameBreakSettings() {
const { resolvedTheme } = useTheme()
const isDark = resolvedTheme === 'dark'
const {
showGameBreakSettings,
gameBreakEnabled,
setGameBreakEnabled,
gameBreakMinutes,
setGameBreakMinutes,
gameBreakSelectionMode,
setGameBreakSelectionMode,
gameBreakSelectedGame,
setGameBreakSelectedGame,
practiceApprovedGames,
hasSingleGame,
singleGame,
} = useStartPracticeModal()
if (!showGameBreakSettings) {
return null
}
// Simplified UI for single-game scenario
if (hasSingleGame && singleGame) {
return (
{/* Header with toggle */}
Game Breaks
setGameBreakEnabled(!gameBreakEnabled)}
className={css({
display: 'flex',
alignItems: 'center',
gap: '0.375rem',
padding: '0.25rem 0.5rem',
fontSize: '0.6875rem',
fontWeight: '500',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
transition: 'all 0.15s ease',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0.125rem 0.375rem',
fontSize: '0.5625rem',
},
})}
style={{
backgroundColor: gameBreakEnabled
? isDark
? 'rgba(34, 197, 94, 0.2)'
: 'rgba(34, 197, 94, 0.15)'
: isDark
? 'rgba(255,255,255,0.05)'
: 'rgba(0,0,0,0.03)',
color: gameBreakEnabled
? isDark
? '#86efac'
: '#16a34a'
: isDark
? '#9ca3af'
: '#6b7280',
}}
>
{gameBreakEnabled ? '🎮' : '⏸️'}
{gameBreakEnabled ? 'On' : 'Off'}
{gameBreakEnabled && (
<>
{/* Game info + duration in one row */}
{/* Game icon and name */}
{singleGame.manifest.icon}
{singleGame.manifest.shortName || singleGame.manifest.displayName}
{/* Duration selector - compact */}
{[2, 3, 5].map((mins) => {
const isSelected = gameBreakMinutes === mins
return (
setGameBreakMinutes(mins)}
className={css({
padding: '0.25rem 0.5rem',
fontSize: '0.75rem',
fontWeight: '600',
borderRadius: '4px',
border: 'none',
cursor: 'pointer',
transition: 'all 0.15s ease',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0.1875rem 0.375rem',
fontSize: '0.6875rem',
},
})}
style={{
backgroundColor: isSelected
? isDark
? '#22c55e'
: '#16a34a'
: isDark
? 'rgba(255,255,255,0.08)'
: 'rgba(0,0,0,0.06)',
color: isSelected ? 'white' : isDark ? '#9ca3af' : '#6b7280',
}}
>
{mins}m
)
})}
{/* Helper text + coming soon */}
Starts automatically between parts
More games coming soon!
>
)}
)
}
// Full UI for multiple games
return (
{/* Header with toggle */}
Game Breaks
setGameBreakEnabled(!gameBreakEnabled)}
className={css({
display: 'flex',
alignItems: 'center',
gap: '0.375rem',
padding: '0.25rem 0.5rem',
fontSize: '0.6875rem',
fontWeight: '500',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
transition: 'all 0.15s ease',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0.125rem 0.375rem',
fontSize: '0.5625rem',
},
})}
style={{
backgroundColor: gameBreakEnabled
? isDark
? 'rgba(34, 197, 94, 0.2)'
: 'rgba(34, 197, 94, 0.15)'
: isDark
? 'rgba(255,255,255,0.05)'
: 'rgba(0,0,0,0.03)',
color: gameBreakEnabled
? isDark
? '#86efac'
: '#16a34a'
: isDark
? '#9ca3af'
: '#6b7280',
}}
>
{gameBreakEnabled ? '🎮' : '⏸️'}
{gameBreakEnabled ? 'On' : 'Off'}
{/* Duration options */}
{gameBreakEnabled && (
{[2, 3, 5, 10].map((mins) => {
const isSelected = gameBreakMinutes === mins
return (
setGameBreakMinutes(mins)}
className={css({
flex: 1,
padding: '0.5rem 0.25rem',
fontSize: '0.875rem',
fontWeight: '600',
borderRadius: '6px',
border: 'none',
cursor: 'pointer',
transition: 'all 0.15s ease',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0.3125rem 0.125rem',
fontSize: '0.75rem',
borderRadius: '4px',
},
})}
style={{
backgroundColor: isSelected
? isDark
? '#22c55e'
: '#16a34a'
: isDark
? 'rgba(255,255,255,0.06)'
: 'rgba(0,0,0,0.04)',
color: isSelected ? 'white' : isDark ? '#9ca3af' : '#6b7280',
}}
>
{mins}m
)
})}
)}
{/* Selection Mode Toggle */}
{gameBreakEnabled && (
How to start
{[
{ mode: 'auto-start' as const, emoji: '🚀', label: 'Auto-start' },
{ mode: 'kid-chooses' as const, emoji: '🎯', label: 'Kid picks' },
].map(({ mode, emoji, label }) => {
const isSelected = gameBreakSelectionMode === mode
return (
setGameBreakSelectionMode(mode)}
className={css({
flex: 1,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: '0.25rem',
padding: '0.375rem 0.5rem',
fontSize: '0.6875rem',
fontWeight: '500',
borderRadius: '6px',
border: 'none',
cursor: 'pointer',
transition: 'all 0.15s ease',
'@media (max-width: 480px), (max-height: 700px)': {
padding: '0.25rem 0.375rem',
fontSize: '0.5625rem',
gap: '0.125rem',
},
})}
style={{
backgroundColor: isSelected
? isDark
? 'rgba(59, 130, 246, 0.25)'
: 'rgba(59, 130, 246, 0.15)'
: isDark
? 'rgba(255,255,255,0.06)'
: 'rgba(0,0,0,0.04)',
color: isSelected
? isDark
? '#93c5fd'
: '#2563eb'
: isDark
? '#9ca3af'
: '#6b7280',
}}
>
{emoji}
{label}
)
})}
)}
{/* Game Selection Dropdown */}
{gameBreakEnabled && (
{gameBreakSelectionMode === 'auto-start' ? 'Game' : 'Default'}
setGameBreakSelectedGame(value === '__none__' ? null : (value as string | 'random'))
}
>
{(() => {
if (gameBreakSelectedGame === 'random') return '🎲 Random'
if (gameBreakSelectedGame === null) return '✨ No default'
const game = practiceApprovedGames.find(
(g) => g.manifest.name === gameBreakSelectedGame
)
return game
? `${game.manifest.icon} ${game.manifest.shortName || game.manifest.displayName}`
: 'Select game'
})()}
▼
{/* Random option */}
🎲 Random
{/* Practice-approved games */}
{practiceApprovedGames.map((game) => (
{game.manifest.icon} {game.manifest.shortName || game.manifest.displayName}
))}
{/* "No default" option for kid-chooses mode only */}
{gameBreakSelectionMode === 'kid-chooses' && (
✨ No default
)}
)}
{/* Helper text */}
{gameBreakEnabled && (
{gameBreakSelectionMode === 'auto-start'
? gameBreakSelectedGame === 'random'
? 'A random game will start automatically'
: 'This game will start automatically (kid can skip)'
: gameBreakSelectedGame === null
? 'Kid chooses from full list'
: 'This game will be highlighted as suggested'}
)}
)
}