'use client';
import { motion } from 'framer-motion';
import { cn } from '@/lib/utils';
import type { BitManipulationState } from '@/lib/visualizations/types';
import { BitDisplay } from '../primitives/bit-display';
interface BitManipulationViewProps {
state: BitManipulationState;
bitWidth?: number;
className?: string;
}
const OPERATION_SYMBOLS = {
XOR: '⊕',
AND: '&',
OR: '|',
NOT: '~',
} as const;
export function BitManipulationView({
state,
bitWidth = 4,
className,
}: BitManipulationViewProps) {
const hasOperation = state.operation && state.operands.length >= 2;
const hasResult = state.result;
return (
{/* Label */}
{state.label && (
{state.label}
)}
{/* Operation layout */}
{/* Operands */}
{state.operands.map((operand, index) => (
{/* Show operation symbol before second operand */}
{index === 1 && hasOperation && (
{OPERATION_SYMBOLS[state.operation!]}
)}
{index === 0 && hasOperation && (
/* Spacer for alignment */
)}
))}
{/* Divider line and result */}
{hasResult && (
<>
=
>
)}
);
}
interface BitXORSequenceProps {
states: BitManipulationState[];
bitWidth?: number;
className?: string;
}
export function BitXORSequence({
states,
bitWidth = 4,
className,
}: BitXORSequenceProps) {
return (
{states.map((state) => (
))}
);
}
interface BitArrayWithBinaryProps {
values: Array<{
value: number;
bits: string;
state: 'normal' | 'highlighted' | 'comparing' | 'result' | 'cancelled';
}>;
bitWidth?: number;
label?: string;
className?: string;
}
export function BitArrayWithBinary({
values,
bitWidth = 4,
label,
className,
}: BitArrayWithBinaryProps) {
return (
{label && (
{label}
)}
{values.map((item, index) => (
))}
);
}