import { useState, useEffect, useMemo } from 'react'; import { Reorder, useMotionValue } from 'framer-motion'; import { generateStepDisplayText } from '../utils/export'; const typeInfo: { [key: string]: { border: string; text: string; } } = { given: { border: 'border-sky-500', text: 'text-sky-500' }, when: { border: 'border-emerald-500', text: 'text-emerald-500' }, then: { border: 'border-amber-500', text: 'text-amber-500' }, and: { border: 'border-gray-500', text: 'text-gray-500' }, }; const parseTemplate = (template: string) => { const parts = []; let lastIndex = 0; const regex = /\{([^}]+)\}/g; let match; while ((match = regex.exec(template)) !== null) { if (match.index > lastIndex) { parts.push({ type: 'text', value: template.substring(lastIndex, match.index) }); } const placeholder = match[1]; if (placeholder === 'dataTable') { parts.push({ type: 'dataTable', placeholder }); } else if (placeholder.includes('|')) { parts.push({ type: 'select', placeholder, options: placeholder.split('|') }); } else { parts.push({ type: 'input', placeholder }); } lastIndex = regex.lastIndex; } if (lastIndex < template.length) { parts.push({ type: 'text', value: template.substring(lastIndex) }); } return parts; }; export const StepCard = ({ step, onDelete, onUpdateStep }: { step: any; onDelete: () => void; onUpdateStep: (newValues: string[]) => void; }) => { const [isEditing, setIsEditing] = useState(false); const { type: stepType, template, values } = step.data; const templateParts = useMemo(() => parseTemplate(template), [template]); const [paramValues, setParamValues] = useState(values || []); useEffect(() => { setParamValues(values || []); }, [values, step.id]); const handleParamChange = (index: number, value: string) => { const newParams = [...paramValues]; newParams[index] = value; setParamValues(newParams); }; const handleSave = () => { onUpdateStep(paramValues); setIsEditing(false); }; const displayText = useMemo(() => generateStepDisplayText(step.data), [step.data]); const info = typeInfo[stepType.toLowerCase()] || { border: 'border-gray-400', text: 'text-gray-400' }; const y = useMotionValue(0); return (

{displayText}

{stepType.toUpperCase()}

{isEditing && (
{templateParts.filter(p => p.type !== 'text').map((part, idx) => { if (part.type === 'input') { return (
handleParamChange(idx, e.target.value)} className="mt-1 w-full text-sm p-1 rounded bg-gray-100 dark:bg-gray-700 border border-gray-300 dark:border-gray-600" />
); } else if (part.type === 'select') { return (
); } else if (part.type === 'dataTable') { return (