All files / web/src/components/toys/euclid/proof FactRow.tsx

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

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

import type React from 'react'
import type { ProofFact } from '../engine/facts'
import type { CitationDef } from '../engine/citations'
import { getFoundationHref } from '../foundations/citationUtils'
import { PROOF_COLORS, PROOF_FONTS } from './styles'

interface FactRowCitation {
  def: CitationDef | null
  /** Display label (may be abbreviated) */
  label: string | null
  /** Whether to show the full definition text */
  showText: boolean
  onPointerEnter?: (key: string, e: React.PointerEvent) => void
  onPointerLeave?: () => void
  onPointerDown?: (key: string, e: React.PointerEvent) => void
}

interface FactRowProps {
  fact: ProofFact
  highlighted?: boolean
  onMouseEnter?: () => void
  onMouseLeave?: () => void
  citation?: FactRowCitation
  explanation?: string
  fontSize?: number
  /** Extra left padding (for conclusion facts positioned under step indicators) */
  paddingLeft?: number
  /** Border color when not highlighted (default: factBorder) */
  borderColor?: string
}

export function FactRow({
  fact,
  highlighted = false,
  onMouseEnter,
  onMouseLeave,
  citation,
  explanation,
  fontSize = 12,
  paddingLeft = 8,
  borderColor = PROOF_COLORS.factBorder,
}: FactRowProps) {
  const citDef = citation?.def
  const citLabel = citation?.label
  const foundationHref = citDef ? getFoundationHref(citDef.key) : null
  const isLink = citDef && (foundationHref || citDef.key.match(/^I\./))
  const href = isLink ? (foundationHref ?? `/toys/euclid/${citDef!.key.replace('I.', '')}`) : null

  return (
    <div
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      style={{
        fontSize,
        marginBottom: 3,
        paddingLeft,
        cursor: 'default',
        borderLeft: highlighted
          ? `2px solid ${PROOF_COLORS.factBorderHighlighted}`
          : `2px solid ${borderColor}`,
        background: highlighted ? PROOF_COLORS.factBgHighlighted : 'transparent',
        borderRadius: highlighted ? 2 : 0,
        transition: 'all 0.15s ease',
      }}
    >
      <div>
        <span
          style={{
            color: PROOF_COLORS.factStatement,
            fontWeight: 600,
            fontFamily: PROOF_FONTS.serif,
          }}
        >
          {fact.statement}
        </span>
        {citLabel && citDef && (
          <>
            {href ? (
              <a
                href={href}
                target="_blank"
                rel="noopener noreferrer"
                onPointerEnter={
                  citation?.onPointerEnter
                    ? (e) => citation.onPointerEnter!(citDef.key, e)
                    : undefined
                }
                onPointerLeave={citation?.onPointerLeave}
                onPointerDown={
                  citation?.onPointerDown
                    ? (e) => citation.onPointerDown!(citDef.key, e)
                    : undefined
                }
                style={{
                  color: PROOF_COLORS.textMuted,
                  fontFamily: PROOF_FONTS.serif,
                  fontSize: Math.max(fontSize - 2, 9),
                  fontWeight: 600,
                  marginLeft: 6,
                  textDecoration: 'underline',
                  textDecorationColor: PROOF_COLORS.citationUnderline,
                  cursor: 'pointer',
                }}
              >
                [{citLabel}]
              </a>
            ) : (
              <span
                style={{
                  color: PROOF_COLORS.textMuted,
                  fontFamily: PROOF_FONTS.serif,
                  fontSize: Math.max(fontSize - 2, 9),
                  fontWeight: 600,
                  marginLeft: 6,
                }}
              >
                [{citLabel}]
              </span>
            )}
          </>
        )}
      </div>
      {citation?.showText && citDef?.text && (
        <div
          style={{
            color: PROOF_COLORS.textMuted,
            fontStyle: 'italic',
            fontFamily: PROOF_FONTS.serif,
            fontSize: Math.max(fontSize - 2, 9),
            lineHeight: 1.3,
            marginTop: 1,
          }}
        >
          {citDef.text}
        </div>
      )}
      {explanation && (
        <div
          style={{
            color: PROOF_COLORS.textMuted,
            fontStyle: 'italic',
            fontFamily: PROOF_FONTS.serif,
            fontSize: Math.max(fontSize - 2, 9),
            lineHeight: 1.3,
            marginTop: 1,
          }}
        >
          {explanation}
        </div>
      )}
    </div>
  )
}