/* Pegar SOLO el contenido de este archivo entre en Flatsome > Settings > Custom Code > Footer. */
(function () {
'use strict';
function iniciarBonos() {
var zona = document.getElementById('baby-gifts');
if (!zona) return;
var botones = zona.querySelectorAll('[data-select-bono]');
var formulario = document.getElementById('wpforms-form-1183');
var selectBono = formulario ? formulario.querySelector('.baby-bono-field select') : null;
var montoPrevia = document.getElementById('baby-voucher-value');
var nota = document.getElementById('baby-selected-note');
var etiqueta = document.getElementById('baby-selected-label');
botones.forEach(function (boton) {
boton.addEventListener('click', function (ev) {
ev.preventDefault();
var bono = boton.getAttribute('data-select-bono');
var monto = boton.getAttribute('data-amount');
botones.forEach(function (b) { b.closest('.baby-gift-card').classList.remove('is-chosen'); });
boton.closest('.baby-gift-card').classList.add('is-chosen');
if (montoPrevia) montoPrevia.textContent = 'Bono de ' + monto;
if (nota && etiqueta) { etiqueta.textContent = bono; nota.hidden = false; }
// Funciona con campo WPForms de tipo Desplegable, estilo Clásico.
// El campo debe tener la clase CSS adicional "baby-bono-field".
if (selectBono) {
Array.prototype.slice.call(selectBono.options).forEach(function (opcion) {
if (opcion.text.trim() === bono) selectBono.value = opcion.value;
});
selectBono.dispatchEvent(new Event('change', { bubbles: true }));
}
var destino = document.getElementById('bono-formulario');
if (destino) destino.scrollIntoView({ behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth', block: 'start' });
});
});
var copiar = document.getElementById('baby-copy-nequi');
var estado = document.getElementById('baby-copy-status');
if (copiar) {
copiar.addEventListener('click', function () {
if (!navigator.clipboard || !navigator.clipboard.writeText) {
if (estado) estado.textContent = 'Selecciona el número de Nequi para copiarlo manualmente.';
return;
}
navigator.clipboard.writeText('3138583255').then(function () {
if (estado) estado.textContent = '¡Número copiado! Ya puedes pegarlo en Nequi.';
}).catch(function () {
if (estado) estado.textContent = 'No fue posible copiarlo automáticamente. Copia 3138583255.';
});
});
}
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', iniciarBonos);
else iniciarBonos();
})();