"use client"; import { useEffect, useState } from "react"; import { Button, Input, Select, ContentCard, StateMessage } from "@/fsd/shared/ui"; import { analytics } from "@/fsd/shared/config"; type Entry = { path: string; title: string; summary: string; category: string; date: string; text: string; }; const normalized = (value: string) => value .toLocaleLowerCase("ru") .replaceAll("ё", "е") .replace(/\s+/g, " ") .trim(); export default function Search({ entries, idPrefix = "library", emitAnalytics = true }: { entries: Entry[]; idPrefix?: string; emitAnalytics?: boolean }) { const [query, setQuery] = useState(""); const [category, setCategory] = useState("Все темы"); const categories = ["Все темы", ...new Set(entries.map((a) => a.category))]; const words = normalized(query).split(" ").filter(Boolean); const found = entries.filter( (a) => (category === "Все темы" || a.category === category) && words.every((word) => normalized(a.title + " " + a.summary + " " + a.text).includes(word), ), ); useEffect(() => { if (!analytics.enabled || !emitAnalytics || !query.trim() || found.length !== 0) return; // Wait until the live filtered zero state is displayed, not an initial page state. const timer = setTimeout(() => document.dispatchEvent(new Event("videoreg:search-zero-results")), 500); return () => clearTimeout(timer); }, [query, category, found.length, emitAnalytics]); return ( <>
Найдено материалов: {found.length}
Попробуйте название модели, «карта», «кадры» или уберите фильтр раздела.