import { Button } from '@/components/ui/button'; import { Download, Eye, Pencil } from 'lucide-react'; import { useState } from 'react'; import ResourceForm from './forms/resource-form'; interface Props { lesson: SectionLesson; isSubmit: boolean; setIsSubmit: (value: boolean) => void; setOpen: (value: boolean) => void; } const ResourceList = ({ lesson, isSubmit, setIsSubmit, setOpen }: Props) => { const [editId, setEditId] = useState(''); // Helper to handle file download const handleDownload = async (resource: LessonResource, e: React.MouseEvent) => { e.preventDefault(); try { // For non-link resources, use the download endpoint const url = route('resources.download', resource.id); window.open(url, '_blank'); } catch (error) { // Fallback to direct download if the endpoint fails window.open(resource.resource, '_blank'); } }; return (
{lesson.resources.length > 0 ? ( lesson.resources.map((resource: LessonResource) => (
{resource.id === editId ? (
) : (
{resource.type === 'link' ? ( {resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')} ) : ( handleDownload(resource, e)}> {resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')} )}
{resource.type !== 'link' ? ( ) : ( )}
)}
)) ) : (

No resources available

)}
); }; export default ResourceList;