import { useState, useEffect } from 'react'; import { listSectionSchedules, type SectionSchedule } from '../services/sectionScheduleService'; import LoadingState from './LoadingState'; import ScheduleGrid from './ScheduleGrid'; import { useAuthStore } from '../store/authStore'; export interface ScheduleViewerModalProps { open: boolean; sectionId: number; sectionName: string; academicPeriod?: string | null; onClose: () => void; } export default function ScheduleViewerModal({ open, sectionId, sectionName, academicPeriod, onClose, }: ScheduleViewerModalProps) { const [items, setItems] = useState([]); const [loading, setLoading] = useState(false); const organizationName = useAuthStore((s) => s.user?.organization_name || ''); useEffect(() => { if (!open) return; setLoading(true); listSectionSchedules(sectionId) .then(setItems) .catch(() => setItems([])) .finally(() => setLoading(false)); }, [open, sectionId]); if (!open) return null; const printDate = new Date().toLocaleDateString('es-VE', { day: '2-digit', month: 'long', year: 'numeric', }); return (
e.stopPropagation()} > {/* Modal header — hidden in print */}

Horario — {sectionName}

{academicPeriod && (

{academicPeriod}

)}
{/* Printable grid area */}
{/* Print-only title: school name primary, section as subtitle */}
{organizationName &&

{organizationName}

}

Horario — {sectionName} {academicPeriod ? ` · ${academicPeriod}` : ''}

Generado: {printDate}

{loading ? (
) : items.length === 0 ? (

Sin bloques de horario registrados.

) : ( )}
{/* Modal footer — hidden in print */}
); }