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

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

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

/**
 * ProgressiveHighlightOverlay - SVG overlay showing completed problem boxes
 *
 * As the LLM streams parsing results, this component renders boxes
 * around each completed problem. New boxes appear with a pop-in animation.
 *
 * Uses normalized coordinates (0-1) and positions them relative to the
 * parent container.
 */

import { css } from '../../../styled-system/css'
import type { CompletedProblem } from '@/hooks/useWorksheetParsing'

export interface ProgressiveHighlightOverlayProps {
  /** Problems that have been completed (with bounding boxes) */
  completedProblems: CompletedProblem[]
  /** Animation delay per problem (staggered appearance) */
  staggerDelay?: number
}

export function ProgressiveHighlightOverlay({
  completedProblems,
  staggerDelay = 50,
}: ProgressiveHighlightOverlayProps) {
  if (completedProblems.length === 0) {
    return null
  }

  return (
    <svg
      data-component="progressive-highlight-overlay"
      className={css({
        position: 'absolute',
        inset: 0,
        width: '100%',
        height: '100%',
        pointerEvents: 'none',
        zIndex: 5,
      })}
      viewBox="0 0 100 100"
      preserveAspectRatio="none"
    >
      {completedProblems.map((problem, index) => {
        const { x, y, width, height } = problem.problemBoundingBox

        // Convert normalized (0-1) to viewBox (0-100)
        const boxX = x * 100
        const boxY = y * 100
        const boxWidth = width * 100
        const boxHeight = height * 100

        return (
          <g
            key={`problem-${problem.problemNumber}`}
            style={{
              animation: 'problemAppear 0.3s ease-out forwards',
              animationDelay: `${index * staggerDelay}ms`,
              opacity: 0,
            }}
          >
            {/* Background fill */}
            <rect
              x={boxX}
              y={boxY}
              width={boxWidth}
              height={boxHeight}
              fill="rgba(34, 197, 94, 0.2)"
              stroke="rgba(34, 197, 94, 0.8)"
              strokeWidth={0.5}
              rx={0.5}
              ry={0.5}
            />
            {/* Checkmark in corner */}
            <circle cx={boxX + boxWidth - 2} cy={boxY + 2} r={2} fill="rgba(34, 197, 94, 1)" />
            <path
              d={`M ${boxX + boxWidth - 3} ${boxY + 2} l 0.7 0.7 l 1.3 -1.5`}
              stroke="white"
              strokeWidth={0.4}
              fill="none"
              strokeLinecap="round"
              strokeLinejoin="round"
            />
          </g>
        )
      })}
    </svg>
  )
}

/**
 * Compact version for smaller tiles (just shows green border, no checkmark)
 */
export function ProgressiveHighlightOverlayCompact({
  completedProblems,
  staggerDelay = 50,
}: ProgressiveHighlightOverlayProps) {
  if (completedProblems.length === 0) {
    return null
  }

  return (
    <svg
      data-component="progressive-highlight-overlay-compact"
      className={css({
        position: 'absolute',
        inset: 0,
        width: '100%',
        height: '100%',
        pointerEvents: 'none',
        zIndex: 5,
      })}
      viewBox="0 0 100 100"
      preserveAspectRatio="none"
    >
      {completedProblems.map((problem, index) => {
        const { x, y, width, height } = problem.problemBoundingBox

        // Convert normalized (0-1) to viewBox (0-100)
        const boxX = x * 100
        const boxY = y * 100
        const boxWidth = width * 100
        const boxHeight = height * 100

        return (
          <rect
            key={`problem-${problem.problemNumber}`}
            x={boxX}
            y={boxY}
            width={boxWidth}
            height={boxHeight}
            fill="rgba(34, 197, 94, 0.15)"
            stroke="rgba(34, 197, 94, 0.7)"
            strokeWidth={0.3}
            rx={0.3}
            ry={0.3}
            style={{
              animation: 'problemAppear 0.3s ease-out forwards',
              animationDelay: `${index * staggerDelay}ms`,
              opacity: 0,
            }}
          />
        )
      })}
    </svg>
  )
}