All files / web/src/components/worksheet-parsing ProblemReviewCard.tsx

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

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 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
'use client'

/**
 * ProblemReviewCard - Mobile-first card UI for reviewing one problem at a time
 *
 * Features:
 * - Large cropped view of the problem region from the worksheet
 * - Clear display of terms, student answer, and correct answer
 * - Inline editing for corrections
 * - Quick action buttons: Approve, Correct, Flag
 * - Navigation controls
 */

import { type ReactNode, useState, useCallback, useRef, useEffect, useMemo } from 'react'
import { css } from '../../../styled-system/css'
import type { ParsedProblem, BoundingBox } from '@/lib/worksheet-parsing'
import type { ProblemCorrection } from './EditableProblemRow'

export interface ProblemReviewCardProps {
  /** The problem being reviewed */
  problem: ParsedProblem
  /** Index in the problems array (0-based) */
  index: number
  /** Total number of problems */
  totalProblems: number
  /** Full worksheet image URL */
  worksheetImageUrl: string
  /** Callback when correction is submitted */
  onSubmitCorrection: (correction: ProblemCorrection) => void
  /** Callback when approved without changes */
  onApprove: () => void
  /** Callback when flagged for re-scan */
  onFlag: () => void
  /** Callback to navigate to next problem */
  onNext: () => void
  /** Callback to navigate to previous problem */
  onPrev: () => void
  /** Whether currently saving */
  isSaving?: boolean
  /** Dark mode */
  isDark?: boolean
}

/**
 * Parse terms string into array of numbers
 */
function parseTermsString(input: string): number[] | null {
  const cleaned = input.trim()
  if (!cleaned) return null

  const parts = cleaned.split(/([+-])/).filter((p) => p.trim())
  const terms: number[] = []
  let sign = 1

  for (const part of parts) {
    const trimmed = part.trim()
    if (trimmed === '+') {
      sign = 1
    } else if (trimmed === '-') {
      sign = -1
    } else {
      const num = parseInt(trimmed, 10)
      if (Number.isNaN(num)) return null
      terms.push(sign * num)
      sign = 1
    }
  }

  return terms.length > 0 ? terms : null
}

/**
 * Format terms array into readable string
 */
function formatTerms(terms: number[]): string {
  if (terms.length === 0) return ''
  if (terms.length === 1) return terms[0].toString()

  return terms
    .map((term, i) => {
      if (i === 0) return term.toString()
      if (term >= 0) return `+ ${term}`
      return `- ${Math.abs(term)}`
    })
    .join(' ')
}

/**
 * Get confidence level info
 */
function getConfidenceInfo(confidence: number): {
  label: string
  color: string
  bgColor: string
} {
  if (confidence >= 0.85) {
    return { label: 'High', color: 'green.400', bgColor: 'green.900/30' }
  }
  if (confidence >= 0.7) {
    return { label: 'Medium', color: 'yellow.400', bgColor: 'yellow.900/30' }
  }
  return { label: 'Low', color: 'red.400', bgColor: 'red.900/30' }
}

/**
 * Cropped image component that displays a specific region of the worksheet
 */
