';
var a=document.createElement('button');a.type='button';a.className='btn';a.textContent='Próximo disponible: '+fmt(d.date)+' →';
a.addEventListener('click',function(){sel.date=d.date;if(dateEl)dateEl.value=d.date;renderSlots(d.slots);});
slotsEl.appendChild(a);
} else { slotsEl.innerHTML='No hay disponibilidad en las próximas semanas — por favor, contáctanos.'; }
}).catch(function(){slotsEl.innerHTML='No hay horarios disponibles en esa fecha — prueba otra.';});
}
function loadDate(ymd){
sel.date=ymd; sel.time=''; slotsEl.innerHTML='Cargando...';
fetch(availUrl+'?'+q('&date='+encodeURIComponent(ymd))).then(function(r){return r.json();}).then(function(d){
var slots=(d&&d.slots&&typeof d.slots==='object'&&!Array.isArray(d.slots))?d.slots:{};
if(!Object.keys(slots).length){offerNext(ymd);return;}
renderSlots(slots);
}).catch(function(){slotsEl.innerHTML='No se pudieron cargar los horarios.';});
}
function startDate(){
show('date');
slotsEl.innerHTML='Buscando horarios disponibles...';
fetch(nextUrl+'?'+q()).then(function(r){return r.json();}).then(function(d){
if(d&&d.date){sel.date=d.date;if(dateEl)dateEl.value=d.date;renderSlots(d.slots);}
else{slotsEl.innerHTML='No hay disponibilidad en las próximas semanas — por favor, contáctanos.';}
}).catch(function(){if(dateEl&&dateEl.value)loadDate(dateEl.value);});
}
function loadStaff(){
show('staff'); if(!staffEl)return; staffEl.innerHTML='Cargando...';
fetch(staffUrl+'?service='+encodeURIComponent(sel.service)+'&location='+encodeURIComponent(sel.location||0)).then(function(r){return r.json();}).then(function(list){
staffEl.innerHTML='';
var any=document.createElement('button');any.type='button';any.className='opt';any.innerHTML='Cualquier disponible
'+p.name+'';
b.addEventListener('click',function(){sel.provider=p.id;startDate();});staffEl.appendChild(b);});
if(!list||!list.length){var n=document.createElement('div');n.className='none';n.textContent='Ningún miembro del equipo lo ofrece aún.';staffEl.appendChild(n);}
}).catch(function(){staffEl.innerHTML='No se pudo cargar el equipo.';});
}
function afterService(){ sel.provider=0; if(chooseStaff)loadStaff(); else startDate(); }
root.querySelectorAll('.loc[data-id]').forEach(function(b){b.addEventListener('click',function(){
root.querySelectorAll('.loc').forEach(function(x){x.classList.remove('sel');});b.classList.add('sel');
sel.location=parseInt(b.getAttribute('data-id'),10)||0; root.querySelector('#f-location').value=sel.location; show('service');
});});
root.querySelectorAll('.svc[data-id]').forEach(function(b){b.addEventListener('click',function(){
root.querySelectorAll('.svc').forEach(function(x){x.classList.remove('sel');});b.classList.add('sel');
sel.service=b.getAttribute('data-id');sel.name=b.getAttribute('data-name');
root.querySelector('#f-service').value=sel.service; afterService();
});});
dateEl&&dateEl.addEventListener('change',function(){loadDate(dateEl.value);});
root.querySelectorAll('[data-back]').forEach(function(b){b.addEventListener('click',prev);});
var pre=root.querySelector('.svc[data-pre]'); if(pre&&steps[0]==='service')pre.click();
})();';});
}
function afterService(){ sel.provider=0; if(chooseStaff)loadStaff(); else startDate(); }
root.querySelectorAll('.loc[data-id]').forEach(function(b){b.addEventListener('click',function(){
root.querySelectorAll('.loc').forEach(function(x){x.classList.remove('sel');});b.classList.add('sel');
sel.location=parseInt(b.getAttribute('data-id'),10)||0; root.querySelector('#f-location').value=sel.location; show('service');
});});
root.querySelectorAll('.svc[data-id]').forEach(function(b){b.addEventListener('click',function(){
root.querySelectorAll('.svc').forEach(function(x){x.classList.remove('sel');});b.classList.add('sel');
sel.service=b.getAttribute('data-id');sel.name=b.getAttribute('data-name');
root.querySelector('#f-service').value=sel.service; afterService();
});});
dateEl&&dateEl.addEventListener('change',function(){loadDate(dateEl.value);});
root.querySelectorAll('[data-back]').forEach(function(b){b.addEventListener('click',prev);});
var pre=root.querySelector('.svc[data-pre]'); if(pre&&steps[0]==='service')pre.click();
})();
Valoramos tu privacidadUtilizamos cookies para mejorar tu experiencia. Puedes aceptar todas, rechazar las no esenciales, o elegir qué categorías permitir. Las cookies esenciales siempre están activadas.
Preferencias de cookies
EsencialRequerido para que el sitio funcione. Siempre activo.
AnalíticaAyúdanos a entender cómo los visitantes usan el sitio (por ejemplo, Google Analytics).
MarketingUtilizado para medir y orientar la publicidad (por ejemplo, Meta Pixel, Google Ads).
Accesibilidad
Ajusta este sitio a tu gusto. Tus elecciones se recuerdan en este dispositivo.