Portail d'Administration
Aucune conversation.
';
} else {
list.innerHTML = '';
chats.forEach(c => {
if (c.unread_admin) unreadTotal++;
const isSelected = currentAdminChatClient === c.client_id;
const bg = isSelected ? '#f3f4f6' : 'white';
const weight = c.unread_admin ? '700' : '500';
const color = c.unread_admin ? '#111827' : '#6b7280';
const div = document.createElement('div');
div.style.cssText = `padding: 16px 20px; border-bottom: 1px solid #f3f4f6; cursor: pointer; background: ${bg}; transition: background 0.2s;`;
div.onclick = () => adminOpenChat(c.client_id, c.client_name);
const dot = c.unread_admin ? '' : '';
let name = c.client_name;
if (name.startsWith('guest_')) name = 'Visiteur ' + name.substr(6, 4).toUpperCase();
div.innerHTML = `
${name}
${dot}
${name.substring(0, 2).toUpperCase()}
${name}
Client / Prospect
Aucun message dans cette conversation.
';
} else {
messages.forEach(m => {
const isMe = m.sender === 'admin';
const align = isMe ? 'flex-end' : 'flex-start';
const bg = isMe ? '#5a4c95' : '#ffffff';
const color = isMe ? '#ffffff' : '#1f2937';
const border = isMe ? 'none' : '1px solid #d1d5db';
const br = isMe ? '16px 16px 0 16px' : '16px 16px 16px 0';
const div = document.createElement('div');
div.style.cssText = `align-self: ${align}; max-width: 75%; background:${bg}; color:${color}; padding:12px 16px; border-radius:${br}; border:${border}; font-size:14px; line-height:1.5; box-shadow:0 1px 2px rgba(0,0,0,0.05); word-break:break-word;`;
div.innerHTML = m.text.replace(//g, ">");
container.appendChild(div);
});
}
if (isScrolledToBottom) {
container.scrollTop = container.scrollHeight;
}
}
function adminSendChatMessage() {
if (!currentAdminChatClient) return;
const input = document.getElementById('admin-chat-input');
const msg = input.value.trim();
if (!msg) return;
input.value = '';
jQuery.post(fc_ajax_obj.ajax_url, {
action: 'fc_send_chat_message',
client_id: currentAdminChatClient,
message: msg,
sender: 'admin'
}, function(res) {
if(res.success) {
adminLoadChatMessages();
setTimeout(() => {
const container = document.getElementById('admin-chat-messages');
if(container) container.scrollTop = container.scrollHeight;
}, 100);
}
});
}