diff --git a/index.html b/index.html index a3601e9..bb4ba60 100644 --- a/index.html +++ b/index.html @@ -113,17 +113,34 @@ } function summarizeDescription(rawText) { - if (!rawText) return "Avería reportada."; - let text = rawText.replace(/\n/g, ' '); - const regexCorte = /(\(|\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bURGENTE\b)/i; + if (!rawText) return "Revisión técnica de avería en el domicilio."; + + // 1. Quitar saltos de línea + let text = String(rawText).replace(/(\r\n|\n|\r)/gm, " "); + + // 2. Cortar basura interna de las aseguradoras (M.O., MATERIALES, teléfonos, código de propuesta, etc.) + const regexCorte = /(\bM\.O\b|\bMATERIAL\b|\bASEGURADO\b|\bTELEFONO\b|\bTEL\b|\bURGENTE\b|\bFRANQUICIA\b|\[PROPUESTA)/i; let cutPos = text.search(regexCorte); - if (cutPos > 5) text = text.substring(0, cutPos); + if (cutPos > 15) text = text.substring(0, cutPos); + + // 3. Limpiar prefijos inútiles que no aportan nada al cliente + text = text.replace(/^(Aver[ií]a|Descripci[oó]n|Motivo|Siniestro|Detalle)[\s:]*/i, ''); + text = text.trim(); - text = text.charAt(0).toUpperCase() + text.slice(1).toLowerCase(); + + // 4. Capitalizar solo la primera letra (sin destrozar el resto de mayúsculas como hacía antes) + if (text.length > 0) { + text = text.charAt(0).toUpperCase() + text.slice(1); + } + + // 5. Límite elástico y elegante (25 palabras máximo, para que se lea un buen trozo sin saturar) let words = text.split(/\s+/); - if (words.length > 10) return words.slice(0, 10).join(" ") + "..."; - if (text.length < 5) return "Reparación general solicitada."; - return text.endsWith('.') ? text : text + "."; + if (words.length > 25) { + text = words.slice(0, 25).join(" ") + "..."; + } + + if (text.length < 5) return "Revisión general en el domicilio."; + return text.endsWith('.') || text.endsWith('...') ? text : text + "."; } function addOneHour(timeStr) { @@ -434,8 +451,10 @@ ${contactHtml} ${clientDataHtml}
-

Motivo de la Visita

-

${descLimpia}

+

+ Motivo de la Visita +

+

${descLimpia}

`;