// Variables para almacenar referencias let productFilterButtons = []; let productSections = []; // Función para inicializar los filtros de productos function initProductFilters() { // Obtener botones de filtro productFilterButtons = document.querySelectorAll('[data-product-filter]'); // Si no hay botones con data-product-filter, usar los botones del header if (productFilterButtons.length === 0) { const filterContainer = document.querySelector('#svulbdu'); if (filterContainer) { const buttons = filterContainer.querySelectorAll('button'); buttons.forEach((button, index) => { // Agregar atributos de datos según el texto del botón const buttonText = button.textContent.trim().toLowerCase(); if (buttonText.includes('todos')) { button.setAttribute('data-product-filter', 'todos'); } else if (buttonText.includes('swanson')) { button.setAttribute('data-product-filter', 'swanson'); } else if (buttonText.includes('xtralife')) { button.setAttribute('data-product-filter', 'xtralife'); } else if (buttonText.includes('bio c')) { button.setAttribute('data-product-filter', 'bio-c'); } }); productFilterButtons = document.querySelectorAll('[data-product-filter]'); } } // Obtener secciones de productos productSections = [ { id: 'so2jb8c', category: 'swanson' }, // Sección de productos Swanson { id: 'smzxmk', category: 'xtralife' } // Sección de productos XtraLife // Bio C será agregado cuando exista su sección ]; // Agregar event listeners a los botones productFilterButtons.forEach(button => { button.addEventListener('click', handleFilterClick); }); // Mostrar todos los productos por defecto showAllProducts(); } // Función para manejar clics en filtros function handleFilterClick(event) { const filterValue = event.target.getAttribute('data-product-filter'); // Actualizar estilos de botones activos updateActiveButton(event.target); // Filtrar productos filterProducts(filterValue); } // Función para actualizar el botón activo function updateActiveButton(activeButton) { productFilterButtons.forEach(button => { button.classList.remove('bg-[var(--primary-color)]', 'text-[var(--primary-button-text-color)]'); button.classList.remove('bg-[var(--accent3-color)]', 'text-white'); button.classList.remove('bg-[var(--accent4-color)]', 'text-white'); button.classList.add('bg-white', 'text-[var(--primary-color)]', 'border-2', 'border-[var(--primary-color)]'); }); // Aplicar estilo al botón activo según su categoría const filterValue = activeButton.getAttribute('data-product-filter'); activeButton.classList.remove('bg-white', 'text-[var(--primary-color)]', 'border-2', 'border-[var(--primary-color)]'); if (filterValue === 'todos') { activeButton.classList.add('bg-[var(--primary-color)]', 'text-[var(--primary-button-text-color)]'); } else if (filterValue === 'swanson') { activeButton.classList.add('bg-[var(--primary-color)]', 'text-white'); } else if (filterValue === 'xtralife') { activeButton.classList.add('bg-[var(--accent3-color)]', 'text-white'); } else if (filterValue === 'bio-c') { activeButton.classList.add('bg-[var(--accent4-color)]', 'text-white'); } } // Función para filtrar productos function filterProducts(filterValue) { productSections.forEach(section => { const sectionElement = document.getElementById(section.id); if (sectionElement) { if (filterValue === 'todos' || filterValue === section.category) { sectionElement.style.display = 'block'; // Smooth scroll effect sectionElement.style.opacity = '0'; setTimeout(() => { sectionElement.style.opacity = '1'; sectionElement.style.transition = 'opacity 0.3s ease-in-out'; }, 100); } else { sectionElement.style.display = 'none'; } } }); // Manejar caso especial de Bio C (si no existe sección, mostrar mensaje) if (filterValue === 'bio-c') { showBioCMessage(); } else { hideBioCMessage(); } } // Función para mostrar todos los productos function showAllProducts() { productSections.forEach(section => { const sectionElement = document.getElementById(section.id); if (sectionElement) { sectionElement.style.display = 'block'; sectionElement.style.opacity = '1'; } }); hideBioCMessage(); } // Función para mostrar mensaje de Bio C function showBioCMessage() { // Buscar si ya existe el mensaje let bioCMessage = document.getElementById('bio-c-message'); if (!bioCMessage) { // Crear mensaje para Bio C bioCMessage = document.createElement('div'); bioCMessage.id = 'bio-c-message'; bioCMessage.className = 'py-20 bg-white'; bioCMessage.innerHTML = `

Bio C - Vitamina C Inyectable

Nuestro más reciente lanzamiento: vitamina C para administración endovenosa de la más alta pureza y calidad, fabricada por James Brown Pharma.

Características Especiales

  • Administración endovenosa para máxima absorción
  • Pureza farmacéutica garantizada
  • Fabricado por James Brown Pharma
  • Calidad superior para uso médico
Bio C Super alta resolucion
`; // Insertar el mensaje después de la sección de filtros const filterSection = document.getElementById('svulbdu'); if (filterSection) { filterSection.parentNode.insertBefore(bioCMessage, filterSection.nextSibling); } } bioCMessage.style.display = 'block'; } // Función para ocultar mensaje de Bio C function hideBioCMessage() { const bioCMessage = document.getElementById('bio-c-message'); if (bioCMessage) { bioCMessage.style.display = 'none'; } } // Función de limpieza function cleanupProductFilters() { productFilterButtons.forEach(button => { button.removeEventListener('click', handleFilterClick); }); } // Función principal de inicialización function init() { initProductFilters(); } // Función de limpieza function teardown() { cleanupProductFilters(); } // Exportar funciones export { init, teardown };