import React, { useState } from 'react'; import { Download, Search, Filter, FileText, FileSpreadsheet, FileArchive, FileCode, Sparkles, ExternalLink, BookOpen, Layers } from 'lucide-react'; import { Course, Attachment, AttachmentType } from '../types'; import { MaterialCard } from './MaterialCard'; interface MaterialsHubModalProps { isOpen: boolean; onClose: () => void; courses: Course[]; onSelectCourse?: (course: Course) => void; } export const MaterialsHubModal: React.FC = ({ isOpen, onClose, courses, onSelectCourse, }) => { const [searchTerm, setSearchTerm] = useState(''); const [selectedType, setSelectedType] = useState('all'); const [selectedCategory, setSelectedCategory] = useState('all'); if (!isOpen) return null; // Aggregate all materials across all courses and lessons const allMaterials: Array<{ attachment: Attachment; course: Course; lessonTitle?: string }> = []; courses.forEach(course => { // Global course attachments if (course.attachments && course.attachments.length > 0) { course.attachments.forEach(att => { allMaterials.push({ attachment: att, course }); }); } // Lesson specific attachments if (course.lessons) { course.lessons.forEach(lesson => { if (lesson.attachments && lesson.attachments.length > 0) { lesson.attachments.forEach(att => { allMaterials.push({ attachment: att, course, lessonTitle: lesson.title }); }); } }); } }); // Filtered materials const filtered = allMaterials.filter(item => { const matchesSearch = item.attachment.name.toLowerCase().includes(searchTerm.toLowerCase()) || item.course.title.toLowerCase().includes(searchTerm.toLowerCase()) || (item.attachment.description && item.attachment.description.toLowerCase().includes(searchTerm.toLowerCase())); const matchesType = selectedType === 'all' || item.attachment.type === selectedType; const matchesCategory = selectedCategory === 'all' || item.course.category === selectedCategory; return matchesSearch && matchesType && matchesCategory; }); const categories = Array.from(new Set(courses.map(c => c.category))); return (
{/* Header */}
Central de Recursos & Downloads

Biblioteca de Materiais Complementares

Baixe planilhas, modelos, e-books, checklists e PDFs de todos os cursos do Compor HUB.

{/* Filters and Search Bar */}
{/* Search Input */}
setSearchTerm(e.target.value)} placeholder="Pesquisar material por nome, curso ou palavra-chave..." className="w-full bg-black/60 border border-white/10 rounded-[8px] pl-12 pr-4 py-3 text-body-sm text-white placeholder:text-gray-500 focus:outline-none focus:border-orange-500/50 focus:ring-1 focus:ring-orange-500/50 transition-all" />
{/* Type Filters Pills */}
{[ { id: 'all', label: 'Todos' }, { id: 'pdf', label: 'PDFs' }, { id: 'spreadsheet', label: 'Planilhas' }, { id: 'zip', label: 'Pacotes ZIP' }, { id: 'doc', label: 'Documentos' }, { id: 'link', label: 'Links' }, ].map(t => ( ))}
{/* Category Filter */}
Categoria: {categories.map(cat => { const count = allMaterials.filter(m => m.course.category === cat).length; return ( ); })}
{/* Material Cards Grid */}
{filtered.length === 0 ? (

Nenhum material encontrado

Tente ajustar seus termos de pesquisa ou filtros.

) : (
{filtered.map((item, index) => (
{/* Context Badge: Which Course / Lesson */}
{ onClose(); onSelectCourse?.(item.course); }} className="hover:text-orange-400 cursor-pointer truncate flex items-center gap-1.5" > {item.course.title} {item.lessonTitle && ( {item.lessonTitle} )}
))}
)}
{/* Footer info */}
{filtered.length} materiais disponíveis para download Compor HUB • Materiais Exclusivos
); };