diff --git a/servicios.html b/servicios.html
index 83e719a..ee81af2 100644
--- a/servicios.html
+++ b/servicios.html
@@ -142,6 +142,13 @@
+
+
+
+ Este cliente ya tiene direcciones guardadas. Puedes usar la actual o escribir una nueva.
+
+
+
@@ -383,6 +390,40 @@
+
+
+ // --- FUNCIÓN PARA BUSCAR CLIENTE POR TELÉFONO AL ESCRIBIR ---
+async function searchClientByPhone(phone) {
+ if (phone.length < 9) {
+ document.getElementById('addrSuggestions').classList.add('hidden');
+ return;
+ }
+ try {
+ const res = await fetch(`${API_URL}/clients/search?phone=${phone}`, {
+ headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
+ });
+ const data = await res.json();
+
+ if (data.ok && data.client) {
+ // Rellenar nombre si está vacío
+ const nameInput = document.getElementById('nName');
+ if (!nameInput.value) {
+ nameInput.value = data.client.full_name;
+ nameInput.classList.add('bg-emerald-50'); // Efecto visual de éxito
+ }
+
+ // Mostrar aviso de direcciones si existen
+ const addrDiv = document.getElementById('addrSuggestions');
+ if (data.client.addresses && data.client.addresses.length > 0) {
+ addrDiv.classList.remove('hidden');
+ // Si el campo de dirección está vacío, ponemos la primera que tengamos
+ if (!document.getElementById('nAddr').value) {
+ document.getElementById('nAddr').value = data.client.addresses[0];
+ }
+ }
+ }
+ } catch (e) { console.error("Error en buscador rápido:", e); }
+}