document.addEventListener('DOMContentLoaded', function() { // DOM Elements const spreadsheetInput = document.getElementById('spreadsheet'); const inputTypeSelect = document.getElementById('inputType'); const manualInput = document.getElementById('manualInput'); const processBtn = document.getElementById('processBtn'); const dataPreview = document.getElementById('dataPreview'); const exportBtn = document.getElementById('exportBtn'); const reportBtn = document.getElementById('reportBtn'); const formulaDisplay = document.getElementById('formulaDisplay'); // Event Listeners inputTypeSelect.addEventListener('change', toggleInputType); processBtn.addEventListener('click', processData); exportBtn.addEventListener('click', exportData); reportBtn.addEventListener('click', generateReport); // Initialize toggleInputType(); feather.replace(); // Functions function toggleInputType() { const inputType = inputTypeSelect.value; if (inputType === 'text') { manualInput.placeholder = "Insira os valores (um por linha)\nExemplo:\nvalor1\nvalor2\nvalor3"; } else { manualInput.placeholder = "Insira os valores separados por |\nExemplo:\nvalor1|valor2|valor3\nvalor4|valor5|valor6"; } } function processData() { // Show processing state processBtn.disabled = true; processBtn.innerHTML = ' Processando...'; feather.replace(); // Simulate processing delay setTimeout(() => { // Process data based on input type const inputType = inputTypeSelect.value; let data = []; if (inputType === 'text') { data = manualInput.value.split('\n').filter(item => item.trim() !== ''); } else { data = manualInput.value.split('\n') .filter(row => row.trim() !== '') .map(row => row.split('|').map(item => item.trim())); } // Display preview displayDataPreview(data); // Display sample formulas displayFormulas(data); // Reset button processBtn.disabled = false; processBtn.innerHTML = ' Processar Dados'; feather.replace(); }, 1500); } function displayDataPreview(data) { if (Array.isArray(data[0])) { // Tabular data let tableHTML = ''; // Create headers (assuming first row has all columns) for (let i = 0; i < data[0].length; i++) { tableHTML += ``; } tableHTML += ''; // Add rows data.forEach(row => { tableHTML += ''; row.forEach(cell => { tableHTML += ``; }); tableHTML += ''; }); tableHTML += '
Coluna ${i+1}
${cell}
'; dataPreview.innerHTML = tableHTML; } else { // Simple list let listHTML = ''; dataPreview.innerHTML = listHTML; } } function displayFormulas(data) { formulaDisplay.innerHTML = `

Fórmulas Aplicadas:

* As fórmulas serão calculadas automaticamente conforme os dados são processados.

`; } function exportData() { alert('Funcionalidade de exportação será implementada aqui. Os dados serão exportados no formato selecionado.'); } function generateReport() { alert('Relatório gerado com sucesso! Esta funcionalidade criará um PDF/Excel com os dados processados e cálculos aplicados.'); } // Handle spreadsheet file upload spreadsheetInput.addEventListener('change', function(e) { const file = e.target.files[0]; if (file) { alert(`Planilha "${file.name}" selecionada. O processamento de arquivos será implementado aqui.`); // In a real app, you would use a library like SheetJS to read the file } }); });