'use client'; import { useEffect, useState } from 'react'; import type { BeoOption } from '@/types/logbuch'; interface Props { selected: BeoOption[]; onChange: (beos: BeoOption[]) => void; } export default function BeoSelector({ selected, onChange }: Props) { const [all, setAll] = useState([]); useEffect(() => { fetch('/api/beos') .then((r) => { if (!r.ok) throw new Error('Fehler'); return r.json(); }) .then(setAll) .catch(() => {}); }, []); const selectedIds = new Set(selected.map((b) => b.ID)); const available = all.filter((b) => !selectedIds.has(b.ID)); function add(id: string) { if (!id) return; const beo = all.find((b) => b.ID === parseInt(id)); if (beo) onChange([...selected, beo]); } function remove(id: number) { onChange(selected.filter((b) => b.ID !== id)); } return (
{selected.map((b) => ( {b.Kuerzel} — {b.Name} ))}
{available.length > 0 && ( )}
); }