All files / web/src/app/vision-training/train/components/wizard CollapsedCard.tsx

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

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

import { css } from '../../../../../../styled-system/css'

interface CollapsedCardProps {
  icon: string
  title: string
  summary?: string
  // For upcoming cards - can be a simple string or rich preview with multiple lines
  preview?:
    | {
        primary: string
        secondary?: string
        tertiary?: string
      }
    | string
  status: 'done' | 'upcoming'
  // Optional click handler for done cards (to allow rewinding)
  onClick?: () => void
}

export function CollapsedCard({
  icon,
  title,
  summary,
  preview,
  status,
  onClick,
}: CollapsedCardProps) {
  const isDone = status === 'done'
  const isClickable = isDone && !!onClick

  // Parse preview into lines
  const previewObj = typeof preview === 'string' ? { primary: preview } : preview

  // Rich preview means we need a larger card
  const hasRichPreview = !isDone && previewObj && (previewObj.secondary || previewObj.tertiary)

  return (
    <div
      data-element="collapsed-card"
      data-status={status}
      title={isClickable ? `Go back to ${title}` : title}
      onClick={isClickable ? onClick : undefined}
      onKeyDown={
        isClickable
          ? (e) => {
              if (e.key === 'Enter' || e.key === ' ') {
                onClick()
              }
            }
          : undefined
      }
      role={isClickable ? 'button' : undefined}
      tabIndex={isClickable ? 0 : undefined}
      className={css({
        width: hasRichPreview ? '90px' : '70px',
        minHeight: hasRichPreview ? '85px' : '70px',
        py: hasRichPreview ? 2 : 0,
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        gap: hasRichPreview ? 1 : 0.5,
        bg: 'gray.800',
        borderRadius: 'lg',
        border: '2px solid',
        borderColor: isDone ? 'green.700' : 'gray.700',
        opacity: isDone ? 1 : 0.7,
        transition: 'all 0.15s ease',
        cursor: isClickable ? 'pointer' : 'default',
        _hover: isClickable
          ? {
              bg: 'gray.700',
              borderColor: 'green.600',
              transform: 'scale(1.05)',
            }
          : {},
      })}
    >
      {/* Icon */}
      <span className={css({ fontSize: 'lg' })}>{icon}</span>

      {isDone ? (
        /* Done state - simple summary */
        <span
          className={css({
            fontSize: 'xs',
            color: 'green.400',
            fontWeight: 'medium',
            textAlign: 'center',
            px: 1,
            whiteSpace: 'nowrap',
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            maxWidth: '100%',
          })}
        >
          {summary || '✓'}
        </span>
      ) : previewObj ? (
        /* Upcoming state with preview */
        <div
          className={css({
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            gap: 0,
          })}
        >
          <span
            className={css({
              fontSize: 'xs',
              color: 'gray.300',
              fontWeight: 'medium',
              textAlign: 'center',
              whiteSpace: 'nowrap',
            })}
          >
            {previewObj.primary}
          </span>
          {previewObj.secondary && (
            <span
              className={css({
                fontSize: '10px',
                color: 'gray.500',
                textAlign: 'center',
                whiteSpace: 'nowrap',
              })}
            >
              {previewObj.secondary}
            </span>
          )}
          {previewObj.tertiary && (
            <span
              className={css({
                fontSize: '10px',
                color: 'gray.500',
                textAlign: 'center',
                whiteSpace: 'nowrap',
              })}
            >
              {previewObj.tertiary}
            </span>
          )}
        </div>
      ) : (
        /* Fallback to title */
        <span
          className={css({
            fontSize: 'xs',
            color: 'gray.400',
            fontWeight: 'medium',
            textAlign: 'center',
          })}
        >
          {title}
        </span>
      )}
    </div>
  )
}