import React, { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useAppContext } from '../context/AppContext'; type CodeItem = { code: number; text: string; }; const LogCodes: React.FC = () => { const { t } = useTranslation(); const { q } = useAppContext(); const [items, setItems] = useState([]); const [kw, setKw] = useState(''); useEffect(() => { const load = async () => { try { const paths = [`/webui/log-codes.json${q}`, '/log-codes.json']; for (const p of paths) { const r = await fetch(p); if (!r.ok) continue; const j = await r.json(); if (Array.isArray(j?.items)) { setItems(j.items); return; } } } catch { setItems([]); } }; load(); }, [q]); const filtered = useMemo(() => { const k = kw.trim().toLowerCase(); if (!k) return items; return items.filter((it) => String(it.code).includes(k) || it.text.toLowerCase().includes(k)); }, [items, kw]); return (

{t('logCodes')}

setKw(e.target.value)} placeholder={t('logCodesSearchPlaceholder')} className="w-72 bg-zinc-900 border border-zinc-800 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-indigo-500" />
{filtered.map((it) => ( ))} {filtered.length === 0 && ( )}
{t('code')} {t('template')}
{it.code} {it.text}
{t('logCodesNoCodes')}
); }; export default LogCodes;