import { useEffect, useState, useCallback } from 'react'; import { apiPatch, apiFetchOne, apiFetch, apiLink, apiUnlink } from '../lib/api'; import { STATUS_COLORS } from '../lib/tables'; const READ_ONLY_FIELDS = new Set(['id', 'created_at', 'updated_at']); const TIMESTAMP_RE = /(_at|_timestamp)$/; function isReadOnly(key) { return READ_ONLY_FIELDS.has(key) || TIMESTAMP_RE.test(key); } function FieldLabel({ name }) { return ( {name.replace(/_/g, ' ')} ); } function ReadOnlyValue({ fieldKey, value }) { if (value == null || value === '') return ; if (Array.isArray(value)) { if (value.length === 0) return []; return (
{value.map((v, i) => ( {String(v).slice(0, 12)} ))}
); } if (TIMESTAMP_RE.test(fieldKey)) { return ( {new Date(value).toLocaleString('de-DE')} ); } if (fieldKey === 'status') { const cls = STATUS_COLORS[value] || 'bg-slate-100 text-slate-600'; return {value}; } if (fieldKey === 'id') { return {value}; } return {String(value)}; } function EditableField({ fieldKey, value, fieldDef, onChange }) { const { type, options, min, max } = fieldDef; if (type === 'select') { return ( ); } if (type === 'textarea') { return (