|
| 1 | +import React from 'react'; |
| 2 | +import { WeeklyTableSchema, type WeeklyTableData } from './schema'; |
| 3 | +import sampleData from './sample-data.json'; |
| 4 | + |
| 5 | +interface WeeklyTableProps { |
| 6 | + schema: typeof WeeklyTableSchema | null; |
| 7 | + data?: WeeklyTableData | null; |
| 8 | +} |
| 9 | + |
| 10 | +// Extend Window interface for global function |
| 11 | +declare global { |
| 12 | + interface Window { |
| 13 | + __registerVisualComponent: (slug: string, component: React.ComponentType<WeeklyTableProps>) => void; |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +const WeeklyTable: React.FC<WeeklyTableProps> = ({ data }) => { |
| 18 | + // Use sample data if no data is provided |
| 19 | + const tableData = (data as WeeklyTableData) || sampleData; |
| 20 | + |
| 21 | + const days = [ |
| 22 | + { key: 'monday', label: 'Mon', full: 'Monday' }, |
| 23 | + { key: 'tuesday', label: 'Tue', full: 'Tuesday' }, |
| 24 | + { key: 'wednesday', label: 'Wed', full: 'Wednesday' }, |
| 25 | + { key: 'thursday', label: 'Thu', full: 'Thursday' }, |
| 26 | + { key: 'friday', label: 'Fri', full: 'Friday' }, |
| 27 | + { key: 'saturday', label: 'Sat', full: 'Saturday' }, |
| 28 | + { key: 'sunday', label: 'Sun', full: 'Sunday' } |
| 29 | + ]; |
| 30 | + |
| 31 | + const getThemeClasses = (theme?: string) => { |
| 32 | + switch (theme) { |
| 33 | + case 'gradient': |
| 34 | + return 'bg-gradient-to-br from-purple-50 via-blue-50 to-indigo-50'; |
| 35 | + case 'minimal': |
| 36 | + return 'bg-gray-50'; |
| 37 | + case 'colorful': |
| 38 | + return 'bg-gradient-to-br from-pink-50 via-yellow-50 to-green-50'; |
| 39 | + default: |
| 40 | + return 'bg-white'; |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + return ( |
| 45 | + <div className={`min-h-full ${getThemeClasses(tableData.theme)} p-6 print:p-4`}> |
| 46 | + <div className="mx-auto max-w-7xl"> |
| 47 | + {/* Header Section */} |
| 48 | + <div className="mb-8 text-center"> |
| 49 | + <h1 className="mb-2 text-4xl font-bold text-gray-900 print:text-2xl"> |
| 50 | + {tableData.title || 'Weekly Planner'} |
| 51 | + </h1> |
| 52 | + {tableData.subtitle && ( |
| 53 | + <p className="text-lg text-gray-600 print:text-base"> |
| 54 | + {tableData.subtitle} |
| 55 | + </p> |
| 56 | + )} |
| 57 | + </div> |
| 58 | + |
| 59 | + {/* Weekly Table */} |
| 60 | + <div className="overflow-x-auto"> |
| 61 | + <table className="w-full border-collapse overflow-hidden rounded-lg bg-white shadow-lg print:shadow-none"> |
| 62 | + {/* Header Row */} |
| 63 | + <thead> |
| 64 | + <tr className="bg-gradient-to-r from-gray-100 to-gray-200"> |
| 65 | + <th className="min-w-[200px] border border-gray-300 bg-gray-50 p-4 text-left font-bold text-gray-900 print:border-gray-600"> |
| 66 | + <div className="text-sm uppercase tracking-wider text-gray-600">Activities</div> |
| 67 | + </th> |
| 68 | + {days.map((day) => ( |
| 69 | + <th |
| 70 | + key={day.key} |
| 71 | + className="min-w-[140px] border border-gray-300 p-4 text-center font-bold text-gray-900 print:border-gray-600" |
| 72 | + > |
| 73 | + <div className="text-lg print:text-base">{day.label}</div> |
| 74 | + <div className="hidden text-xs font-normal text-gray-600 md:block print:hidden"> |
| 75 | + {day.full} |
| 76 | + </div> |
| 77 | + </th> |
| 78 | + ))} |
| 79 | + </tr> |
| 80 | + </thead> |
| 81 | + |
| 82 | + {/* Body Rows */} |
| 83 | + <tbody> |
| 84 | + {tableData.rows.map((row, rowIndex) => ( |
| 85 | + <tr |
| 86 | + key={row.id} |
| 87 | + className={rowIndex % 2 === 0 ? 'bg-white' : 'bg-gray-25 print:bg-white'} |
| 88 | + > |
| 89 | + {/* Row Header */} |
| 90 | + <td |
| 91 | + className="border border-gray-300 bg-gray-50 p-4 font-medium text-gray-900 print:border-gray-600 print:bg-gray-100" |
| 92 | + style={{ |
| 93 | + borderLeftColor: row.color || '#e5e7eb', |
| 94 | + borderLeftWidth: '4px', |
| 95 | + borderLeftStyle: 'solid' |
| 96 | + }} |
| 97 | + > |
| 98 | + <div className="flex items-start space-x-3"> |
| 99 | + {row.icon && ( |
| 100 | + <span className="shrink-0 text-2xl print:text-xl">{row.icon}</span> |
| 101 | + )} |
| 102 | + <div className="min-w-0 flex-1"> |
| 103 | + <h4 className="mb-1 text-sm font-semibold text-gray-900"> |
| 104 | + {row.label} |
| 105 | + </h4> |
| 106 | + {row.time && ( |
| 107 | + <p className="mb-1 text-xs text-gray-600">{row.time}</p> |
| 108 | + )} |
| 109 | + {row.category && ( |
| 110 | + <span className=" inline-block rounded-full bg-gray-200 p-2 py-1 text-xs text-gray-700 print:bg-gray-300"> |
| 111 | + {row.category} |
| 112 | + </span> |
| 113 | + )} |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </td> |
| 117 | + |
| 118 | + {/* Day Cells */} |
| 119 | + {days.map((day) => { |
| 120 | + const item = tableData.items?.[day.key as keyof typeof tableData.items]?.[row.id]; |
| 121 | + const itemColor = row.color; |
| 122 | + |
| 123 | + return ( |
| 124 | + <td |
| 125 | + key={`${row.id}-${day.key}`} |
| 126 | + className="border border-gray-300 bg-white p-3 align-top print:border-gray-600" |
| 127 | + style={itemColor && item ? { |
| 128 | + borderTopColor: itemColor, |
| 129 | + borderTopWidth: '3px', |
| 130 | + borderTopStyle: 'solid' |
| 131 | + } : {}} |
| 132 | + > |
| 133 | + {item ? ( |
| 134 | + <div className="min-h-[80px] space-y-2 print:min-h-[60px]"> |
| 135 | + {/* Content */} |
| 136 | + <p className="text-sm font-medium leading-tight text-gray-900 print:text-xs"> |
| 137 | + {item.content} |
| 138 | + </p> |
| 139 | + |
| 140 | + {/* Notes */} |
| 141 | + {item.notes && ( |
| 142 | + <p className="border-t border-gray-200 pt-2 text-xs italic text-gray-600 print:border-gray-400"> |
| 143 | + {item.notes} |
| 144 | + </p> |
| 145 | + )} |
| 146 | + </div> |
| 147 | + ) : ( |
| 148 | + <div className="flex h-20 items-center justify-center print:h-16"> |
| 149 | + <span className="text-xs text-gray-400">—</span> |
| 150 | + </div> |
| 151 | + )} |
| 152 | + </td> |
| 153 | + ); |
| 154 | + })} |
| 155 | + </tr> |
| 156 | + ))} |
| 157 | + </tbody> |
| 158 | + </table> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + ); |
| 163 | +}; |
| 164 | + |
| 165 | +// Export for dynamic loading |
| 166 | +export default WeeklyTable; |
| 167 | + |
| 168 | +// Register component for dynamic loading |
| 169 | +if (typeof window !== 'undefined' && window.__registerVisualComponent) { |
| 170 | + window.__registerVisualComponent('weekly-table', WeeklyTable); |
| 171 | +} |
0 commit comments