/* Catálogo: header, filtros (edad / categoría / buscador), grid, empty state. */ (function () { const { useState, useMemo, useEffect } = React; function BookGrid({ books, navigate }) { return (
{books.map((b, i) => ( navigate("libro/" + b.slug)} /> ))}
); } window.BookGrid = BookGrid; function Filters({ q, setQ, age, setAge, cat, setCat, cats, top }) { return (
setQ(e.target.value)} className="search-input" />
Edad
{window.FUN_BANDS.map(b => ( ))}
Categoría
{cats.map(c => ( ))}
); } function Catalog({ navigate }) { const [q, setQ] = useState(""); const [age, setAge] = useState(null); const [cat, setCat] = useState(null); const cats = useMemo(() => Object.keys(window.FUN_CATS).filter(c => window.FUN_BOOKS.some(b => b.category === c)), []); const result = useMemo(() => { const term = q.trim().toLowerCase(); return window.FUN_BOOKS.filter(b => { if (age && !b.bands.includes(age)) return false; if (cat && b.category !== cat) return false; if (term) { const hay = (b.title + " " + b.topics.join(" ") + " " + b.description_short + " " + b.category).toLowerCase(); if (!hay.includes(term)) return false; } return true; }); }, [q, age, cat]); const active = (age ? 1 : 0) + (cat ? 1 : 0) + (q ? 1 : 0); const clear = () => { setQ(""); setAge(null); setCat(null); }; return (
Catálogo completo

Todos nuestros libros

Tenemos {window.FUN_BOOKS.length} libros para ti, elegidos uno a uno.

{/* Filtros en barra superior */}
{active > 0 && ( )}
{result.length} {result.length === 1 ? "resultado" : "resultados"}
{result.length > 0 ? ( ) : (

No encontramos libros con esos filtros

Prueba a quitar algún filtro o a buscar otra palabra.

)}
); } window.Catalog = Catalog; })();