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

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

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

import type { SlotResult } from '@/db/schema/session-plans'
import type { SkillBktResult } from '@/lib/curriculum/bkt'
import { css } from '../../../styled-system/css'
import { calculateAutoPauseInfo, formatMs, getAutoPauseExplanation } from './autoPauseCalculator'
import { ProblemToReview } from './ProblemToReview'
import type { ProblemNeedingAttention } from './sessionSummaryUtils'

export interface ProblemsToReviewPanelProps {
  /** Problems that need attention */
  problems: ProblemNeedingAttention[]
  /** All session results (for auto-pause calculation) */
  results: SlotResult[]
  /** BKT skill mastery data for annotation */
  skillMasteries: Record<string, SkillBktResult>
  /** Total problems in the session */
  totalProblems: number
  /** Dark mode */
  isDark: boolean
}

/**
 * ProblemsToReviewPanel - Shows problems that need attention with timing info
 *
 * Features:
 * - Auto-pause timing summary section
 * - All problems needing attention (no limit)
 * - ProblemToReview cards with annotations
 * - "All correct" celebration when no problems need attention
 */
export function ProblemsToReviewPanel({
  problems,
  results,
  skillMasteries,
  totalProblems,
  isDark,
}: ProblemsToReviewPanelProps) {
  // Calculate auto-pause info for timing summary
  const autoPauseInfo = calculateAutoPauseInfo(results)

  return (
    <div
      data-component="problems-to-review-panel"
      className={css({
        display: 'flex',
        flexDirection: 'column',
        gap: '1rem',
      })}
    >
      {/* Auto-Pause Timing Summary */}
      <section
        data-section="auto-pause-summary"
        className={css({
          padding: '1rem',
          borderRadius: '8px',
          backgroundColor: isDark ? 'gray.800' : 'gray.50',
          border: '1px solid',
          borderColor: isDark ? 'gray.700' : 'gray.200',
        })}
      >
        <h3
          className={css({
            fontSize: '1rem',
            fontWeight: 'bold',
            color: isDark ? 'gray.200' : 'gray.700',
            marginBottom: '0.5rem',
          })}
        >
          Response Timing
        </h3>
        <div
          className={css({
            display: 'grid',
            gap: '0.5rem',
            fontSize: '0.875rem',
          })}
        >
          <div
            className={css({
              display: 'flex',
              justifyContent: 'space-between',
            })}
          >
            <span className={css({ color: isDark ? 'gray.400' : 'gray.600' })}>
              Auto-pause threshold:
            </span>
            <span
              className={css({
                fontWeight: 'bold',
                color: isDark ? 'gray.200' : 'gray.800',
              })}
            >
              {formatMs(autoPauseInfo.threshold)}
            </span>
          </div>
          <div
            className={css({
              fontSize: '0.75rem',
              color: isDark ? 'gray.500' : 'gray.500',
              fontStyle: 'italic',
            })}
          >
            {getAutoPauseExplanation(autoPauseInfo.stats)}
          </div>
          {autoPauseInfo.stats.sampleCount > 0 && (
            <div
              className={css({
                display: 'flex',
                gap: '1rem',
                marginTop: '0.25rem',
                fontSize: '0.75rem',
                color: isDark ? 'gray.400' : 'gray.500',
              })}
            >
              <span>Mean: {formatMs(autoPauseInfo.stats.meanMs)}</span>
              <span>Std Dev: {formatMs(autoPauseInfo.stats.stdDevMs)}</span>
              <span>Samples: {autoPauseInfo.stats.sampleCount}</span>
            </div>
          )}
        </div>
      </section>

      {/* Problems Worth Attention */}
      {problems.length > 0 ? (
        <section
          data-section="problems-to-review"
          className={css({
            padding: '1rem',
            borderRadius: '12px',
            backgroundColor: isDark ? 'gray.800' : 'white',
            border: '1px solid',
            borderColor: isDark ? 'gray.700' : 'gray.200',
          })}
        >
          <h3
            className={css({
              fontSize: '1rem',
              fontWeight: 'bold',
              color: isDark ? 'gray.200' : 'gray.700',
              marginBottom: '0.5rem',
            })}
          >
            Problems to Review
          </h3>
          <p
            className={css({
              fontSize: '0.75rem',
              color: isDark ? 'gray.400' : 'gray.500',
              marginBottom: '1rem',
            })}
          >
            {problems.length} of {totalProblems} problems need attention
          </p>
          <div
            className={css({
              display: 'flex',
              flexDirection: 'column',
              gap: '0.75rem',
            })}
          >
            {problems.map((problem) => {
              // Get all results before this problem for auto-pause calculation
              const resultsBeforeThis = results.slice(
                0,
                results.findIndex(
                  (r) =>
                    r.partNumber === problem.result.partNumber &&
                    r.slotIndex === problem.result.slotIndex
                )
              )

              return (
                <ProblemToReview
                  key={`${problem.part.partNumber}-${problem.slot.index}`}
                  problem={problem}
                  allResultsBeforeThis={resultsBeforeThis}
                  skillMasteries={skillMasteries}
                  isDark={isDark}
                />
              )
            })}
          </div>
        </section>
      ) : (
        <div
          data-section="all-correct"
          className={css({
            padding: '1.5rem',
            borderRadius: '12px',
            backgroundColor: isDark ? 'green.900/30' : 'green.50',
            border: '1px solid',
            borderColor: isDark ? 'green.700' : 'green.200',
            textAlign: 'center',
          })}
        >
          <span
            className={css({
              fontSize: '2rem',
              display: 'block',
              marginBottom: '0.5rem',
            })}
          >
            🎉
          </span>
          <h3
            className={css({
              fontSize: '1rem',
              fontWeight: 'bold',
              color: isDark ? 'green.300' : 'green.700',
            })}
          >
            Perfect! All problems answered correctly.
          </h3>
        </div>
      )}
    </div>
  )
}

export default ProblemsToReviewPanel