Los libros de Efrén

Una colección de tesoros literarios seleccionados por Flor.

Nuestra Estantería

Cargando catálogo...
// --- 2. RENDERIZADO CON DEBOUNCE --- function debouncedRender() { clearTimeout(searchTimeout); searchTimeout = setTimeout(renderBooks, 300); } function renderBooks() { const searchTerm = document.getElementById('searchInput').value.toLowerCase(); const sortMode = document.getElementById('sortSelect').value; const grid = document.getElementById('bookGrid'); // FILTRADO (Reglas AJ y AE) let filtered = allBooks.filter(book => { if (!book.mostrar) return false; // Solo si AJ es TRUE const matchesSearch = book.title.toLowerCase().includes(searchTerm) || book.author.toLowerCase().includes(searchTerm); let matchesGenre = (currentGenre === 'Todos') || (currentGenre === 'Saldos' && (book.pastilla || '').toLowerCase().includes('saldo')) || (book.genre === currentGenre); return matchesSearch && matchesGenre; }); // ORDENAMIENTO if (sortMode === 'title') filtered.sort((a,b) => a.title.localeCompare(b.title)); if (sortMode === 'price-asc') filtered.sort((a,b) => (parseFloat(a.price) || 0) - (parseFloat(b.price) || 0)); grid.innerHTML = ''; document.getElementById('resultsCount').innerText = `Encontramos ${filtered.length} libros`; filtered.forEach(book => { const isInCart = cart.some(c => c.id === book.id); const isSold = book.status === 'vendido'; // Lógica de Imagen (Local -> OpenLibrary -> Placeholder) const localImg = `./covers/${book.isbn}.jpg`; const fallbackImg = `https://covers.openlibrary.org/b/isbn/${book.isbn}-M.jpg?default=false`; const placeholder = `https://placehold.co/400x600/e8e6e1/1a1a1a?text=${encodeURIComponent(book.title)}`; grid.innerHTML += `
${isSold ? '
Vendido
' : ''} ${book.pastilla && !book.pastilla.toLowerCase().includes('saldo') ? `
${book.pastilla}
` : ''}
${book.title}
${isSold ? 'Vendido' : (book.price ? '$' + book.price : 'Consultar')}
${book.author}
`; }); } // --- 3. INTERACCIONES --- function setGenre(genre, btn) { currentGenre = genre; document.querySelectorAll('.genre-pill').forEach(p => p.classList.remove('active')); btn.classList.add('active'); renderBooks(); } function openDetails(id) { const book = allBooks.find(b => b.id == id); const isSold = book.status === 'vendido'; // El modal siempre abre (tu petición), pero el botón se bloquea const modalImg = `./covers/${book.isbn}.jpg`; document.getElementById('m-img').src = modalImg; document.getElementById('m-img').onerror = function() { this.src = `https://placehold.co/400x600/e8e6e1/1a1a1a?text=${encodeURIComponent(book.title)}`; }; document.getElementById('m-title').innerText = book.title; document.getElementById('m-author').innerText = book.author; document.getElementById('m-genre').innerText = book.genre || 'General'; document.getElementById('m-state').innerText = book.condition || 'No especificado'; document.getElementById('m-pages').innerText = book.pages || '-'; document.getElementById('m-desc').innerText = book.description || 'Sin descripción detallada.'; document.getElementById('m-price').innerText = isSold ? 'Vendido' : (book.price ? '$' + book.price : 'Consultar'); const addBtn = document.getElementById('m-add-btn'); const isInCart = cart.some(c => c.id === book.id); addBtn.disabled = isSold; if (isSold) { addBtn.innerText = "No disponible"; addBtn.className = "btn btn-secondary rounded-pill px-4 disabled"; } else { addBtn.innerText = isInCart ? "Quitar del Carrito" : "Añadir al Carrito"; addBtn.className = isInCart ? "btn btn-success rounded-pill px-4" : "btn btn-dark rounded-pill px-4"; addBtn.onclick = () => { toggleCart(null, book.id); bootstrap.Modal.getInstance(document.getElementById('bookModal')).hide(); }; } new bootstrap.Modal(document.getElementById('bookModal')).show(); } function toggleCart(event, id) { if(event) event.stopPropagation(); const book = allBooks.find(b => b.id == id); if (!book || book.status === 'vendido') return; const idx = cart.findIndex(c => c.id == id); if(idx > -1) cart.splice(idx, 1); else cart.push(book); document.getElementById('cartCounter').innerText = cart.length; renderBooks(); } function openCart() { const container = document.getElementById('cartItems'); if(cart.length === 0) { container.innerHTML = '
No has seleccionado libros aún
'; } else { container.innerHTML = cart.map(item => `
${item.title}
$${item.price || '?'}
`).join(''); } new bootstrap.Modal(document.getElementById('cartModal')).show(); } function checkoutWhatsApp() { if(cart.length === 0) return; let text = "¡Hola Flor! 👋 Me interesan estos libros de Los Libros de Efrén:\n\n"; cart.forEach(item => text += `• ${item.title} ($${item.price || 'Consultar'})\n`); text += "\n¿Están disponibles?"; window.open(`https://wa.me/5491100000000?text=${encodeURIComponent(text)}`); }