All files / web/src/components/practice StartPracticeModal.tsx

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

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 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
'use client'

import * as Dialog from '@radix-ui/react-dialog'
import { useQueryClient } from '@tanstack/react-query'
import { useCallback, useEffect, useRef, useState } from 'react'
import {
  useSkillTutorialBroadcast,
  type SkillTutorialBroadcastState,
} from '@/hooks/useSkillTutorialBroadcast'
import type { PlayerSessionPreferencesConfig } from '@/db/schema/player-session-preferences'
import {
  usePlayerSessionPreferences,
  useSavePlayerSessionPreferences,
} from '@/hooks/usePlayerSessionPreferences'
import type { SkillTutorialControlAction } from '@/lib/classroom/socket-events'
import { useTheme } from '@/contexts/ThemeContext'
import type { SessionPlan } from '@/db/schema/session-plans'
import type { SessionMode } from '@/lib/curriculum/session-mode'
import { sessionModeKeys } from '@/hooks/useSessionMode'
import type { ProblemResultWithContext } from '@/lib/curriculum/session-planner'
import { css } from '../../../styled-system/css'
import { SkillTutorialLauncher } from '../tutorial/SkillTutorialLauncher'
import { ManualSkillSelector } from './ManualSkillSelector'
import {
  StartPracticeModalProvider,
  useStartPracticeModal,
  type GameInfo,
} from './StartPracticeModalContext'
import {
  SessionConfigSummary,
  DurationSelector,
  PracticeModesSelector,
  PurposeDistributionBar,
  ProblemLengthSelector,
  GameBreakSettings,
  SessionFocusInfo,
  PlanIndicator,
  ErrorDisplay,
  StartButton,
} from './start-practice-modal'

interface StartPracticeModalProps {
  studentId: string
  studentName: string
  focusDescription: string
  sessionMode: SessionMode
  /** Comfort level from the session mode API (0-1) */
  comfortLevel?: number
  /** Per-mode comfort levels from the session mode API */
  comfortByMode?: Record<string, number>
  secondsPerTerm?: number
  /** @deprecated Use secondsPerTerm instead */
  avgSecondsPerProblem?: number
  existingPlan?: SessionPlan | null
  /** When true, abandon the existing session and generate a new one */
  startFresh?: boolean
  problemHistory?: ProblemResultWithContext[]
  onClose: () => void
  onStarted?: () => void
  open?: boolean
  /** Initial expanded state for settings panel (for Storybook) */
  initialExpanded?: boolean
  /** Override practice-approved games list (for Storybook/testing) */
  practiceApprovedGamesOverride?: GameInfo[]
}

