Przejdź do treści

Choose a service

Pick a date & time

Finding available times…

Your details

'; var a=document.createElement('button');a.type='button';a.className='btn';a.textContent='Next available: '+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 availability in the coming weeks — please get in touch.'; } }).catch(function(){slotsEl.innerHTML='No times available on that date — try another.';}); } function loadDate(ymd){ sel.date=ymd; sel.time=''; slotsEl.innerHTML='Loading…'; 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='Could not load times.';}); } function startDate(){ show('date'); slotsEl.innerHTML='Finding available times…'; 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 availability in the coming weeks — please get in touch.';} }).catch(function(){if(dateEl&&dateEl.value)loadDate(dateEl.value);}); } function loadStaff(){ show('staff'); if(!staffEl)return; staffEl.innerHTML='Loading…'; 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='Any available
First free appointment
'; any.addEventListener('click',function(){sel.provider=0;startDate();});staffEl.appendChild(any); (list||[]).forEach(function(p){var b=document.createElement('button');b.type='button';b.className='opt';b.innerHTML=''+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='No team members offer this yet.';staffEl.appendChild(n);} }).catch(function(){staffEl.innerHTML='Could not load team.';}); } 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(); })();