import React, { useState, useEffect } from 'react'; import { AlertCircle } from 'lucide-react'; import type { Dataset, FeatureGroup } from '../../types'; import { CodeEditor } from './CodeEditor'; import { DataPreview } from './DataPreview'; interface FeatureFormProps { datasets: Dataset[]; groups: FeatureGroup[]; initialData?: { name: string; description: string; groupId: number; testDatasetId: number; inputColumns: string[]; outputColumns: string[]; code: string; }; onSubmit: (data: any) => void; onCancel: () => void; } export function FeatureForm({ datasets, groups, initialData, onSubmit, onCancel }: FeatureFormProps) { const [formData, setFormData] = useState({ name: initialData?.name || '', description: initialData?.description || '', groupId: initialData?.groupId || '', testDatasetId: initialData?.testDatasetId || '', inputColumns: initialData?.inputColumns || [], outputColumns: initialData?.outputColumns || [], code: initialData?.code || '' }); const [selectedDataset, setSelectedDataset] = useState( initialData?.testDatasetId ? datasets.find(d => d.id === initialData.testDatasetId) || null : null ); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSubmit(formData); }; const handleDatasetChange = (datasetId: string) => { const dataset = datasets.find(d => d.id === Number(datasetId)) || null; setSelectedDataset(dataset); setFormData(prev => ({ ...prev, testDatasetId: datasetId, inputColumns: [], outputColumns: [] })); }; const toggleColumn = (columnName: string, type: 'input' | 'output') => { setFormData(prev => ({ ...prev, [type === 'input' ? 'inputColumns' : 'outputColumns']: prev[type === 'input' ? 'inputColumns' : 'outputColumns'].includes(columnName) ? prev[type === 'input' ? 'inputColumns' : 'outputColumns'].filter(c => c !== columnName) : [...prev[type === 'input' ? 'inputColumns' : 'outputColumns'], columnName] })); }; return (
setFormData({ ...formData, name: e.target.value })} className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" required />