"use client"; // Umschaltung zwischen der detaillierten Allergen-/Zusatzstoff-Auswahl // je Gericht und einem einfachen, editierbaren Hinweistext. import { useCallback, useEffect, useState } from "react"; import { formatMessage } from "@/lib/i18n/shared"; import { useDict } from "@/components/i18n/LocaleProvider"; import type { LabelingMode } from "@/lib/db/settings"; export default function LabelingNoticeEditor() { const dict = useDict(); const [mode, setMode] = useState("detailed"); const [noticeDe, setNoticeDe] = useState(""); const [noticeEn, setNoticeEn] = useState(""); const [noticePl, setNoticePl] = useState(""); const [loading, setLoading] = useState(true); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [info, setInfo] = useState(null); const load = useCallback(async () => { const res = await fetch("/api/settings"); if (!res.ok) { setError(formatMessage(dict.labelingNotice.loadError, { message: String(res.status) })); setLoading(false); return; } const data = await res.json(); setMode(data.labeling_mode ?? "detailed"); setNoticeDe(data.labeling_notice ?? ""); setNoticeEn(data.labeling_notice_en ?? ""); setNoticePl(data.labeling_notice_pl ?? ""); setLoading(false); }, [dict]); useEffect(() => { load(); }, [load]); async function save() { setBusy(true); setError(null); setInfo(null); const res = await fetch("/api/settings", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ labeling_mode: mode, labeling_notice: noticeDe.trim(), labeling_notice_en: noticeEn.trim() || null, labeling_notice_pl: noticePl.trim() || null, }), }); setBusy(false); if (!res.ok) { setError(formatMessage(dict.labelingNotice.saveError, { message: String(res.status) })); return; } setInfo(dict.labelingNotice.saved); } if (loading) return null; return (

{dict.labelingNotice.title}

{dict.labelingNotice.hint}

{error && (

{error}

)} {info &&

{info}

}