const listView = document.getElementById('list-view'); const observationView = document.getElementById('obs-view'); const encaminharView = document.getElementById('encaminhar-view'); const itemList = document.getElementById('item-list'); const nextButton = document.getElementById('next-button'); const logoutButton = document.getElementById('logout-button'); const observationText = document.getElementById('observation-text'); const encObservationText = document.getElementById('enc-observation-text'); const saveButton = document.getElementById('save-button'); const selectedItemNameSpan = document.getElementById('selected-item-name'); const queueNumber = document.getElementById('queue-number'); const idAtend = document.getElementById('idAtend'); const counterStart = document.getElementById('counter-start'); let currentData = []; let selectedItemId = null; let selectedItemName = ''; window.electronAPI.onLoadData((data) => { if(!data){ return; } // Reseta a view para a lista sempre que os dados são carregados populateList(data[0]); }); async function initializePusher() { if (typeof window.electronAPI === 'undefined' || !window.electronAPI.getPusherConfig) { console.error('electronAPI not available or getPusherConfig method missing.'); return; } const pusherConfig = await window.electronAPI.getPusherConfig(); const PUSHER_APP_KEY = pusherConfig.appKey; let host = pusherConfig.host; const channelLocal = localStorage.getItem('channel'); const colabId = localStorage.getItem('idOperator'); if (channelLocal && PUSHER_APP_KEY) { Pusher.logToConsole = true; var pusher = new Pusher(PUSHER_APP_KEY, { wsHost: host, wsPort: 6001, wssPort: 6001, forceTLS: false, enableStats: false, enabledTransports: ['ws','wss'], cluster: 'mt1' }); var channel = pusher.subscribe('chat.' + channelLocal + '_' + colabId); channel.bind('message-sent', function(r) { let count = r.data.fila.original.length; console.log(r.data.fila.original); localStorage.setItem('proximos',JSON.stringify(r.data.fila.original)); populateList(r.data.currentData.original); }); pusher.connection.bind('error', function(err) { console.error('Pusher connection error:', err); }); console.log('Host de conexão:', host); } else { console.warn('User not authenticated or Pusher APP_KEY not available. Private channel not subscribed.'); } } initializePusher(); //chama o proximo da fila ao abrir a janela de atendimentos window.electronAPI.selectAtendID((data)=>{ if(!data){ queueNumber.innerHTML = 'Ninguem aguardando atendimento, fechando a janela em alguns segundos...'; setTimeout(() => { window.close(); },5000); return; } // Reseta a view para a lista sempre que os dados são carregados ao clicar no botão para abrir a janela populateList(data); showListView(); selectedItemId = data.id ?? null; //data.senhaGen queueNumber.innerHTML = data ? `NA VEZ: ${data.clientName.toUpperCase()} - ${data.descricaoServico.toUpperCase()}` : 'Ninguem aguardando atendimento'; selectedItemNameSpan.innerHTML = data ? ` ${data.clientName.toUpperCase()} [ ${data.senhaGen} ]` : 'Ninguem aguardando atendimento'; }); // Função para popular a lista de itens function populateList(currentData) { let datastorage = localStorage.getItem('proximos'); nextButton.disabled = true; // Adiciona os outros itens apenas para visualização (opcional) const proximos = JSON.parse(datastorage); var count = 5; itemList.innerHTML = ''; // Limpa a lista anterior if (!proximos || proximos.length === 0 || !currentData) { itemList.innerHTML = '