"use client"; import { useMemo, useState } from "react"; import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group"; import { SearchIcon } from "lucide-react"; import type { Language } from "@/types/api"; import { WordCard } from "./wordCard"; interface WordsSearchProps { words: string[]; lang: Language; collectionId: string; isRemovable: boolean; placeholder: string; noWordsLabel: string; noResultsLabel: string; } export function WordsSearch({ words, lang, collectionId, isRemovable, placeholder, noWordsLabel, noResultsLabel, }: WordsSearchProps) { const [query, setQuery] = useState(""); const filtered = useMemo(() => { const q = query.trim().toLowerCase(); if (!q) return words; return words.filter((w) => w.toLowerCase().includes(q)); }, [words, query]); return (
setQuery(e.target.value)} /> {words.length === 0 ? (

{noWordsLabel}

) : filtered.length === 0 ? (

{noResultsLabel}

) : (
{filtered.map((word) => (
))}
)}
); }