PATRONES GRATIS

'gratis-pareo': { nombre: 'PATRÓN PAREO', precio: '$0 (GRATIS)', stock: 'Descarga gratuita inmediata', fotos: ['pareo-alma-portada.jpg', 'pareo-alma-detalle.jpg'], especificaciones: [ { label: 'Formato', valor: 'PDF digital descargable' }, { label: 'Nivel', valor: 'Principiante / Intermedio' }, { label: 'Precio', valor: '$0 (Gratis)' } ], descripcion: 'Un hermoso patrón para tejer tu propio pareo calado paso a paso con explicaciones detalladas y fotos guía.' }, 'gratis-cuellito': { nombre: 'PATRÓN CUELLITO', precio: '$0 (GRATIS)', stock: 'Descarga gratuita inmediata', fotos: ['bufanda-capucha-abrazo-portada.jpg', 'bufanda-capucha-abrazo.jpg'], especificaciones: [ { label: 'Formato', valor: 'PDF digital descargable' }, { label: 'Nivel', valor: 'Fácil / Rápido de tejer' }, { label: 'Precio', valor: '$0 (Gratis)' } ], descripcion: 'Un patrón express super abrigado y fácil para tejer un cuellito acogedor en tus tardes de tejido.' } }; const modalOverlay = document.getElementById('modal-producto-overlay'); const btnCerrarModal = document.getElementById('btn-cerrar-modal'); const modalFotoPrincipal = document.getElementById('modal-foto-principal'); const modalMiniaturas = document.getElementById('modal-miniaturas'); const modalNombre = document.getElementById('modal-nombre'); const modalPrecio = document.getElementById('modal-precio'); const modalStock = document.getElementById('modal-stock'); const modalEspecificaciones = document.getElementById('modal-especificaciones'); const modalDescripcion = document.getElementById('modal-descripcion'); const inputCantidad = document.getElementById('modal-input-cantidad'); const btnMenosCant = document.getElementById('btn-menos-cant'); const btnMasCant = document.getElementById('btn-mas-cant'); const btnComprarAhora = document.getElementById('btn-comprar-ahora'); const btnModalAgregarCarrito = document.getElementById('btn-modal-agregar-carrito'); let prodSeleccionado = null; let prodIdSeleccionado = null; function abrirModal(id) { const data = PRODUCTOS_GRATIS_DATA[id]; if (!data) return; prodSeleccionado = data; prodIdSeleccionado = id; inputCantidad.value = 1; modalNombre.textContent = data.nombre; modalPrecio.textContent = data.precio; modalStock.textContent = data.stock; modalDescripcion.textContent = data.descripcion; modalEspecificaciones.innerHTML = data.especificaciones.map(s => `
  • ${s.label}: ${s.valor}
  • `).join(''); modalFotoPrincipal.src = data.fotos[0]; modalMiniaturas.innerHTML = ''; data.fotos.forEach((f, idx) => { const item = document.createElement('div'); item.className = `miniatura-item ${idx === 0 ? 'activo' : ''}`; const img = document.createElement('img'); img.src = f; item.appendChild(img); item.addEventListener('click', () => { document.querySelectorAll('.miniatura-item').forEach(m => m.classList.remove('activo')); item.classList.add('activo'); modalFotoPrincipal.src = f; }); modalMiniaturas.appendChild(item); }); modalOverlay.classList.add('activo'); document.body.style.overflow = 'hidden'; } function cerrarModal() { modalOverlay.classList.remove('activo'); document.body.style.overflow = ''; } btnCerrarModal.addEventListener('click', cerrarModal); modalOverlay.addEventListener('click', (e) => { if (e.target === modalOverlay) cerrarModal(); }); btnMenosCant.addEventListener('click', () => { let val = parseInt(inputCantidad.value) || 1; if (val > 1) inputCantidad.value = val - 1; }); btnMasCant.addEventListener('click', () => { let val = parseInt(inputCantidad.value) || 1; inputCantidad.value = val + 1; }); document.querySelectorAll('.tarjeta-producto').forEach(tarjeta => { const id = tarjeta.getAttribute('data-id'); const enlaces = tarjeta.querySelectorAll('.enlace-detalle-producto, .contenedor-imagen img'); enlaces.forEach(enlace => { enlace.addEventListener('click', (e) => { e.preventDefault(); abrirModal(id); }); }); }); btnModalAgregarCarrito.addEventListener('click', (e) => { const cant = parseInt(inputCantidad.value) || 1; if (window.agregarAlCarrito) { window.agregarAlCarrito(prodIdSeleccionado, prodSeleccionado.nombre, cant, e.currentTarget); } cerrarModal(); }); btnComprarAhora.addEventListener('click', (e) => { const cant = parseInt(inputCantidad.value) || 1; if (window.iniciarCompraProducto) { window.iniciarCompraProducto(prodIdSeleccionado, prodSeleccionado.nombre, cant); } else if (window.agregarAlCarrito) { window.agregarAlCarrito(prodIdSeleccionado, prodSeleccionado.nombre, cant, e.currentTarget); if (window.puroCrochetCart) window.puroCrochetCart.openCartDrawer(); } cerrarModal(); }); document.querySelectorAll('.boton-agregar-rapido').forEach((boton) => { boton.addEventListener('click', (e) => { e.stopPropagation(); const tarjeta = boton.closest('.tarjeta-producto'); const nombre = tarjeta.querySelector('.nombre-producto').textContent.trim(); if (window.agregarAlCarrito) { window.agregarAlCarrito(tarjeta.dataset.id, nombre, 1, boton); } }); }); document.querySelectorAll('.boton-favorito').forEach(btn => { btn.addEventListener('click', (e) => { e.stopPropagation(); btn.classList.toggle('activo'); }); });