// Dashboard/PlatformSearch.jsx function PlatformSearch({ dataSources = {}, onSelect }) { // dataSources: { courses: [], certificates: [], profile: {...}, other: [...] } const [q, setQ] = React.useState(""); const [results, setResults] = React.useState([]); const [loading, setLoading] = React.useState(false); // простой debounce React.useEffect(() => { if (!q) { setResults([]); return; } setLoading(true); const id = setTimeout(() => { const query = q.trim().toLowerCase(); const matches = []; // Поиск по курсам (dataSources.courses || []).forEach((c) => { if ((c.title || "").toLowerCase().includes(query) || (c.sub || "").toLowerCase().includes(query)) { matches.push({ type: "course", item: c }); } }); // Поиск по сертификатам (dataSources.certificates || []).forEach((c) => { if ((c.title || "").toLowerCase().includes(query)) { matches.push({ type: "certificate", item: c }); } }); // Поиск по профилю (имя, email, специализация) const profile = dataSources.profile || {}; ["name", "email", "specialization", "license"].forEach((k) => { if ((profile[k] || "").toLowerCase().includes(query)) { matches.push({ type: "profile", item: profile, field: k }); } }); // Дополнительные источники (опционально) (dataSources.other || []).forEach((o) => { if ((o.title || "").toLowerCase().includes(query) || (o.text || "").toLowerCase().includes(query)) { matches.push({ type: "other", item: o }); } }); setResults(matches); setLoading(false); }, 300); return () => clearTimeout(id); }, [q, dataSources]); function highlight(text = "", q) { if (!q) return text; const idx = text.toLowerCase().indexOf(q.toLowerCase()); if (idx === -1) return text; return ( <> {text.slice(0, idx)} {text.slice(idx, idx + q.length)} {text.slice(idx + q.length)} > ); } return (