diff --git a/public/js/views/ticketDetail.js b/public/js/views/ticketDetail.js
index 2f2e453..cfc433e 100644
--- a/public/js/views/ticketDetail.js
+++ b/public/js/views/ticketDetail.js
@@ -3565,6 +3565,131 @@ const TicketDetailView = {
});
}
+ // Queue Search Autocomplete
+ const queueSuggestionsDiv = document.getElementById('qe-queue-suggestions');
+ let queueDebounce;
+
+ if (queueSearchInput && queueSuggestionsDiv) {
+ queueSearchInput.addEventListener('input', () => {
+ clearTimeout(queueDebounce);
+ const q = queueSearchInput.value.trim();
+ if (queueIdInput) queueIdInput.value = '';
+ checkChanges();
+
+ queueDebounce = setTimeout(async () => {
+ try {
+ const queues = await App.api(`/api/queues/search?q=${encodeURIComponent(q)}`);
+ if (!queues || queues.length === 0) {
+ queueSuggestionsDiv.innerHTML = '
Nessuna coda trovata
';
+ queueSuggestionsDiv.style.display = 'block';
+ return;
+ }
+
+ queueSuggestionsDiv.innerHTML = queues.map(qObj => {
+ const displayName = qObj.name.replace(/::/g, ' › ');
+ return `
+
+ ${App.escapeHtml(displayName)}
+
+ `;
+ }).join('');
+ queueSuggestionsDiv.style.display = 'block';
+
+ queueSuggestionsDiv.querySelectorAll('.autocomplete-suggestion-item').forEach(item => {
+ if (item.dataset.id) {
+ item.addEventListener('mousedown', (e) => {
+ e.preventDefault();
+ queueSearchInput.value = item.dataset.name;
+ if (queueIdInput) queueIdInput.value = item.dataset.id;
+ queueSuggestionsDiv.style.display = 'none';
+ checkChanges();
+ });
+ }
+ });
+ } catch (err) {
+ console.error('Queue search error:', err);
+ }
+ }, 150);
+ });
+
+ if (App.setupAutocompleteKeyboardNavigation) {
+ App.setupAutocompleteKeyboardNavigation(queueSearchInput, queueSuggestionsDiv, (item) => {
+ if (item && item.dataset.id) {
+ queueSearchInput.value = item.dataset.name;
+ if (queueIdInput) queueIdInput.value = item.dataset.id;
+ queueSuggestionsDiv.style.display = 'none';
+ checkChanges();
+ }
+ });
+ }
+
+ queueSearchInput.addEventListener('focus', () => {
+ queueSearchInput.dispatchEvent(new Event('input'));
+ });
+ }
+
+ // Customer Search Autocomplete
+ const customerSuggestionsDiv = document.getElementById('qe-customer-suggestions');
+ let customerDebounce;
+
+ if (customerSearchInput && customerSuggestionsDiv) {
+ customerSearchInput.addEventListener('input', () => {
+ clearTimeout(customerDebounce);
+ const q = customerSearchInput.value.trim();
+ if (customerUserIdInput) customerUserIdInput.value = '';
+ if (customerIdInput) customerIdInput.value = '';
+ checkChanges();
+
+ customerDebounce = setTimeout(async () => {
+ try {
+ const customers = await App.api(`/api/customers/search?q=${encodeURIComponent(q)}`);
+ if (!customers || customers.length === 0) {
+ customerSuggestionsDiv.innerHTML = 'Nessun cliente trovato
';
+ customerSuggestionsDiv.style.display = 'block';
+ return;
+ }
+
+ customerSuggestionsDiv.innerHTML = customers.map(c => `
+
+ ${App.escapeHtml(c.first_name ? `${c.first_name} ${c.last_name}` : c.customer_user_id)}
+ ${c.email ? `(${App.escapeHtml(c.email)})` : ''}
+
+ `).join('');
+ customerSuggestionsDiv.style.display = 'block';
+
+ customerSuggestionsDiv.querySelectorAll('.autocomplete-suggestion-item').forEach(item => {
+ if (item.dataset.userId) {
+ item.addEventListener('mousedown', (e) => {
+ e.preventDefault();
+ customerSearchInput.value = item.dataset.name;
+ if (customerUserIdInput) customerUserIdInput.value = item.dataset.userId;
+ if (customerIdInput) customerIdInput.value = item.dataset.customerId;
+ customerSuggestionsDiv.style.display = 'none';
+ checkChanges();
+ });
+ }
+ });
+ } catch (err) {
+ console.error('Customer search error:', err);
+ }
+ }, 150);
+ });
+
+ customerSearchInput.addEventListener('focus', () => {
+ customerSearchInput.dispatchEvent(new Event('input'));
+ });
+ }
+
+ // Close suggestions on click outside
+ document.addEventListener('click', (e) => {
+ if (queueSearchInput && queueSuggestionsDiv && e.target !== queueSearchInput && !queueSuggestionsDiv.contains(e.target)) {
+ queueSuggestionsDiv.style.display = 'none';
+ }
+ if (customerSearchInput && customerSuggestionsDiv && e.target !== customerSearchInput && !customerSuggestionsDiv.contains(e.target)) {
+ customerSuggestionsDiv.style.display = 'none';
+ }
+ });
+
// Unified Save Quick Edit & Send Note action
if (saveBtn) {
saveBtn.addEventListener('click', async () => {