import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { StudentCourseProps } from '@/types/page'; import { usePage } from '@inertiajs/react'; import { format } from 'date-fns'; import { Download, ExternalLink } from 'lucide-react'; const CourseResources = () => { const { props } = usePage(); const { resources } = props; // Funktion zum Formatieren von Datum/Uhrzeit (bei Bedarf auf Deutsch) const formatDate = (dateString: string) => { const date = new Date(dateString); return format(date, 'MMMM dd, yyyy, hh:mm a'); }; // Helferfunktion zum Herunterladen von Dateien const handleDownload = async (resource: LessonResource, e: React.MouseEvent) => { e.preventDefault(); try { // Für nicht-verlinkte Ressourcen den Download-Endpunkt verwenden const url = route('resources.download', resource.id); window.open(url, '_blank'); } catch (error) { // Fallback: Direktes Öffnen/Herunterladen, falls der Endpunkt fehlschlägt window.open(resource.resource, '_blank'); } }; return (
{resources && resources.length > 0 ? ( resources.map((section, sectionIndex) => ( {/* Modul-Überschrift */}

Modul: {section.title}

{/* Lektionen-Tabelle */}
{section.section_lessons && section.section_lessons.length > 0 ? ( section.section_lessons.map((lesson) => lesson.resources && lesson.resources.length > 0 ? (
{/* Lesson Title */}

Lektion: {lesson.title}

{/* Resources Table */}
Titel Datum & Uhrzeit Aktion {lesson.resources.map((resource) => ( {resource.title} {formatDate(resource.created_at)}
{resource.type === 'link' ? ( ) : ( )}
))}
) : null, ) ) : (
Keine Lektionen in diesem Modul gefunden.
)}
)) ) : (

Für diesen Kurs sind noch keine Ressourcen verfügbar.

)}
); }; export default CourseResources;