'use client' import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { useToast } from '@/components/ui/use-toast' import { BookOpen, Plus, X, Download, Upload } from 'lucide-react' interface SuggestionsTabProps { tenantId: string | undefined } export function SuggestionsTab({ tenantId }: SuggestionsTabProps) { const { toast } = useToast() const [journalSuggestions, setJournalSuggestions] = useState([]) const [newSuggestion, setNewSuggestion] = useState('') useEffect(() => { if (!tenantId) return fetch(`/api/tenants/${tenantId}/suggestions`) .then(r => r.ok ? r.json() : null) .then(data => { if (data?.suggestions) setJournalSuggestions(data.suggestions) }) .catch(() => {}) }, [tenantId]) const saveSuggestions = (updated: string[]) => { if (!tenantId) return fetch(`/api/tenants/${tenantId}/suggestions`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ suggestions: updated }), }).then(r => { if (r.ok) toast({ title: 'Gespeichert' }) }) } const handleAdd = () => { const trimmed = newSuggestion.trim() if (!trimmed || journalSuggestions.includes(trimmed)) return const updated = [...journalSuggestions, trimmed].sort((a, b) => a.localeCompare(b, 'de')) setJournalSuggestions(updated) setNewSuggestion('') saveSuggestions(updated) } const handleRemove = (index: number) => { const updated = journalSuggestions.filter((_, idx) => idx !== index) setJournalSuggestions(updated) saveSuggestions(updated) toast({ title: 'Entfernt' }) } return (

Journal-Wörterliste

Häufige Begriffe und Textbausteine, die beim Erfassen von Journal-Einträgen als Vorschläge erscheinen. Wenn der Benutzer im "Was..."-Feld tippt, werden passende Begriffe vorgeschlagen.

{/* Add new suggestion */}
setNewSuggestion(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && newSuggestion.trim()) handleAdd() }} className="flex-1" />
{/* List of suggestions */} {journalSuggestions.length === 0 ? (
Noch keine Begriffe hinterlegt. Fügen Sie häufig verwendete Textbausteine hinzu,
z.B. "Leitung aufbauen", "Leitung abbauen", "Lüfter in Stellung", etc.
) : (
{journalSuggestions.map((s, i) => ( {s} ))}
)}

{journalSuggestions.length} Begriff(e) hinterlegt. Änderungen werden automatisch gespeichert.

) }