diff --git a/modules/turnero/views/chat.php b/modules/turnero/views/chat.php
index cf7e389..37e2e38 100644
--- a/modules/turnero/views/chat.php
+++ b/modules/turnero/views/chat.php
@@ -1038,6 +1038,7 @@ function cancelRecording() {
const nuevoMensaje = (() => {
let _phone = '';
let _destLabel = '';
+ let _patientName = '';
let _tpl = null;
let _buscarTimer = null;
@@ -1048,7 +1049,7 @@ const nuevoMensaje = (() => {
}
function abrir() {
- _phone = ''; _destLabel = ''; _tpl = null;
+ _phone = ''; _destLabel = ''; _patientName = ''; _tpl = null;
document.getElementById('nv-pac-search').value = '';
document.getElementById('nv-phone-input').value = '';
document.getElementById('nv-phone-hint').textContent = '';
@@ -1082,6 +1083,7 @@ const nuevoMensaje = (() => {
_setDest('', '');
}
// Clear patient selection if typing a phone
+ _patientName = '';
document.getElementById('nv-pac-search').value = '';
document.getElementById('nv-pac-results').innerHTML = '';
}
@@ -1113,6 +1115,7 @@ const nuevoMensaje = (() => {
div.onclick = () => {
const phone = (p.telefono || '').replace(/\D/g,'');
if (!phone) { alert('Este paciente no tiene teléfono registrado.'); return; }
+ _patientName = p.nombre_completo;
_setDest(phone, p.nombre_completo + ' · ' + tel);
document.getElementById('nv-pac-search').value = p.nombre_completo;
el.innerHTML = '';
@@ -1177,8 +1180,10 @@ const nuevoMensaje = (() => {
const row = document.createElement('div');
row.className = 'tpl-var-row';
const ph = v.example || v.placeholder || v.label;
+ const varName = (v.placeholder || '').replace(/\{\{|\}\}/g, '').trim();
+ const autoVal = (varName === 'name' && _patientName) ? _patientName : '';
row.innerHTML = `` +
- ``;
+ ``;
varsBody.appendChild(row);
});
}