function CroppedProblemImage({
  imageUrl,
  boundingBox,
  isDark,
}: {
  imageUrl: string
  boundingBox: BoundingBox
  isDark?: boolean
}): ReactNode {
  const containerRef = useRef<HTMLDivElement>(null)
  const [imageSize, setImageSize] = useState({ width: 0, height: 0 })
  const [containerSize, setContainerSize] = useState({ width: 0, height: 0 })

  // Load image to get natural dimensions
  useEffect(() => {
    const img = new Image()
    img.onload = () => {
      setImageSize({ width: img.naturalWidth, height: img.naturalHeight })
    }
    img.src = imageUrl
  }, [imageUrl])

  // Measure container
  useEffect(() => {
    if (!containerRef.current) return
    const observer = new ResizeObserver((entries) => {
      const entry = entries[0]
      if (entry) {
        setContainerSize({
          width: entry.contentRect.width,
          height: entry.contentRect.height,
        })
      }
    })
    observer.observe(containerRef.current)
    return () => observer.disconnect()
  }, [])

  // Calculate CSS to crop and display the region, plus bounding box overlay position
  const { cropStyle, boxStyle } = useMemo(() => {
    if (!imageSize.width || !containerSize.width) {
      return { cropStyle: {}, boxStyle: {} }
    }

    // Add padding around the bounding box (20% on each side)
    const padding = 0.2
    const x = Math.max(0, boundingBox.x - boundingBox.width * padding)
    const y = Math.max(0, boundingBox.y - boundingBox.height * padding)
    const width = Math.min(1 - x, boundingBox.width * (1 + padding * 2))
    const height = Math.min(1 - y, boundingBox.height * (1 + padding * 2))

    // Calculate scale to fit the region in the container
    const regionAspect = width / height
    const containerAspect = containerSize.width / containerSize.height

    let scale: number
    if (regionAspect > containerAspect) {
      // Region is wider - fit to width
      scale = containerSize.width / (width * imageSize.width)
    } else {
      // Region is taller - fit to height
      scale = containerSize.height / (height * imageSize.height)
    }

    const scaledImageWidth = imageSize.width * scale
    const scaledImageHeight = imageSize.height * scale

    // Center the cropped region
    const offsetX = -x * scaledImageWidth + (containerSize.width - width * scaledImageWidth) / 2
    const offsetY = -y * scaledImageHeight + (containerSize.height - height * scaledImageHeight) / 2

    // Calculate bounding box overlay position (in container coordinates)
    const boxLeft = boundingBox.x * scaledImageWidth + offsetX
    const boxTop = boundingBox.y * scaledImageHeight + offsetY
    const boxWidth = boundingBox.width * scaledImageWidth
    const boxHeight = boundingBox.height * scaledImageHeight

    return {
      cropStyle: {
        width: `${scaledImageWidth}px`,
        height: `${scaledImageHeight}px`,
        transform: `translate(${offsetX}px, ${offsetY}px)`,
      },
      boxStyle: {
        left: `${boxLeft}px`,
        top: `${boxTop}px`,
        width: `${boxWidth}px`,
        height: `${boxHeight}px`,
      },
    }
  }, [imageSize, containerSize, boundingBox])

  return (
    <div
      ref={containerRef}
      data-element="cropped-problem-image"
      style={{ overflow: 'hidden' }}
      className={css({
        width: '100%',
        height: '200px',
        borderRadius: 'lg',
        backgroundColor: isDark ? 'gray.900' : 'gray.100',
        position: 'relative',
      })}
    >
      {imageSize.width > 0 && (
        <>
          {/* biome-ignore lint/performance/noImgElement: Using CSS transforms for cropping that next/image doesn't support */}
          <img
            src={imageUrl}
            alt="Problem region"
            style={cropStyle}
            className={css({
              position: 'absolute',
              top: 0,
              left: 0,
              objectFit: 'none',
            })}
          />
          {/* Bounding box overlay to highlight the detected problem */}
          {/* Uses massive box-shadow spread to darken everything outside the box */}
          <div
            data-element="problem-bounding-box"
            style={boxStyle}
            className={css({
              position: 'absolute',
              border: '2px solid',
              borderColor: 'blue.400',
              borderRadius: 'sm',
              pointerEvents: 'none',
              // Large spread shadow covers everything outside, creating cutout effect
              boxShadow: '0 0 0 9999px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(59, 130, 246, 0.4)',
            })}
          />
        </>
      )}
    </div>
  )
}

