'use client' import { useState } from 'react' import { WowheadRefresh } from './WowheadRefresh' import { wowheadIcon, wowheadUrl, wowheadData } from '@/lib/wowhead' export type CollectionEntry = { id: number; name: string; icon: string } /** Colección (monturas/mascotas) con búsqueda en tiempo real y paginación en cliente. */ export function ArmoryCollection({ items, locale, pageSize, labels, }: { items: CollectionEntry[] locale: string pageSize: number labels: { title: string; search: string; empty: string } }) { const [q, setQ] = useState('') const [page, setPage] = useState(1) const query = q.trim().toLowerCase() const filtered = query ? items.filter((i) => i.name.toLowerCase().includes(query)) : items const pages = Math.max(1, Math.ceil(filtered.length / pageSize)) const p = Math.min(page, pages) const pageItems = filtered.slice((p - 1) * pageSize, (p - 1) * pageSize + pageSize) const win = 2 const from = Math.max(1, p - win) const to = Math.min(pages, p + win) const nums: number[] = [] for (let i = from; i <= to; i++) nums.push(i) return (
{labels.empty}
) : (