+s.precio+'').join('')}
`, servicio:`

${params?.id?'Editar':'Nuevo'} Operación/Servicio

`, walkin:`

Paciente sin cita (Walk-in)

` }; m.innerHTML='';document.body.appendChild(m); } async function savePac(){ const r=await api('POST','/pacientes',{nombre:document.getElementById('m-nom').value,apellidos:document.getElementById('m-ape').value,telefono:document.getElementById('m-tel').value,sexo:document.getElementById('m-sexo').value}); if(r&&r.id){document.querySelector('.modal-bg').remove();navigate('pacientes');} } async function saveCita(){ const r=await api('POST','/citas',{paciente_id:document.getElementById('m-pac').value,fecha:document.getElementById('m-fecha').value,hora:document.getElementById('m-hora').value,motivo:document.getElementById('m-mot').value,podologo:document.getElementById('m-pod').value,estado:'Pendiente'}); if(r&&r.id){document.querySelector('.modal-bg').remove();await loadAg();} } async function updateCita(id){ const r=await api('PUT','/citas/'+id,{fecha:document.getElementById('m-fecha').value,hora:document.getElementById('m-hora').value,motivo:document.getElementById('m-mot').value,podologo:document.getElementById('m-pod').value,estado:'Pendiente'}); if(r&&r.id){document.querySelector('.modal-bg').remove();await loadAg();} } async function saveWalkin(){ let pacId=document.getElementById('wk-pac').value; if(window._wNew){ const np=await api('POST','/pacientes',{nombre:document.getElementById('wk-nom').value,apellidos:document.getElementById('wk-ape').value,telefono:document.getElementById('wk-tel').value,sexo:'M'}); if(np&&np.id) pacId=np.id; else return; } const c=await api('POST','/citas',{paciente_id:pacId,fecha:today(),hora:new Date().toTimeString().substring(0,5),motivo:document.getElementById('wk-mot').value,podologo:document.getElementById('wk-pod').value,estado:'Confirmada'}); if(c&&c.id){await api('POST','/citas/'+c.id+'/llegada');document.querySelector('.modal-bg').remove();await loadAg();} } (async()=>{ if(S.token){const me=await api('GET','/auth/me');if(me&&me.id){S.user=me;renderApp();if(!S.user.username||S.user.username==='')setTimeout(showUsernamePopup,800);return;}} renderLogin(); })();