export function ProblemReviewCard({
  problem,
  index,
  totalProblems,
  worksheetImageUrl,
  onSubmitCorrection,
  onApprove,
  onFlag,
  onNext,
  onPrev,
  isSaving = false,
  isDark = true,
}: ProblemReviewCardProps): ReactNode {
  const [isEditing, setIsEditing] = useState(false)
  const [termsInput, setTermsInput] = useState(formatTerms(problem.terms))
  const [studentAnswerInput, setStudentAnswerInput] = useState(
    problem.studentAnswer?.toString() ?? ''
  )
  const [termsError, setTermsError] = useState<string | null>(null)
  const termsInputRef = useRef<HTMLInputElement>(null)

  // Reset form when problem changes
  useEffect(() => {
    setIsEditing(false)
    setTermsInput(formatTerms(problem.terms))
    setStudentAnswerInput(problem.studentAnswer?.toString() ?? '')
    setTermsError(null)
  }, [problem])

  // Focus input when editing starts
  useEffect(() => {
    if (isEditing && termsInputRef.current) {
      termsInputRef.current.focus()
    }
  }, [isEditing])

  const isCorrect =
    problem.studentAnswer !== null && problem.studentAnswer === problem.correctAnswer
  const minConfidence = Math.min(problem.termsConfidence, problem.studentAnswerConfidence)
  const confidenceInfo = getConfidenceInfo(minConfidence)

  // Calculate correct answer from current terms input
  const calculatedAnswer = useMemo(() => {
    const parsed = parseTermsString(termsInput)
    if (!parsed) return null
    return parsed.reduce((a, b) => a + b, 0)
  }, [termsInput])

  const handleSaveCorrection = useCallback(() => {
    const parsedTerms = parseTermsString(termsInput)
    if (!parsedTerms || parsedTerms.length < 2) {
      setTermsError('Enter at least 2 terms')
      return
    }

    let parsedAnswer: number | null = null
    if (studentAnswerInput.trim()) {
      parsedAnswer = parseInt(studentAnswerInput.trim(), 10)
      if (Number.isNaN(parsedAnswer)) {
        return
      }
    }

    const termsChanged = JSON.stringify(parsedTerms) !== JSON.stringify(problem.terms)
    const answerChanged = parsedAnswer !== problem.studentAnswer

    if (termsChanged || answerChanged) {
      onSubmitCorrection({
        problemNumber: problem.problemNumber,
        correctedTerms: termsChanged ? parsedTerms : undefined,
        correctedStudentAnswer: answerChanged ? parsedAnswer : undefined,
      })
    }

    setIsEditing(false)
  }, [termsInput, studentAnswerInput, problem, onSubmitCorrection])

  const handleKeyDown = useCallback(
    (e: React.KeyboardEvent) => {
      if (e.key === 'Enter') {
        handleSaveCorrection()
      } else if (e.key === 'Escape') {
        setIsEditing(false)
        setTermsInput(formatTerms(problem.terms))
        setStudentAnswerInput(problem.studentAnswer?.toString() ?? '')
      }
    },
    [handleSaveCorrection, problem]
  )

  return (
    <div
      data-component="problem-review-card"
      data-problem-index={index}
      className={css({
        display: 'flex',
        flexDirection: 'column',
        gap: 4,
        padding: 4,
        backgroundColor: isDark ? 'gray.800' : 'white',
        borderRadius: 'xl',
        boxShadow: 'lg',
      })}
    >
      {/* Header with problem number and navigation */}
      <div
        data-element="card-header"
        className={css({
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'space-between',
        })}
      >
        <div
          data-element="problem-number-group"
          className={css({ display: 'flex', alignItems: 'center', gap: 2 })}
        >
          <span
            data-element="problem-number"
            className={css({
              fontSize: 'lg',
              fontWeight: 'bold',
              color: isDark ? 'white' : 'gray.900',
            })}
          >
            Problem {index + 1}
          </span>
          <span
            data-element="problem-counter"
            className={css({
              fontSize: 'sm',
              color: isDark ? 'gray.400' : 'gray.500',
            })}
          >
            of {totalProblems}
          </span>
        </div>

        {/* Confidence badge */}
        <span
          data-element="confidence-badge"
          data-confidence-level={confidenceInfo.label.toLowerCase()}
          className={css({
            px: 2,
            py: 1,
            fontSize: 'xs',
            fontWeight: 'medium',
            borderRadius: 'full',
            backgroundColor: confidenceInfo.bgColor,
            color: confidenceInfo.color,
          })}
        >
          {Math.round(minConfidence * 100)}% confidence
        </span>
      </div>

      {/* Cropped problem image */}
      <CroppedProblemImage
        imageUrl={worksheetImageUrl}
        boundingBox={problem.problemBoundingBox}
        isDark={isDark}
      />

      {/* Problem details */}
      {isEditing ? (
        <div
          data-element="edit-form"
          className={css({ display: 'flex', flexDirection: 'column', gap: 3 })}
        >
          {/* Terms input */}
          <div data-element="terms-input-group">
            <label
              data-element="terms-label"
              className={css({
                display: 'block',
                fontSize: 'sm',
                fontWeight: 'medium',
                color: isDark ? 'gray.400' : 'gray.600',
                marginBottom: 1,
              })}
            >
              Problem
            </label>
            <input
              ref={termsInputRef}
              data-input="terms"
              type="text"
              value={termsInput}
              onChange={(e) => {
                setTermsInput(e.target.value)
                setTermsError(null)
              }}
              onKeyDown={handleKeyDown}
              className={css({
                width: '100%',
                px: 3,
                py: 2,
                fontSize: 'lg',
                fontFamily: 'mono',
                backgroundColor: isDark ? 'gray.900' : 'gray.100',
                color: isDark ? 'white' : 'gray.900',
                border: '2px solid',
                borderColor: termsError ? 'red.500' : isDark ? 'gray.600' : 'gray.300',
                borderRadius: 'lg',
                _focus: {
                  outline: 'none',
                  borderColor: 'blue.500',
                },
              })}
              placeholder="45 + 27 - 12"
            />
            {termsError && (
              <p
                data-element="terms-error"
                className={css({
                  fontSize: 'sm',
                  color: 'red.400',
                  marginTop: 1,
                })}
              >
                {termsError}
              </p>
            )}
            {calculatedAnswer !== null && (
              <p
                data-element="calculated-answer"
                className={css({
                  fontSize: 'sm',
                  color: isDark ? 'gray.500' : 'gray.500',
                  marginTop: 1,
                })}
              >
                Correct answer: {calculatedAnswer}
              </p>
            )}
          </div>

          {/* Student answer input */}
          <div data-element="student-answer-input-group">
            <label
              data-element="student-answer-label"
              className={css({
                display: 'block',
                fontSize: 'sm',
                fontWeight: 'medium',
                color: isDark ? 'gray.400' : 'gray.600',
                marginBottom: 1,
              })}
            >
              Student's Answer
            </label>
            <input
              data-input="student-answer"
              type="text"
              value={studentAnswerInput}
              onChange={(e) => setStudentAnswerInput(e.target.value)}
              onKeyDown={handleKeyDown}
              className={css({
                width: '120px',
                px: 3,
                py: 2,
                fontSize: 'lg',
                fontFamily: 'mono',
                backgroundColor: isDark ? 'gray.900' : 'gray.100',
                color: isDark ? 'white' : 'gray.900',
                border: '2px solid',
                borderColor: isDark ? 'gray.600' : 'gray.300',
                borderRadius: 'lg',
                _focus: {
                  outline: 'none',
                  borderColor: 'blue.500',
                },
              })}
              placeholder="?"
            />
          </div>

          {/* Edit mode buttons */}
          <div
            data-element="edit-actions"
            className={css({ display: 'flex', gap: 2, marginTop: 2 })}
          >
            <button
              type="button"
              data-action="save-correction"
              onClick={handleSaveCorrection}
              disabled={isSaving}
              className={css({
                flex: 1,
                py: 2,
                fontSize: 'sm',
                fontWeight: 'medium',
                backgroundColor: 'green.600',
                color: 'white',
                border: 'none',
                borderRadius: 'lg',
                cursor: 'pointer',
                _hover: { backgroundColor: 'green.700' },
                _disabled: { opacity: 0.5, cursor: 'not-allowed' },
              })}
            >
              {isSaving ? 'Saving...' : 'Save & Continue'}
            </button>
            <button
              type="button"
              data-action="cancel-edit"
              onClick={() => {
                setIsEditing(false)
                setTermsInput(formatTerms(problem.terms))
                setStudentAnswerInput(problem.studentAnswer?.toString() ?? '')
              }}
              className={css({
                px: 4,
                py: 2,
                fontSize: 'sm',
                fontWeight: 'medium',
                backgroundColor: isDark ? 'gray.700' : 'gray.200',
                color: isDark ? 'white' : 'gray.700',
                border: 'none',
                borderRadius: 'lg',
                cursor: 'pointer',
                _hover: { backgroundColor: isDark ? 'gray.600' : 'gray.300' },
              })}
            >
              Cancel
            </button>
          </div>
        </div>
      ) : (
        <div
          data-element="display-mode"
          className={css({ display: 'flex', flexDirection: 'column', gap: 2 })}
        >
          {/* Problem expression - large display */}
          <div
            data-element="problem-expression"
            className={css({
              fontFamily: 'mono',
              fontSize: '2xl',
              fontWeight: 'bold',
              color: isDark ? 'white' : 'gray.900',
              textAlign: 'center',
              padding: 3,
              backgroundColor: isDark ? 'gray.900' : 'gray.100',
              borderRadius: 'lg',
            })}
          >
            <span data-element="terms-display">{formatTerms(problem.terms)}</span> ={' '}
            <span
              data-element="student-answer-display"
              data-answer-status={
                problem.studentAnswer === null ? 'missing' : isCorrect ? 'correct' : 'incorrect'
              }
              className={css({
                color:
                  problem.studentAnswer === null
                    ? isDark
                      ? 'gray.500'
                      : 'gray.400'
                    : isCorrect
                      ? 'green.400'
                      : 'red.400',
              })}
            >
              {problem.studentAnswer ?? '?'}
            </span>
          </div>

          {/* Result indicator */}
          <div
            data-element="result-indicator"
            data-result={
              isCorrect ? 'correct' : problem.studentAnswer === null ? 'missing' : 'incorrect'
            }
            className={css({
              textAlign: 'center',
              fontSize: 'sm',
              color: isCorrect
                ? 'green.400'
                : problem.studentAnswer === null
                  ? isDark
                    ? 'gray.500'
                    : 'gray.500'
                  : 'red.400',
            })}
          >
            {isCorrect
              ? '✓ Correct'
              : problem.studentAnswer === null
                ? 'No answer detected'
                : `✗ Incorrect — Correct answer: ${problem.correctAnswer}`}
          </div>

          {/* Notes from LLM if any */}
          {problem.notes && (
            <div
              data-element="llm-notes"
              className={css({
                fontSize: 'sm',
                color: isDark ? 'yellow.400' : 'yellow.600',
                backgroundColor: isDark ? 'yellow.900/20' : 'yellow.50',
                padding: 2,
                borderRadius: 'md',
                borderLeft: '3px solid',
                borderColor: 'yellow.500',
              })}
            >
              ⚠️ {problem.notes}
            </div>
          )}
        </div>
      )}

      {/* Action buttons - only show when not editing */}
      {!isEditing && (
        <div data-element="action-buttons" className={css({ display: 'flex', gap: 2 })}>
          <button
            type="button"
            data-action="approve-problem"
            onClick={onApprove}
            disabled={isSaving}
            className={css({
              flex: 1,
              py: 3,
              fontSize: 'sm',
              fontWeight: 'bold',
              backgroundColor: 'green.600',
              color: 'white',
              border: 'none',
              borderRadius: 'lg',
              cursor: 'pointer',
              _hover: { backgroundColor: 'green.700' },
              _disabled: { opacity: 0.5, cursor: 'not-allowed' },
            })}
          >
            ✓ Looks Good
          </button>
          <button
            type="button"
            data-action="edit-problem"
            onClick={() => setIsEditing(true)}
            className={css({
              flex: 1,
              py: 3,
              fontSize: 'sm',
              fontWeight: 'bold',
              backgroundColor: isDark ? 'blue.600' : 'blue.500',
              color: 'white',
              border: 'none',
              borderRadius: 'lg',
              cursor: 'pointer',
              _hover: { backgroundColor: isDark ? 'blue.700' : 'blue.600' },
            })}
          >
            ✏️ Correct
          </button>
          <button
            type="button"
            data-action="flag-problem"
            onClick={onFlag}
            disabled={isSaving}
            className={css({
              px: 4,
              py: 3,
              fontSize: 'sm',
              fontWeight: 'bold',
              backgroundColor: isDark ? 'gray.700' : 'gray.200',
              color: isDark ? 'orange.400' : 'orange.600',
              border: 'none',
              borderRadius: 'lg',
              cursor: 'pointer',
              _hover: { backgroundColor: isDark ? 'gray.600' : 'gray.300' },
              _disabled: { opacity: 0.5, cursor: 'not-allowed' },
            })}
          >
            🚩
          </button>
        </div>
      )}

      {/* Navigation */}
      <div
        data-element="navigation"
        className={css({
          display: 'flex',
          justifyContent: 'space-between',
          alignItems: 'center',
          paddingTop: 2,
          borderTop: '1px solid',
          borderColor: isDark ? 'gray.700' : 'gray.200',
        })}
      >
        <button
          type="button"
          data-action="prev-problem"
          onClick={onPrev}
          disabled={index === 0}
          className={css({
            display: 'flex',
            alignItems: 'center',
            gap: 1,
            px: 3,
            py: 2,
            fontSize: 'sm',
            fontWeight: 'medium',
            backgroundColor: 'transparent',
            color: isDark ? 'gray.400' : 'gray.600',
            border: 'none',
            borderRadius: 'md',
            cursor: 'pointer',
            _hover: { backgroundColor: isDark ? 'gray.700' : 'gray.100' },
            _disabled: { opacity: 0.3, cursor: 'not-allowed' },
          })}
        >
          ← Previous
        </button>

        <span
          data-element="navigation-counter"
          className={css({
            fontSize: 'sm',
            color: isDark ? 'gray.500' : 'gray.500',
          })}
        >
          {index + 1} / {totalProblems}
        </span>

        <button
          type="button"
          data-action="next-problem"
          onClick={onNext}
          disabled={index === totalProblems - 1}
          className={css({
            display: 'flex',
            alignItems: 'center',
            gap: 1,
            px: 3,
            py: 2,
            fontSize: 'sm',
            fontWeight: 'medium',
            backgroundColor: 'transparent',
            color: isDark ? 'gray.400' : 'gray.600',
            border: 'none',
            borderRadius: 'md',
            cursor: 'pointer',
            _hover: { backgroundColor: isDark ? 'gray.700' : 'gray.100' },
            _disabled: { opacity: 0.3, cursor: 'not-allowed' },
          })}
        >
          Next →
        </button>
      </div>
    </div>
  )
}

export default ProblemReviewCard