All files / web/src/app/create/worksheets/components/worksheet-preview DuplicateWarningBanner.tsx

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

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

import { useState } from 'react'
import { css } from '@styled/css'
import { useWorksheetPreview } from './WorksheetPreviewContext'

export function DuplicateWarningBanner() {
  const { warnings, isDismissed, setIsDismissed } = useWorksheetPreview()
  const [showDetails, setShowDetails] = useState(false)

  if (warnings.length === 0 || isDismissed) {
    return null
  }

  // Parse warnings to extract actionable items
  const firstWarning = warnings[0]
  const hasMultipleWarnings = warnings.length > 1

  return (
    <div
      data-element="problem-space-warning"
      className={css({
        position: 'absolute',
        top: '50%',
        left: '50%',
        transform: 'translate(-50%, -50%)',
        maxW: 'calc(100% - 160px)', // Leave space for action button
        zIndex: 100,
        bg: 'rgba(254, 243, 199, 0.95)', // amber.100 with transparency
        backdropFilter: 'blur(8px)',
        border: '1px solid',
        borderColor: 'amber.300',
        rounded: '15px',
        p: '4',
        display: 'flex',
        alignItems: 'flex-start',
        gap: '3',
        boxShadow: '0 2px 12px rgba(217, 119, 6, 0.15)', // amber shadow
      })}
    >
      {/* Warning Icon */}
      <div
        className={css({
          fontSize: '2xl',
          lineHeight: '1',
          flexShrink: '0',
        })}
      >
        ⚠️
      </div>

      {/* Content */}
      <div
        className={css({
          flex: '1',
          display: 'flex',
          flexDirection: 'column',
          gap: '2',
        })}
      >
        <div
          className={css({
            fontWeight: 'bold',
            fontSize: 'md',
            color: 'amber.900',
          })}
        >
          Not Enough Unique Problems
        </div>
        <div
          className={css({
            fontSize: 'sm',
            color: 'amber.800',
            lineHeight: '1.5',
          })}
        >
          {firstWarning}
        </div>

        {/* Show/Hide Details Toggle */}
        {hasMultipleWarnings && (
          <button
            type="button"
            onClick={() => setShowDetails(!showDetails)}
            className={css({
              alignSelf: 'flex-start',
              fontSize: 'xs',
              fontWeight: 'semibold',
              color: 'amber.700',
              cursor: 'pointer',
              bg: 'transparent',
              border: 'none',
              p: '0',
              textDecoration: 'underline',
              _hover: {
                color: 'amber.900',
              },
            })}
          >
            {showDetails ? '▼ Hide details' : '▶ Show details'}
          </button>
        )}

        {/* Detailed warnings (collapsed by default) */}
        {showDetails && hasMultipleWarnings && (
          <div
            className={css({
              fontSize: 'xs',
              color: 'amber.800',
              whiteSpace: 'pre-wrap',
              lineHeight: '1.6',
              mt: '2',
              pl: '3',
              borderLeft: '2px solid',
              borderColor: 'amber.300',
            })}
          >
            {warnings.slice(1).join('\n\n')}
          </div>
        )}
      </div>

      {/* Prominent Dismiss Button */}
      <button
        type="button"
        onClick={() => setIsDismissed(true)}
        className={css({
          flexShrink: '0',
          px: '3',
          py: '1.5',
          bg: 'amber.600',
          color: 'white',
          fontSize: 'sm',
          fontWeight: 'bold',
          rounded: 'full',
          cursor: 'pointer',
          border: 'none',
          display: 'flex',
          alignItems: 'center',
          gap: '1',
          transition: 'all 0.2s',
          _hover: {
            bg: 'amber.700',
            transform: 'scale(1.05)',
          },
        })}
        aria-label="Dismiss warning"
      >
        <span>✕</span>
        <span>Dismiss</span>
      </button>
    </div>
  )
}