import React, { useState } from 'react'; import { Course, Institution } from '../types'; import { Input, Select } from './Input'; import { Button } from './Button'; import { GraduationCap, X, Check, AlertCircle } from 'lucide-react'; interface CourseFormProps { onCancel: () => void; onSubmit: (data: Partial) => void; initialData?: Course; userId: string; institutions: Institution[]; } const GRADUATION_TYPES = [ 'Bacharelado', 'Licenciatura', 'Tecnológico', 'Especialização', 'Mestrado', 'Doutorado' ]; export const CourseForm: React.FC = ({ onCancel, onSubmit, initialData, userId, institutions }) => { const currentYear = new Date().getFullYear(); const [formData, setFormData] = useState>(initialData || { name: '', institutionId: '', year: currentYear, semester: 1, graduationType: '', createdAt: new Date().toISOString(), createdBy: userId, isActive: true, }); const [showToast, setShowToast] = useState(false); const [error, setError] = useState(''); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // Validações if (!formData.name || formData.name.trim().length < 3) { setError('Nome do curso deve ter pelo menos 3 caracteres'); return; } if (!formData.institutionId) { setError('Selecione uma universidade'); return; } if (!formData.graduationType) { setError('Selecione o tipo de graduação'); return; } setShowToast(true); setTimeout(() => { onSubmit(formData); }, 1000); }; const handleChange = (field: keyof Course, value: any) => { setFormData(prev => ({ ...prev, [field]: value })); setError(''); // Limpa erro ao editar }; return (
{/* Success Toast */} {showToast && (

Sucesso!

Curso cadastrado com sucesso.

)} {/* Form Header */}

{initialData ? 'Editar Curso/Turma' : 'Cadastrar Curso/Turma'}

Registre as turmas disponíveis para eventos fotográficos

{/* Erro global */} {error && (

{error}

)} {/* Informações do Curso */}

Informações do Curso

handleChange('name', e.target.value)} required />
handleChange('year', parseInt(e.target.value))} min={currentYear - 1} max={currentYear + 5} required /> ({ value: t, label: t }))} value={formData.graduationType || ''} onChange={(e) => handleChange('graduationType', e.target.value)} required />
{/* Status Ativo/Inativo */}
handleChange('isActive', e.target.checked)} className="w-4 h-4 text-brand-gold border-gray-300 rounded focus:ring-brand-gold" />
{/* Actions */}
); };