export function StartPracticeModal({
  studentId,
  studentName,
  focusDescription,
  sessionMode,
  comfortLevel,
  comfortByMode,
  secondsPerTerm,
  avgSecondsPerProblem,
  existingPlan,
  startFresh,
  onClose,
  onStarted,
  open = true,
  initialExpanded,
  practiceApprovedGamesOverride,
}: StartPracticeModalProps) {
  // Load persisted preferences for this student.
  // We must wait for the query to settle before rendering the provider,
  // because useState initializers only run on first mount — if the provider
  // mounts before the query resolves, saved values are ignored.
  const { data: savedPreferences, isLoading: prefsLoading } = usePlayerSessionPreferences(studentId)
  const saveMutation = useSavePlayerSessionPreferences(studentId)
  // Ref so the callback never changes identity when mutation state changes
  const saveMutationRef = useRef(saveMutation)
  saveMutationRef.current = saveMutation

  // Debounced save: 1000ms after last change
  const debounceTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
  const pendingPrefsRef = useRef<PlayerSessionPreferencesConfig | null>(null)
  const [saveStatus, setSaveStatus] = useState<'idle' | 'saving' | 'saved' | 'error'>('idle')
  const fadeTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
  const mountedRef = useRef(true)

  const savePreferencesNow = useCallback((prefs: PlayerSessionPreferencesConfig) => {
    saveMutationRef.current.mutate(prefs, {
      onSuccess: () => {
        if (!mountedRef.current) return
        setSaveStatus('saved')
        // Fade the "Saved" indicator after 3 seconds
        fadeTimer.current = setTimeout(() => setSaveStatus('idle'), 3000)
      },
      onError: () => {
        if (!mountedRef.current) return
        setSaveStatus('error')
      },
    })
  }, [])

  const handleSavePreferences = useCallback(
    (prefs: PlayerSessionPreferencesConfig) => {
      pendingPrefsRef.current = prefs
      // Clear any existing debounce timer
      if (debounceTimer.current) clearTimeout(debounceTimer.current)
      // Clear any "saved" fade timer
      if (fadeTimer.current) clearTimeout(fadeTimer.current)

      setSaveStatus('saving')

      debounceTimer.current = setTimeout(() => {
        const pendingPrefs = pendingPrefsRef.current
        pendingPrefsRef.current = null
        debounceTimer.current = null
        if (pendingPrefs) savePreferencesNow(pendingPrefs)
      }, 1000)
    },
    [savePreferencesNow]
  )

  const flushPendingPreferences = useCallback(() => {
    const pendingPrefs = pendingPrefsRef.current
    if (!pendingPrefs) return

    if (debounceTimer.current) {
      clearTimeout(debounceTimer.current)
      debounceTimer.current = null
    }
    if (fadeTimer.current) clearTimeout(fadeTimer.current)

    pendingPrefsRef.current = null
    savePreferencesNow(pendingPrefs)
  }, [savePreferencesNow])

  const handleClose = useCallback(() => {
    flushPendingPreferences()
    onClose()
  }, [flushPendingPreferences, onClose])

  // Cleanup timers on unmount
  useEffect(() => {
    return () => {
      mountedRef.current = false
      if (debounceTimer.current) clearTimeout(debounceTimer.current)
      if (fadeTimer.current) clearTimeout(fadeTimer.current)
      pendingPrefsRef.current = null
    }
  }, [])

  // Don't render until preferences have loaded so useState initializers see the saved values
  if (prefsLoading) return null

  return (
    <StartPracticeModalProvider
      studentId={studentId}
      studentName={studentName}
      focusDescription={focusDescription}
      sessionMode={sessionMode}
      comfortLevel={comfortLevel}
      comfortByMode={comfortByMode}
      secondsPerTerm={secondsPerTerm}
      avgSecondsPerProblem={avgSecondsPerProblem}
      existingPlan={startFresh ? null : existingPlan}
      startFresh={startFresh}
      onStarted={onStarted}
      initialExpanded={initialExpanded}
      practiceApprovedGamesOverride={practiceApprovedGamesOverride}
      savedPreferences={savedPreferences}
      onSavePreferences={handleSavePreferences}
    >
      <StartPracticeModalContent
        studentId={studentId}
        studentName={studentName}
        focusDescription={focusDescription}
        onClose={handleClose}
        open={open}
        saveStatus={saveStatus}
        flushPendingPreferences={flushPendingPreferences}
      />
    </StartPracticeModalProvider>
  )
}

interface StartPracticeModalContentProps {
  studentId: string
  studentName: string
  focusDescription: string
  onClose: () => void
  open: boolean
  saveStatus: 'idle' | 'saving' | 'saved' | 'error'
  flushPendingPreferences: () => void
}

