'use client'; import { motion } from 'framer-motion'; import { cn } from '@/lib/utils'; import type { BitState } from '@/lib/visualizations/types'; interface BitDisplayProps { bit: BitState; bitWidth?: number; showLabel?: boolean; showDecimal?: boolean; className?: string; } const STATE_CLASSES = { normal: 'bg-[var(--muted)] border-[var(--border)] text-[var(--foreground)]', highlighted: 'bg-[var(--primary)]/20 border-[var(--primary)] text-[var(--primary)]', comparing: 'bg-amber-500/20 border-amber-500 text-amber-500 shadow-[0_0_8px_rgba(245,158,11,0.4)]', result: 'bg-green-500/20 border-green-500 text-green-500', cancelled: 'bg-[var(--muted)]/30 border-[var(--border)]/50 text-[var(--muted-foreground)] opacity-40', } as const; export function BitDisplay({ bit, bitWidth = 8, showLabel = true, showDecimal = true, className, }: BitDisplayProps) { // Pad the bits string to the desired width const paddedBits = bit.bits.padStart(bitWidth, '0'); return (
{/* Label (e.g., "result", "num") */} {showLabel && bit.label && ( {bit.label} )} {/* Decimal value display */} {showDecimal && ( {bit.value} )} {/* Binary representation - individual bit cells */} {paddedBits.split('').map((bitChar, index) => (
0 && 'border-l border-[var(--border)]/30', bit.state === 'cancelled' && 'line-through' )} > {bitChar}
))}
); }