import { type SectionSchedule } from '../services/sectionScheduleService'; const DAY_NAMES = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo']; const COLORS = [ 'bg-blue-100 border-blue-300 text-blue-700', 'bg-emerald-100 border-emerald-300 text-emerald-700', 'bg-amber-100 border-amber-300 text-amber-700', 'bg-purple-100 border-purple-300 text-purple-700', 'bg-rose-100 border-rose-300 text-rose-700', 'bg-cyan-100 border-cyan-300 text-cyan-700', 'bg-orange-100 border-orange-300 text-orange-700', 'bg-teal-100 border-teal-300 text-teal-700', ]; const FIXED_SLOTS = Array.from({ length: 11 }, (_, i) => { const h = 7 + i; const entry = `${String(h).padStart(2, '0')}:00`; const exit = `${String(h + 1).padStart(2, '0')}:00`; return { entry, exit }; }); export interface ScheduleGridProps { items: SectionSchedule[]; showWeekend?: boolean; compact?: boolean; } export default function ScheduleGrid({ items, showWeekend = false, compact = false }: ScheduleGridProps) { const visibleDays = DAY_NAMES.filter((_, i) => showWeekend || i < 5); const customSlots: { entry: string; exit: string }[] = []; const seenCustom = new Set(); for (const item of items) { const key = `${item.entry_time}-${item.exit_time}`; if (seenCustom.has(key)) continue; seenCustom.add(key); const isFixed = FIXED_SLOTS.some((s) => s.entry === item.entry_time && s.exit === item.exit_time); if (!isFixed) customSlots.push({ entry: item.entry_time, exit: item.exit_time }); } customSlots.sort((a, b) => a.entry.localeCompare(b.entry)); const allSlots = [...FIXED_SLOTS, ...customSlots]; // En compact (print), oculta filas de horas que no tienen ningún bloque en // ningún día visible. Reduce el alto total para que el PDF entre en 1 página. const slotsToShow = compact ? allSlots.filter((slot) => items.some( (b) => b.entry_time === slot.entry && b.exit_time === slot.exit && visibleDays.includes(DAY_NAMES[b.day_of_week]) ) ) : allSlots; const blockPadding = compact ? 'px-1.5 py-1' : 'px-4 py-3'; const blockText = compact ? 'text-xs' : 'text-base'; const headerText = compact ? 'text-xs' : 'text-base'; const slotText = compact ? 'text-xs' : 'text-base'; const minCellH = compact ? 'min-h-[40px]' : 'min-h-[90px]'; const gridGap = compact ? 'gap-1' : 'gap-3'; const timeColWidth = compact ? '80px' : '120px'; return (
Hora
{visibleDays.map((d, i) => (
{d.slice(0, 3)}
))} {slotsToShow.map((slot, rowIdx) => (
= FIXED_SLOTS.length ? 'italic' : ''}`}> {slot.entry}
{slot.exit}
{visibleDays.map((dayName, vIdx) => { const dayIdx = DAY_NAMES.indexOf(dayName); const cellBlocks = items.filter( (b) => b.day_of_week === dayIdx && b.entry_time === slot.entry && b.exit_time === slot.exit ); return (
0 ? 'border-transparent' : 'border-dashed border-gray-200' }`} > {cellBlocks.map((block, bIdx) => { const colorClass = block.subject_id ? COLORS[block.subject_id % COLORS.length] : 'bg-gray-100 border-gray-200 text-gray-500'; return (
{block.entry_time}–{block.exit_time} {block.subject_name && (
{block.subject_name} {block.teacher_name ? ` — ${block.teacher_name}` : ''}
)}
); })}
); })}
))}
); }