File size: 3,991 Bytes
c398d0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from 'react';

const ScheduleGrid = ({ scheduleData }) => {
  if (!scheduleData || !scheduleData.grid || !scheduleData.time_slots) {
    return (
      <div className="text-center py-8 text-gray-500 dark:text-gray-400">
        No schedule data available for visualization
      </div>
    );
  }

  const { grid, time_slots, used_days } = scheduleData;

  if (!used_days || used_days.length === 0) {
    return (
      <div className="text-center py-8 text-gray-500 dark:text-gray-400">
        No scheduled classes for this combination
      </div>
    );
  }

  return (
    <div className="mt-6">
      <h4 className="text-lg font-medium mb-4 text-gray-900 dark:text-white">Weekly Schedule</h4>
      
      <div className="overflow-x-auto">
        <table className="min-w-full border border-gray-300 dark:border-gray-600">
          <thead>
            <tr className="bg-gray-50 dark:bg-gray-700">
              <th className="border border-gray-300 dark:border-gray-600 px-4 py-2 text-left font-medium text-gray-700 dark:text-gray-300">
                Time
              </th>
              {used_days.map(day => (
                <th key={day} className="border border-gray-300 dark:border-gray-600 px-4 py-2 text-center font-medium text-gray-700 dark:text-gray-300">
                  {day}
                </th>
              ))}
            </tr>
          </thead>
          <tbody>
            {time_slots.map((timeSlot, timeIndex) => (
              <tr key={timeSlot} className="hover:bg-gray-50 dark:hover:bg-gray-700">
                <td className="border border-gray-300 dark:border-gray-600 px-4 py-2 font-medium text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-gray-700">
                  {timeSlot}
                </td>
                {used_days.map(day => {
                  const cellContent = grid[day] && grid[day][timeIndex] ? grid[day][timeIndex] : '';
                  return (
                    <td key={`${day}-${timeIndex}`} className="border border-gray-300 dark:border-gray-600 px-2 py-2 text-center">
                      {cellContent && (
                        <div className={`text-xs p-2 rounded ${getCellStyle(cellContent)}`}>
                          {cellContent}
                        </div>
                      )}
                    </td>
                  );
                })}
              </tr>
            ))}
          </tbody>
        </table>
      </div>
      
      <div className="mt-4 flex flex-wrap gap-4 text-sm text-gray-700 dark:text-gray-300">
        <div className="flex items-center">
          <div className="w-4 h-4 bg-blue-100 dark:bg-blue-900/30 border border-blue-300 dark:border-blue-700 rounded mr-2"></div>
          <span>Lecture (L)</span>
        </div>
        <div className="flex items-center">
          <div className="w-4 h-4 bg-green-100 dark:bg-green-900/30 border border-green-300 dark:border-green-700 rounded mr-2"></div>
          <span>Tutorial (T)</span>
        </div>
        <div className="flex items-center">
          <div className="w-4 h-4 bg-purple-100 dark:bg-purple-900/30 border border-purple-300 dark:border-purple-700 rounded mr-2"></div>
          <span>Multiple Classes</span>
        </div>
      </div>
    </div>
  );
};

const getCellStyle = (content) => {
  if (content.includes('|')) {
    // Multiple classes in same slot
    return 'bg-purple-100 dark:bg-purple-900/30 border-purple-300 dark:border-purple-700 text-purple-800 dark:text-purple-200';
  } else if (content.includes(' L')) {
    // Lecture
    return 'bg-blue-100 dark:bg-blue-900/30 border-blue-300 dark:border-blue-700 text-blue-800 dark:text-blue-200';
  } else if (content.includes(' T')) {
    // Tutorial
    return 'bg-green-100 dark:bg-green-900/30 border-green-300 dark:border-green-700 text-green-800 dark:text-green-200';
  }
  return 'bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 text-gray-800 dark:text-gray-200';
};

export default ScheduleGrid;