/** * SiboPay Food & Beverage Vector Icons (SVG) * Iconografía vectorial fina, minimalista y elegante para productos escolares y soda */ (function (window) { 'use strict'; const FOOD_ICONS = { 'sandwich': { label: 'Sandwich / Panini', svg: '' }, 'croissant': { label: 'Empanada / Repostería', svg: '' }, 'utensils': { label: 'Plato Fuerte / Almuerzo', svg: '' }, 'cup-soda': { label: 'Bebida / Fresco Natural', svg: '' }, 'milk': { label: 'Leche / Lácteos', svg: '' }, 'coffee': { label: 'Café / Infusión Caliente', svg: '' }, 'apple': { label: 'Fruta / Saludable', svg: '' }, 'bowl': { label: 'Bowl / Ensalada / Sopa', svg: '' }, 'cookie': { label: 'Galleta / Snack', svg: '' }, 'pizza': { label: 'Pizza / Taco / Rápida', svg: '' }, 'meat': { label: 'Carne / Pollo / Proteína', svg: '' }, 'wheat': { label: 'Cereal / Granola / Avena', svg: '' }, 'ice-cream': { label: 'Postre / Gelatina / Helado', svg: '' }, 'store': { label: 'Todos / Menú Completo', svg: '' } }; // Mapeo automático de emojis antiguos a iconos SVG elegantes const EMOJI_TO_KEY = { '🥪': 'sandwich', '🥟': 'croissant', '🌮': 'pizza', '🍳': 'utensils', '🍗': 'meat', '🍛': 'utensils', '🍹': 'cup-soda', '🥤': 'cup-soda', '🧃': 'cup-soda', '🥛': 'milk', '🍉': 'apple', '🥣': 'bowl', '🌾': 'wheat', '🍮': 'ice-cream', '🍎': 'apple', '🍕': 'pizza', '🥗': 'bowl', '🍪': 'cookie', '🍽️': 'utensils', '☕': 'coffee', '🥩': 'meat', '🍦': 'ice-cream', '🥑': 'apple', '🥐': 'croissant', '🍞': 'sandwich', '🍔': 'sandwich' }; /** * Resuelve el identificador de icono SVG a partir de una clave, emoji o nombre de producto */ function resolveIconKey(rawInput, fallbackName) { if (!rawInput && !fallbackName) return 'sandwich'; const input = String(rawInput || '').trim(); // 1. Si coincide directamente con una clave conocida if (FOOD_ICONS[input]) return input; // 2. Si coincide con un emoji mapeado if (EMOJI_TO_KEY[input]) return EMOJI_TO_KEY[input]; // 3. Analizar palabras clave en el nombre del producto const text = (String(fallbackName || '') + ' ' + input).toLowerCase(); if (text.includes('empanada') || text.includes('pastel') || text.includes('reposter') || text.includes('croissant')) return 'croissant'; if (text.includes('sandwich') || text.includes('emparedado') || text.includes('pan') || text.includes('tostada')) return 'sandwich'; if (text.includes('fresco') || text.includes('jugo') || text.includes('te frio') || text.includes('té') || text.includes('gaseosa') || text.includes('bebida') || text.includes('refresco')) return 'cup-soda'; if (text.includes('leche') || text.includes('batido')) return 'milk'; if (text.includes('cafe') || text.includes('café') || text.includes('chocolate caliente')) return 'coffee'; if (text.includes('fruta') || text.includes('manzana') || text.includes('sandia') || text.includes('sandía') || text.includes('pina') || text.includes('piña')) return 'apple'; if (text.includes('ensalada') || text.includes('sopa') || text.includes('bowl') || text.includes('yogurt')) return 'bowl'; if (text.includes('pinto') || text.includes('casado') || text.includes('almuerzo') || text.includes('arroz') || text.includes('plato')) return 'utensils'; if (text.includes('pollo') || text.includes('carne') || text.includes('bistec') || text.includes('chuleta')) return 'meat'; if (text.includes('pizza') || text.includes('taco') || text.includes('wrap')) return 'pizza'; if (text.includes('galleta') || text.includes('snack') || text.includes('barra') || text.includes('cereal') || text.includes('avena')) return 'cookie'; if (text.includes('gelatina') || text.includes('helado') || text.includes('postre') || text.includes('flan')) return 'ice-cream'; return 'sandwich'; } /** * Retorna el SVG puro del icono */ function getFoodSvg(rawInput, fallbackName, size = 22) { const key = resolveIconKey(rawInput, fallbackName); const item = FOOD_ICONS[key] || FOOD_ICONS['sandwich']; return item.svg.replace(' ${svg} `; } if (variant === 'badge') { const svg = getFoodSvg(key, null, 17); return `
${svg}
`; } if (variant === 'inline') { const svg = getFoodSvg(key, null, 15); return `${svg}`; } return getFoodSvg(key, fallbackName, 20); } /** * Renderiza el selector de iconos finos para los modales de creación/edición de productos */ function renderIconPicker(containerId, inputId, previewId, currentKey) { const container = document.getElementById(containerId); const input = document.getElementById(inputId); const preview = document.getElementById(previewId); if (!container) return; const resolved = resolveIconKey(currentKey || (input ? input.value : 'sandwich')); if (input) input.value = resolved; if (preview) preview.innerHTML = getFoodIconBadge(resolved, null, 'card'); const pickerKeys = [ 'sandwich', 'croissant', 'utensils', 'cup-soda', 'milk', 'coffee', 'apple', 'bowl', 'cookie', 'pizza', 'meat', 'ice-cream' ]; container.innerHTML = pickerKeys.map(k => { const isAct = (k === resolved); const svg = getFoodSvg(k, null, 18); const label = FOOD_ICONS[k]?.label || k; return ` `; }).join(''); } function onPickIcon(key, containerId, inputId, previewId) { const input = document.getElementById(inputId); const preview = document.getElementById(previewId); if (input) input.value = key; if (preview) preview.innerHTML = getFoodIconBadge(key, null, 'card'); const container = document.getElementById(containerId); if (container) { container.querySelectorAll('.btn-food-icon-picker').forEach(b => { b.classList.remove('active'); b.style.borderColor = 'var(--border)'; b.style.background = 'var(--card-bg)'; b.style.color = 'var(--text-muted)'; }); const activeBtn = document.getElementById(`btnFoodPick_${key}`); if (activeBtn) { activeBtn.classList.add('active'); activeBtn.style.borderColor = '#0284c7'; activeBtn.style.background = '#f0f9ff'; activeBtn.style.color = '#0284c7'; } } } // Exportar al ámbito global window.SiboPayIcons = { FOOD_ICONS, resolveIconKey, getFoodSvg, getFoodIconBadge, renderIconPicker, onPickIcon }; })(window);