'use client' import { useState, useEffect } from 'react' import { teacherUnavailableDayApi, teachersApi } from '@/lib/stundenplan/api' import type { TeacherUnavailableDay, TimetableTeacher } from '@/app/stundenplan/types' import { useConstraintCrud, ConstraintShell, useShellStyles, DAYS, dayLabel } from './_shell' type FormState = Omit const initialForm: FormState = { teacher_id: '', day_of_week: 1, is_hard: true, weight: 100, active: true, note: '', } export function TeacherUnavailableDayEditor() { const styles = useShellStyles() const crud = useConstraintCrud(teacherUnavailableDayApi, initialForm) const [teachers, setTeachers] = useState([]) useEffect(() => { teachersApi.list().then(setTeachers).catch(() => setTeachers([])) }, []) const teacherLabel = (id: string): string => { const t = teachers.find(x => x.id === id) return t ? `${t.last_name}, ${t.first_name} (${t.short_code})` : id.slice(0, 8) + '…' } return (
crud.setForm({ ...crud.form, weight: parseInt(e.target.value) || 0 })} className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
crud.setForm({ ...crud.form, is_hard: e.target.checked })} className="w-5 h-5" />
crud.setForm({ ...crud.form, active: e.target.checked })} className="w-5 h-5" />
crud.setForm({ ...crud.form, note: e.target.value })} placeholder="z.B. Zweitjob in Praxis" className={`w-full px-3 py-2 rounded-lg border ${styles.inputClass}`} />
} renderRow={(item) => { const c = item as TeacherUnavailableDay return ( {teacherLabel(c.teacher_id)} {dayLabel(c.day_of_week)} {c.is_hard ? '✓' : '—'} {c.weight} {c.active ? '✓' : '—'} {c.note || '—'} ) }} /> ) }