feat: agregar buscador inteligente al menu para estudiantes, ninos y padres
This commit is contained in:
@@ -485,6 +485,209 @@ body.dark-mode .wallet-card:not([class*="theme-"]) {
|
||||
}
|
||||
|
||||
/* Navegación por Categorías */
|
||||
/* =================================================== */
|
||||
/* BUSCADOR INTELIGENTE DEL MENÚ (ESTUDIANTES Y PADRES) */
|
||||
/* =================================================== */
|
||||
.menu-smart-search-section {
|
||||
padding: 0 16px;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.menu-smart-search-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1.5px solid var(--border, #cbd5e1);
|
||||
border-radius: 14px;
|
||||
padding: 0 14px;
|
||||
height: 44px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-smart-search-box:focus-within {
|
||||
border-color: #0284c7;
|
||||
box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15), 0 3px 10px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.menu-smart-search-icon {
|
||||
color: #64748b;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
transition: color 0.15s ease;
|
||||
}
|
||||
|
||||
.menu-smart-search-box:focus-within .menu-smart-search-icon {
|
||||
color: #0284c7;
|
||||
}
|
||||
|
||||
.menu-smart-search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-main, #0f172a);
|
||||
font-size: 0.92rem;
|
||||
font-weight: 600;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.menu-smart-search-input::placeholder {
|
||||
color: #94a3b8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.menu-smart-search-clear-btn {
|
||||
background: #f1f5f9;
|
||||
border: none;
|
||||
color: #64748b;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 800;
|
||||
cursor: pointer;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.menu-smart-search-clear-btn:hover {
|
||||
color: #dc2626;
|
||||
background: #fee2e2;
|
||||
}
|
||||
|
||||
.menu-smart-search-chips {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
.menu-smart-search-chips::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.search-chip {
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1px solid var(--border, #e2e8f0);
|
||||
border-radius: 20px;
|
||||
padding: 5px 12px;
|
||||
font-size: 0.74rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-muted, #64748b);
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.search-chip:hover, .search-chip.active {
|
||||
background: #e0f2fe;
|
||||
color: #0369a1;
|
||||
border-color: #bae6fd;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.menu-smart-search-stats {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted, #64748b);
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.menu-smart-search-stats strong {
|
||||
color: var(--text-main, #0f172a);
|
||||
}
|
||||
|
||||
.menu-smart-search-reset-link {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #0284c7;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.menu-smart-search-empty {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 32px 16px;
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1.5px dashed var(--border, #cbd5e1);
|
||||
border-radius: 16px;
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.menu-smart-search-empty-icon {
|
||||
font-size: 2.2rem;
|
||||
margin-bottom: 8px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.menu-smart-search-empty h4 {
|
||||
font-size: 1.05rem;
|
||||
font-weight: 800;
|
||||
color: var(--text-main, #0f172a);
|
||||
margin: 0 0 6px 0;
|
||||
}
|
||||
|
||||
.menu-smart-search-empty p {
|
||||
font-size: 0.82rem;
|
||||
color: var(--text-muted, #64748b);
|
||||
margin: 0 0 14px 0;
|
||||
}
|
||||
|
||||
.menu-smart-search-suggestions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
body.dark-mode .menu-smart-search-box {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
}
|
||||
body.dark-mode .menu-smart-search-clear-btn {
|
||||
background: #334155;
|
||||
color: #94a3b8;
|
||||
}
|
||||
body.dark-mode .search-chip {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
color: #cbd5e1;
|
||||
}
|
||||
body.dark-mode .search-chip:hover, body.dark-mode .search-chip.active {
|
||||
background: rgba(2, 132, 199, 0.25);
|
||||
color: #38bdf8;
|
||||
border-color: #0284c7;
|
||||
}
|
||||
body.dark-mode .menu-smart-search-empty {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
}
|
||||
|
||||
.category-scroll {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
|
||||
+101
-3
@@ -12,7 +12,7 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=9.8">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=10.0">
|
||||
<style>
|
||||
/* Transiciones suaves */
|
||||
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
||||
@@ -893,6 +893,46 @@
|
||||
<span style="font-size: 0.72rem; color: #0284c7; font-weight: 800; background: #f0f9ff; padding: 3px 8px; border-radius: 6px;">● Conectada</span>
|
||||
</div>
|
||||
|
||||
<!-- BUSCADOR INTELIGENTE EN PORTAL DE PADRES -->
|
||||
<div class="parent-smart-search-card" style="margin-bottom: 14px; background: var(--card-bg, #ffffff); border: 1.5px solid var(--border, #e2e8f0); border-radius: 16px; padding: 12px 14px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;">
|
||||
<label for="parentMenuSearchInput" style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; display: flex; align-items: center; gap: 6px; margin: 0;">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
|
||||
<span>Buscador Inteligente de Alimentos:</span>
|
||||
</label>
|
||||
<span style="font-size: 0.7rem; color: #0284c7; font-weight: 700; background: #f0f9ff; padding: 2px 7px; border-radius: 6px;">Catálogo Soda</span>
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<div style="position: relative; flex: 1;">
|
||||
<input
|
||||
type="text"
|
||||
id="parentMenuSearchInput"
|
||||
placeholder="Buscar platillo, fresco, snack o precio (<1000)..."
|
||||
onkeydown="if(event.key==='Enter') searchMenuFromParent(this.value)"
|
||||
style="width: 100%; box-sizing: border-box; padding: 10px 12px 10px 36px; border-radius: 12px; border: 1.5px solid var(--border, #cbd5e1); font-size: 0.88rem; font-weight: 600; outline: none; background: var(--bg-main, #f8fafc); color: var(--text-main);"
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#94a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none;">
|
||||
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
|
||||
</svg>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onclick="searchMenuFromParent(document.getElementById('parentMenuSearchInput').value)"
|
||||
class="btn-saas btn-saas-primary"
|
||||
style="height: 40px; padding: 0 16px; font-size: 0.84rem; border-radius: 10px; flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;"
|
||||
>
|
||||
<span>Buscar</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- Chips de búsqueda rápida para padres -->
|
||||
<div style="display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; scrollbar-width: none;">
|
||||
<button type="button" class="search-chip" onclick="searchMenuFromParent('fresco')">🥤 Frescos</button>
|
||||
<button type="button" class="search-chip" onclick="searchMenuFromParent('almuerzo')">🍛 Almuerzos</button>
|
||||
<button type="button" class="search-chip" onclick="searchMenuFromParent('saludable')">🥗 Saludables</button>
|
||||
<button type="button" class="search-chip" onclick="searchMenuFromParent('<1000')">💰 < ₡1.000</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MENÚ DE ACCIONES RÁPIDAS SUPERFINAS -->
|
||||
<div class="parent-refined-menu-card">
|
||||
<div onclick="switchToSodaMenuAsParent()" class="parent-refined-menu-item">
|
||||
@@ -902,7 +942,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<span class="parent-refined-item-title">Pre-ordenar Merienda / Ver Menú</span>
|
||||
<span class="parent-refined-item-desc">Alimentos saludables aprobados por el MEP</span>
|
||||
<span class="parent-refined-item-desc">Alimentos y meriendas saludables de la soda</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="parent-refined-arrow">›</span>
|
||||
@@ -1333,6 +1373,64 @@
|
||||
<strong>Atención médica:</strong> <span id="allergyText"></span>
|
||||
</div>
|
||||
|
||||
<!-- BUSCADOR INTELIGENTE DEL MENÚ PARA ESTUDIANTES Y PADRES -->
|
||||
<div class="menu-smart-search-section" id="menuSmartSearchSection">
|
||||
<div class="menu-smart-search-box">
|
||||
<div class="menu-smart-search-icon">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8"/>
|
||||
<path d="m21 21-4.3-4.3"/>
|
||||
</svg>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
id="menuSearchInput"
|
||||
class="menu-smart-search-input"
|
||||
placeholder="Buscar merienda, fresco, snack o precio (<1000)..."
|
||||
oninput="handleMenuSearchInput(this.value)"
|
||||
onkeydown="handleMenuSearchKeyDown(event)"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
aria-label="Buscador inteligente del menú"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
id="menuSearchClearBtn"
|
||||
class="menu-smart-search-clear-btn"
|
||||
onclick="clearMenuSearch()"
|
||||
title="Borrar búsqueda"
|
||||
style="display: none;"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- CHIPS INTELIGENTES DE ACCESO RÁPIDO -->
|
||||
<div class="menu-smart-search-chips" id="menuSmartSearchChips">
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('fresco')">
|
||||
<span>🥤 Frescos</span>
|
||||
</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('casado')">
|
||||
<span>🍛 Casados</span>
|
||||
</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('empanada')">
|
||||
<span>🥟 Empanadas</span>
|
||||
</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('<1000')">
|
||||
<span>💰 Menos de ₡1.000</span>
|
||||
</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('saludable')">
|
||||
<span>🥗 Saludables</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ESTADÍSTICAS Y RESET DE BÚSQUEDA -->
|
||||
<div id="menuSearchStats" class="menu-smart-search-stats" style="display: none;">
|
||||
<span id="menuSearchStatsText">Mostrando 0 productos</span>
|
||||
<button type="button" class="menu-smart-search-reset-link" onclick="clearMenuSearch()">Mostrar menú completo</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BARRA DE CATEGORÍAS -->
|
||||
<div class="category-scroll" id="categoriesBar">
|
||||
<!-- Se llena dinámicamente -->
|
||||
@@ -2285,6 +2383,6 @@
|
||||
<script src="/js/sounds.js?v=9.6"></script>
|
||||
<script src="/js/jsQR.js"></script>
|
||||
<script src="/js/food-icons.js?v=1.1"></script>
|
||||
<script src="/js/app.js?v=10.1"></script>
|
||||
<script src="/js/app.js?v=10.2"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+209
-7
@@ -6,6 +6,7 @@ let students = [];
|
||||
let categories = [];
|
||||
let products = [];
|
||||
let activeCategoryId = null;
|
||||
let menuSearchQuery = '';
|
||||
let cart = [];
|
||||
let currentAppMode = 'teens';
|
||||
let adminProducts = [];
|
||||
@@ -125,6 +126,20 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Atajo global para enfocar el buscador inteligente del menú al presionar '/'
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === '/' && !['INPUT', 'TEXTAREA', 'SELECT'].includes(document.activeElement?.tagName)) {
|
||||
const searchInput = document.getElementById('menuSearchInput');
|
||||
const appContainer = document.getElementById('appContainer');
|
||||
if (searchInput && appContainer && appContainer.style.display !== 'none') {
|
||||
e.preventDefault();
|
||||
searchInput.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
searchInput.focus();
|
||||
searchInput.select();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// VISTA Y MANEJO DE AUTENTICACIÓN / SESIÓN
|
||||
// ==========================================
|
||||
@@ -766,7 +781,141 @@ function selectCategory(catId) {
|
||||
renderProducts();
|
||||
}
|
||||
|
||||
// Renderizado de Productos del Menú (Con soporte para Agotado / Greyed Out)
|
||||
// ==========================================
|
||||
// BUSCADOR INTELIGENTE DEL MENÚ (ESTUDIANTES, NIÑOS Y PADRES)
|
||||
// ==========================================
|
||||
|
||||
function normalizeSearchStr(s) {
|
||||
if (!s) return '';
|
||||
return String(s)
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.trim();
|
||||
}
|
||||
|
||||
function matchesMenuProduct(prod, query) {
|
||||
if (!query) return true;
|
||||
const cleanQ = normalizeSearchStr(query);
|
||||
if (!cleanQ) return true;
|
||||
|
||||
// 1. Operadores de precio (ej: <1000, <=1200, >500, >=800 o "< 1000")
|
||||
const priceOpMatch = cleanQ.replace(/\s+/g, '').match(/^([<>]=?)(\d+)$/);
|
||||
if (priceOpMatch) {
|
||||
const op = priceOpMatch[1];
|
||||
const val = parseInt(priceOpMatch[2], 10);
|
||||
const price = Number(prod.precio_colones) || 0;
|
||||
if (op === '<') return price < val;
|
||||
if (op === '<=') return price <= val;
|
||||
if (op === '>') return price > val;
|
||||
if (op === '>=') return price >= val;
|
||||
}
|
||||
|
||||
// 2. Filtros especiales por palabras clave inteligentes
|
||||
if (cleanQ === 'saludable' || cleanQ === 'saludables' || cleanQ === 'nutritivo') {
|
||||
return Boolean(prod.cumple_mep || prod.es_saludable || /fruta|avena|ensalada|natural/i.test((prod.nombre || '') + ' ' + (prod.descripcion || '')));
|
||||
}
|
||||
if (cleanQ === 'bloqueado' || cleanQ === 'agotado' || cleanQ === 'sin stock') {
|
||||
return Boolean(prod.disponible === 0 || (prod.control_stock === 1 && prod.stock <= 0));
|
||||
}
|
||||
if (cleanQ === 'disponible' || cleanQ === 'en stock') {
|
||||
return Boolean(prod.disponible === 1 && (!prod.control_stock || prod.stock > 0));
|
||||
}
|
||||
if (cleanQ === 'fresco' || cleanQ === 'frescos' || cleanQ === 'bebida' || cleanQ === 'bebidas' || cleanQ === 'jugo' || cleanQ === 'jugos' || cleanQ === 'batido') {
|
||||
const catName = normalizeSearchStr(prod.categoria_nombre || '');
|
||||
if (catName.includes('bebida') || catName.includes('fresco') || prod.categoria_id === 3) return true;
|
||||
}
|
||||
if (cleanQ === 'desayuno' || cleanQ === 'desayunos' || cleanQ === 'merienda' || cleanQ === 'meriendas') {
|
||||
if (prod.categoria_id === 1) return true;
|
||||
}
|
||||
if (cleanQ === 'almuerzo' || cleanQ === 'almuerzos' || cleanQ === 'plato' || cleanQ === 'platos' || cleanQ === 'comida') {
|
||||
if (prod.categoria_id === 2) return true;
|
||||
}
|
||||
if (cleanQ === 'snack' || cleanQ === 'snacks' || cleanQ === 'galleta' || cleanQ === 'galletas' || cleanQ === 'postre') {
|
||||
if (prod.categoria_id === 4) return true;
|
||||
}
|
||||
|
||||
// 3. Coincidencia por precio numérico exacto o parcial (ej: 750, 1000)
|
||||
if (/^\d+$/.test(cleanQ)) {
|
||||
const pStr = String(prod.precio_colones || '');
|
||||
if (pStr === cleanQ || pStr.includes(cleanQ)) return true;
|
||||
}
|
||||
|
||||
// 4. Búsqueda multi-término inteligente (nombre, categoría, descripción, alergenos, precio)
|
||||
const tokens = cleanQ.split(/\s+/).filter(Boolean);
|
||||
const targetStr = normalizeSearchStr(
|
||||
`${prod.nombre || ''} ${prod.categoria_nombre || ''} ${prod.descripcion || ''} ${prod.alergenos || ''} ${prod.precio_colones || ''}`
|
||||
);
|
||||
|
||||
return tokens.every(token => targetStr.includes(token));
|
||||
}
|
||||
|
||||
function handleMenuSearchInput(val) {
|
||||
menuSearchQuery = val || '';
|
||||
const clearBtn = document.getElementById('menuSearchClearBtn');
|
||||
if (clearBtn) {
|
||||
clearBtn.style.display = menuSearchQuery.trim() ? 'inline-flex' : 'none';
|
||||
}
|
||||
renderProducts();
|
||||
}
|
||||
|
||||
function clearMenuSearch() {
|
||||
menuSearchQuery = '';
|
||||
const input = document.getElementById('menuSearchInput');
|
||||
if (input) {
|
||||
input.value = '';
|
||||
input.focus();
|
||||
}
|
||||
const clearBtn = document.getElementById('menuSearchClearBtn');
|
||||
if (clearBtn) clearBtn.style.display = 'none';
|
||||
|
||||
// Desactivar chips de búsqueda
|
||||
document.querySelectorAll('.search-chip').forEach(c => c.classList.remove('active'));
|
||||
|
||||
renderProducts();
|
||||
}
|
||||
|
||||
function setMenuSearchSuggestion(term) {
|
||||
// Al seleccionar sugerencia rápida, si el usuario busca algo general, aseguramos buscar en todo
|
||||
if (['fresco', 'casado', 'empanada', '<1000', 'saludable'].includes(term)) {
|
||||
activeCategoryId = null;
|
||||
renderCategories();
|
||||
}
|
||||
const input = document.getElementById('menuSearchInput');
|
||||
if (input) {
|
||||
input.value = term;
|
||||
handleMenuSearchInput(term);
|
||||
input.focus();
|
||||
}
|
||||
document.querySelectorAll('.search-chip').forEach(chip => {
|
||||
if (chip.getAttribute('onclick')?.includes(`'${term}'`)) {
|
||||
chip.classList.add('active');
|
||||
} else {
|
||||
chip.classList.remove('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function handleMenuSearchKeyDown(e) {
|
||||
if (e.key === 'Escape') {
|
||||
clearMenuSearch();
|
||||
}
|
||||
}
|
||||
|
||||
function searchMenuFromParent(val) {
|
||||
switchToSodaMenuAsParent();
|
||||
setTimeout(() => {
|
||||
const searchInput = document.getElementById('menuSearchInput');
|
||||
if (searchInput) {
|
||||
searchInput.value = val || '';
|
||||
handleMenuSearchInput(val || '');
|
||||
searchInput.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
searchInput.focus();
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
// Renderizado de Productos del Menú (Con soporte para Agotado / Greyed Out y Buscador Inteligente)
|
||||
function renderProducts() {
|
||||
const grid = document.getElementById('productsGrid');
|
||||
if (!grid) return;
|
||||
@@ -774,6 +923,7 @@ function renderProducts() {
|
||||
|
||||
let filtered = products;
|
||||
|
||||
// Filtrado por categoría si no es "Todos"
|
||||
if (activeCategoryId !== null) {
|
||||
filtered = filtered.filter(p => p.categoria_id === activeCategoryId);
|
||||
}
|
||||
@@ -782,13 +932,65 @@ function renderProducts() {
|
||||
filtered = filtered.filter(p => p.cumple_mep === 1);
|
||||
}
|
||||
|
||||
// APLICACIÓN DEL BUSCADOR INTELIGENTE MULTI-TÉRMINO
|
||||
const hasSearch = Boolean(menuSearchQuery && menuSearchQuery.trim());
|
||||
if (hasSearch) {
|
||||
filtered = filtered.filter(p => matchesMenuProduct(p, menuSearchQuery));
|
||||
}
|
||||
|
||||
// Actualización de encabezado y estadísticas de resultados
|
||||
const statsEl = document.getElementById('menuSearchStats');
|
||||
const statsText = document.getElementById('menuSearchStatsText');
|
||||
const catalogTitle = document.getElementById('catalogTitle');
|
||||
|
||||
if (statsEl && statsText) {
|
||||
if (hasSearch) {
|
||||
statsEl.style.display = 'flex';
|
||||
const cleanTerm = menuSearchQuery.trim();
|
||||
statsText.innerHTML = `Mostrando <strong>${filtered.length}</strong> de ${products.length} productos para "<strong>${escapeHtml(cleanTerm)}</strong>"`;
|
||||
if (catalogTitle) {
|
||||
catalogTitle.textContent = `Resultados de búsqueda (${filtered.length})`;
|
||||
}
|
||||
} else {
|
||||
statsEl.style.display = 'none';
|
||||
if (catalogTitle) {
|
||||
if (activeCategoryId !== null) {
|
||||
const currentCat = categories.find(c => c.id === activeCategoryId);
|
||||
catalogTitle.textContent = currentCat ? currentCat.nombre : 'Menú del Recreo';
|
||||
} else {
|
||||
catalogTitle.textContent = 'Menú del Recreo';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Estado vacío: Sin resultados
|
||||
if (filtered.length === 0) {
|
||||
grid.innerHTML = `
|
||||
<div style="grid-column: 1 / -1; text-align: center; padding: 30px; color: var(--text-muted);">
|
||||
<div style="display: flex; justify-content: center; margin-bottom: 8px;"><svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="opacity: 0.4;"><path d="M18 8h1a4 4 0 0 1 0 8h-1"/><path d="M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V8z"/><line x1="6" y1="1" x2="6" y2="4"/><line x1="10" y1="1" x2="10" y2="4"/><line x1="14" y1="1" x2="14" y2="4"/></svg></div>
|
||||
<p>No hay productos en esta categoría por ahora.</p>
|
||||
</div>
|
||||
`;
|
||||
if (hasSearch) {
|
||||
grid.innerHTML = `
|
||||
<div class="menu-smart-search-empty">
|
||||
<div class="menu-smart-search-empty-icon">🔍</div>
|
||||
<h4>No encontramos productos</h4>
|
||||
<p>No hay platillos o bebidas que coincidan con "<strong>${escapeHtml(menuSearchQuery.trim())}</strong>".</p>
|
||||
<div class="menu-smart-search-suggestions">
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('fresco')">🥤 Frescos naturales</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('casado')">🍛 Casados</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('empanada')">🥟 Empanadas</button>
|
||||
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('<1000')">💰 Menos de ₡1.000</button>
|
||||
</div>
|
||||
<button type="button" class="btn-saas btn-saas-outline" onclick="clearMenuSearch()" style="margin-top: 8px;">
|
||||
Ver catálogo completo
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
grid.innerHTML = `
|
||||
<div style="grid-column: 1 / -1; text-align: center; padding: 30px; color: var(--text-muted);">
|
||||
<div style="display: flex; justify-content: center; margin-bottom: 8px;"><svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="opacity: 0.4;"><path d="M18 8h1a4 4 0 0 1 0 8h-1"/><path d="M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V8z"/><line x1="6" y1="1" x2="6" y2="4"/><line x1="10" y1="1" x2="10" y2="4"/><line x1="14" y1="1" x2="14" y2="4"/></svg></div>
|
||||
<p>No hay productos en esta categoría por ahora.</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user