function StartPracticeModalContent({
  studentId,
  studentName,
  focusDescription,
  onClose,
  open,
  saveStatus,
  flushPendingPreferences,
}: StartPracticeModalContentProps) {
  const { resolvedTheme } = useTheme()
  const isDark = resolvedTheme === 'dark'
  const queryClient = useQueryClient()

  const {
    nextSkill,
    isExpanded,
    setIsExpanded,
    handleStart,
    showSkillSelector,
    setShowSkillSelector,
    canSkipTutorial,
    includeTutorial,
    setIncludeTutorial,
  } = useStartPracticeModal()

  // Tutorial state (stays in this component for WebSocket broadcast coordination)
  const [showTutorial, setShowTutorial] = useState(false)
  const [tutorialBroadcastState, setTutorialBroadcastState] =
    useState<SkillTutorialBroadcastState | null>(null)
  const [pendingControlAction, setPendingControlAction] =
    useState<SkillTutorialControlAction | null>(null)

  const handleControlActionProcessed = useCallback(() => {
    setPendingControlAction(null)
  }, [])

  const handleControlReceived = useCallback((action: SkillTutorialControlAction) => {
    console.log('[StartPracticeModal] Received control action from teacher:', action)
    setPendingControlAction(action)
  }, [])

  useSkillTutorialBroadcast(
    studentId,
    studentName,
    showTutorial ? tutorialBroadcastState : null,
    handleControlReceived
  )

  // After tutorial completes, invalidate session mode (skill now enabled) and start practice
  const handleTutorialComplete = useCallback(() => {
    setShowTutorial(false)
    queryClient.invalidateQueries({
      queryKey: sessionModeKeys.forPlayer(studentId),
    })
    // Start practice - session plan will be generated with newly-enabled skill
    flushPendingPreferences()
    handleStart()
  }, [queryClient, studentId, handleStart, flushPendingPreferences])

  // Skip tutorial and start practice with existing skills
  const handleTutorialSkip = useCallback(() => {
    setShowTutorial(false)
    setIncludeTutorial(false)
    flushPendingPreferences()
    handleStart()
  }, [handleStart, setIncludeTutorial, flushPendingPreferences])

  const handleTutorialCancel = useCallback(() => {
    setShowTutorial(false)
    onClose()
  }, [onClose])

  // "Let's Go!" button handler - show tutorial first if needed, otherwise start practice
  const handleStartOrTutorial = useCallback(() => {
    flushPendingPreferences()
    if (includeTutorial && nextSkill) {
      setShowTutorial(true)
      return
    }
    handleStart()
  }, [includeTutorial, nextSkill, handleStart, flushPendingPreferences])

  // Render tutorial modal if tutorial is active
  if (showTutorial && nextSkill) {
    return (
      <Dialog.Root open={open} onOpenChange={(o) => !o && handleTutorialCancel()}>
        <Dialog.Portal>
          <Dialog.Overlay
            className={css({
              position: 'fixed',
              inset: 0,
              backgroundColor: 'rgba(0, 0, 0, 0.5)',
              backdropFilter: 'blur(8px)',
              zIndex: 1000,
            })}
          />
          <Dialog.Content
            data-component="skill-tutorial-modal"
            className={css({
              position: 'fixed',
              top: '50%',
              left: '50%',
              transform: 'translate(-50%, -50%)',
              width: 'calc(100% - 2rem)',
              maxWidth: '800px',
              maxHeight: 'calc(100vh - 2rem)',
              overflowY: 'auto',
              borderRadius: '20px',
              boxShadow: '0 20px 50px -12px rgba(0, 0, 0, 0.4)',
              zIndex: 1001,
              outline: 'none',
            })}
            style={{
              background: isDark
                ? 'linear-gradient(150deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%)'
                : 'linear-gradient(150deg, #ffffff 0%, #f8fafc 60%, #f0f9ff 100%)',
            }}
          >
            <SkillTutorialLauncher
              skillId={nextSkill.skillId}
              playerId={studentId}
              theme={isDark ? 'dark' : 'light'}
              onComplete={handleTutorialComplete}
              // Only allow skip if user has other skills to practice
              onSkip={canSkipTutorial ? handleTutorialSkip : undefined}
              onCancel={handleTutorialCancel}
              onBroadcastStateChange={setTutorialBroadcastState}
              controlAction={pendingControlAction}
              onControlActionProcessed={handleControlActionProcessed}
            />
          </Dialog.Content>
        </Dialog.Portal>
      </Dialog.Root>
    )
  }

  // Config view - always shown (unified for all session modes)
  return (
    <>
      <Dialog.Root open={open} onOpenChange={(o) => !o && onClose()}>
        <Dialog.Portal>
          <Dialog.Overlay
            className={css({
              position: 'fixed',
              inset: 0,
              backgroundColor: 'rgba(0, 0, 0, 0.5)',
              backdropFilter: 'blur(8px)',
              zIndex: 1000,
            })}
          />
          <Dialog.Content
            data-component="start-practice-modal"
            className={css({
              position: 'fixed',
              top: '50%',
              left: '50%',
              transform: 'translate(-50%, -50%)',
              width: 'calc(100% - 2rem)',
              maxWidth: '360px',
              borderRadius: '20px',
              boxShadow: '0 20px 50px -12px rgba(0, 0, 0, 0.4)',
              zIndex: 1001,
              outline: 'none',
              '@media (min-width: 480px)': {
                width: 'auto',
                minWidth: '360px',
              },
              '@media (max-width: 480px), (max-height: 700px)': {
                top: 0,
                left: 0,
                transform: 'none',
                width: '100%',
                maxWidth: 'none',
                height: '100%',
                borderRadius: 0,
                boxShadow: 'none',
                display: 'flex',
                flexDirection: 'column',
              },
            })}
            style={{
              background: isDark
                ? 'linear-gradient(150deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%)'
                : 'linear-gradient(150deg, #ffffff 0%, #f8fafc 60%, #f0f9ff 100%)',
            }}
          >
            {/* Close button */}
            <Dialog.Close asChild>
              <button
                type="button"
                data-action="close-modal"
                className={css({
                  position: 'absolute',
                  top: '0.75rem',
                  right: '0.75rem',
                  width: '32px',
                  height: '32px',
                  display: 'flex',
                  alignItems: 'center',
                  justifyContent: 'center',
                  fontSize: '1rem',
                  color: isDark ? 'gray.500' : 'gray.400',
                  backgroundColor: isDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.04)',
                  border: 'none',
                  borderRadius: '50%',
                  cursor: 'pointer',
                  transition: 'all 0.15s ease',
                  _hover: {
                    backgroundColor: isDark ? 'rgba(255,255,255,0.12)' : 'rgba(0,0,0,0.08)',
                    color: isDark ? 'gray.300' : 'gray.600',
                  },
                  '@media (max-width: 480px), (max-height: 700px)': {
                    top: '0.375rem',
                    right: '0.375rem',
                    width: '24px',
                    height: '24px',
                    fontSize: '0.75rem',
                  },
                })}
                aria-label="Close"
              >

              </button>
            </Dialog.Close>

            <div
              data-section="modal-content"
              data-expanded={isExpanded}
              className={css({
                padding: '1.5rem',
                display: 'flex',
                flexDirection: 'column',
                justifyContent: 'center',
                flex: 1,
                overflow: 'hidden',
                '@media (max-height: 500px) and (orientation: landscape)': {
                  padding: '0.75rem 1.5rem',
                  paddingTop: '2rem',
                  justifyContent: 'flex-start',
                },
              })}
            >
              {/* Screen reader only title/description */}
              <Dialog.Title className={css({ srOnly: true })}>Start Practice Session</Dialog.Title>
              <Dialog.Description className={css({ srOnly: true })}>
                {focusDescription}
              </Dialog.Description>

              {/* Config and action wrapper */}
              <div
                data-section="config-and-action"
                className={css({
                  display: 'flex',
                  flexDirection: 'column',
                  gap: '1rem',
                  '@media (max-height: 500px) and (orientation: landscape)': {
                    flex: 1,
                    minHeight: 0,
                    overflow: 'hidden',
                    gap: '0.5rem',
                  },
                })}
              >
                {/* Session focus info (replaces TutorialCTA and RemediationCTA) */}
                <SessionFocusInfo />

                {/* Plan indicator — shows tier and inherited plan info */}
                <PlanIndicator />

                {/* Session config card */}
                <div
                  data-section="session-config"
                  className={css({
                    borderRadius: '12px',
                    overflow: 'hidden',
                    transition: 'all 0.3s ease',
                  })}
                  style={{
                    background: isDark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.03)',
                    border: `1px solid ${isDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)'}`,
                  }}
                >
                  {/* Summary view (collapsed) */}
                  <SessionConfigSummary />

                  {/* Expanded config panel */}
                  <div
                    data-section="config-expanded"
                    className={css({
                      overflow: 'auto',
                      transition: 'all 0.3s ease',
                      '@media (max-height: 500px) and (min-width: 500px)': {
                        overflow: 'auto',
                        maxHeight: '100%',
                      },
                    })}
                    style={{
                      maxHeight: isExpanded ? '620px' : '0px',
                      opacity: isExpanded ? 1 : 0,
                    }}
                  >
                    <div
                      className={css({
                        padding: '1rem',
                        display: 'flex',
                        flexDirection: 'column',
                        gap: '0.875rem',
                      })}
                    >
                      {/* Expanded header with collapse button */}
                      <div
                        className={css({
                          display: 'flex',
                          alignItems: 'center',
                          justifyContent: 'space-between',
                          marginBottom: '-0.25rem',
                          '@media (max-width: 480px), (max-height: 700px)': {
                            marginBottom: '-0.125rem',
                          },
                        })}
                      >
                        <div
                          data-element="settings-header-left"
                          className={css({
                            display: 'flex',
                            alignItems: 'center',
                            gap: '0.5rem',
                          })}
                        >
                          <span
                            className={css({
                              fontSize: '0.75rem',
                              fontWeight: '600',
                              color: isDark ? 'gray.400' : 'gray.500',
                              textTransform: 'uppercase',
                              letterSpacing: '0.05em',
                              '@media (max-width: 480px), (max-height: 700px)': {
                                fontSize: '0.625rem',
                              },
                            })}
                          >
                            Session Settings
                          </span>
                          {saveStatus !== 'idle' && (
                            <span
                              data-element="save-status"
                              className={css({
                                fontSize: '0.625rem',
                                fontWeight: '500',
                                transition: 'opacity 0.3s ease',
                              })}
                              style={{
                                color:
                                  saveStatus === 'error'
                                    ? '#ef4444'
                                    : saveStatus === 'saving'
                                      ? isDark
                                        ? '#94a3b8'
                                        : '#64748b'
                                      : isDark
                                        ? '#4ade80'
                                        : '#16a34a',
                              }}
                            >
                              {saveStatus === 'saving'
                                ? 'Saving...'
                                : saveStatus === 'saved'
                                  ? 'Saved'
                                  : 'Save failed'}
                            </span>
                          )}
                        </div>
                        <button
                          type="button"
                          data-action="collapse-settings"
                          onClick={() => setIsExpanded(false)}
                          className={css({
                            display: 'flex',
                            alignItems: 'center',
                            gap: '0.25rem',
                            padding: '0.25rem 0.5rem',
                            fontSize: '0.6875rem',
                            fontWeight: '500',
                            color: isDark ? 'gray.400' : 'gray.500',
                            backgroundColor: isDark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.03)',
                            border: 'none',
                            borderRadius: '4px',
                            cursor: 'pointer',
                            transition: 'all 0.15s ease',
                            _hover: {
                              backgroundColor: isDark
                                ? 'rgba(255,255,255,0.1)'
                                : 'rgba(0,0,0,0.06)',
                              color: isDark ? 'gray.300' : 'gray.600',
                            },
                            '@media (max-width: 480px), (max-height: 700px)': {
                              padding: '0.125rem 0.375rem',
                              fontSize: '0.5625rem',
                            },
                          })}
                        >
                          <span>▲</span>
                          <span>Collapse</span>
                        </button>
                      </div>

                      {/* Settings grid */}
                      <div
                        data-element="settings-grid"
                        className={css({
                          display: 'flex',
                          flexDirection: 'column',
                          gap: '0.875rem',
                          '@media (max-width: 480px), (max-height: 700px)': {
                            gap: '0.375rem',
                          },
                          '@media (max-height: 500px) and (min-width: 500px)': {
                            display: 'grid',
                            gridTemplateColumns: '1fr 1fr',
                            gap: '0.5rem',
                          },
                        })}
                      >
                        <DurationSelector />
                        <PracticeModesSelector />
                        <PurposeDistributionBar />
                        <ProblemLengthSelector />
                        <GameBreakSettings />
                      </div>
                    </div>
                  </div>
                </div>

                {/* Error display */}
                <ErrorDisplay />

                {/* Primary action button - always visible */}
                <StartButton onStart={handleStartOrTutorial} />

                {/* Manual skill selector link (for users who want to skip tutorial) */}
                {!canSkipTutorial && (
                  <button
                    type="button"
                    data-action="open-manual-skill-selector"
                    onClick={() => setShowSkillSelector(true)}
                    className={css({
                      padding: '0.5rem 1rem',
                      fontSize: '0.75rem',
                      fontWeight: '500',
                      background: 'transparent',
                      border: 'none',
                      borderRadius: '8px',
                      cursor: 'pointer',
                      textDecoration: 'underline',
                      textUnderlineOffset: '2px',
                      transition: 'all 0.15s ease',
                      alignSelf: 'center',
                      _hover: {
                        textDecoration: 'none',
                      },
                    })}
                    style={{ color: isDark ? '#71717a' : '#9ca3af' }}
                  >
                    Skip tutorial — choose skills manually
                  </button>
                )}
              </div>
            </div>
          </Dialog.Content>
        </Dialog.Portal>
      </Dialog.Root>

      {/* Skill Selector Modal (for manual skill selection) */}
      <ManualSkillSelector
        open={showSkillSelector}
        onClose={() => setShowSkillSelector(false)}
        studentName={studentName}
        playerId={studentId}
        onSave={async () => {
          setShowSkillSelector(false)
          queryClient.invalidateQueries({
            queryKey: sessionModeKeys.forPlayer(studentId),
          })
        }}
      />
    </>
  )
}

export default StartPracticeModal