diff --git a/automatizaciones.html b/automatizaciones.html
index 48eedb0..67fd97f 100644
--- a/automatizaciones.html
+++ b/automatizaciones.html
@@ -285,38 +285,50 @@
}
function openEditor(id) {
- const svc = scrapedData.find(s => s.id === id);
- if(!svc) return;
- const raw = svc.raw_data;
- const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
-
- document.getElementById('modalCompanyLogo').innerHTML = `
`;
- document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
- document.getElementById('displayCompany').innerText = companyName;
- document.getElementById('modalStatusBadge').innerHTML = `SERVICIO ACTIVO`;
+ const svc = scrapedData.find(s => s.id === id);
+ if(!svc) return;
+ const raw = svc.raw_data;
+ const companyName = raw['Compañía'] || raw['COMPAÑIA'] || raw['Procedencia'] || "";
+
+ document.getElementById('modalCompanyLogo').innerHTML = `
`;
+ document.getElementById('displayRef').innerText = `REF: ${svc.service_ref}`;
+ document.getElementById('displayCompany').innerText = companyName;
+ document.getElementById('modalStatusBadge').innerHTML = `SERVICIO ACTIVO`;
- document.getElementById('impScrapedId').value = id;
- document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
- const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
- document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
- const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
- const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
- document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
- document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
- document.getElementById('impDesc').value = raw['Descripción'] || "";
-
- const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
- document.getElementById('impUrgent').value = isUrgent.toString();
-
- document.getElementById('impNotesInt').value = "";
- document.getElementById('impNotesExt').value = "";
- document.getElementById('impGuild').value = "";
- document.getElementById('impOperator').innerHTML = '';
-
- document.getElementById('importModal').classList.remove('hidden');
- lucide.createIcons();
- }
+ document.getElementById('impScrapedId').value = id;
+ document.getElementById('impName').value = raw['Nombre Cliente'] || raw['CLIENTE'] || "S/N";
+
+ const rawPhone = raw['Teléfono'] || raw['TELEFONOS'] || raw['TELEFONO'] || "";
+ document.getElementById('impPhone').value = rawPhone.match(/[6789]\d{8}/)?.[0] || "";
+
+ const addr = raw['Dirección'] || raw['DOMICILIO'] || "";
+ const pop = raw['Población'] || raw['POBLACION-PROVINCIA'] || "";
+ document.getElementById('impAddress').value = `${addr} ${pop}`.trim();
+ document.getElementById('impCP').value = raw['Código Postal'] || raw['C.P.'] || "";
+ document.getElementById('impDesc').value = raw['Descripción'] || "";
+
+ const isUrgent = raw['Urgente'] === 'Sí' || raw['Urgente'] === 'true' || raw['URGENTE'] === 'SI';
+ document.getElementById('impUrgent').value = isUrgent.toString();
+
+ // RECUPERACIÓN DE DATOS GUARDADOS PREVIAMENTE
+ document.getElementById('impNotesInt').value = raw['internal_notes'] || "";
+ document.getElementById('impNotesExt').value = raw['client_notes'] || "";
+
+ // Cargar Gremio y disparar carga de operarios si ya existía
+ const savedGuild = raw['guild_id'] || "";
+ document.getElementById('impGuild').value = savedGuild;
+
+ if(savedGuild) {
+ loadOpsForGuild(savedGuild).then(() => {
+ document.getElementById('impOperator').value = raw['assigned_to'] || "";
+ });
+ } else {
+ document.getElementById('impOperator').innerHTML = '';
+ }
+ document.getElementById('importModal').classList.remove('hidden');
+ lucide.createIcons();
+}
function closeModal() { document.getElementById('importModal').classList.add('hidden'); }
async function saveDraftChanges(e) {