document.addEventListener('DOMContentLoaded', function() { const documentInput = document.getElementById('documentInput'); const frameworksInput = document.getElementById('frameworksInput'); const analyzeBtn = document.getElementById('analyzeBtn'); const analysisSection = document.getElementById('analysisSection'); const uploadedDocuments = document.getElementById('uploadedDocuments'); const documentsList = document.getElementById('documentsList'); let uploadedFiles = []; // Show documents section when files are selected documentInput.addEventListener('change', function() { if (this.files.length > 0) { uploadedFiles.push({ name: this.files[0].name, type: 'Documento', date: new Date().toLocaleString() }); updateDocumentsList(); uploadedDocuments.classList.remove('hidden'); } }); frameworksInput.addEventListener('change', function() { if (this.files.length > 0) { Array.from(this.files).forEach(file => { uploadedFiles.push({ name: file.name, type: 'Marco', date: new Date().toLocaleString() }); }); updateDocumentsList(); uploadedDocuments.classList.remove('hidden'); } }); function updateDocumentsList() { documentsList.innerHTML = ''; uploadedFiles.forEach((file, index) => { const row = document.createElement('tr'); row.className = 'hover:bg-gray-50'; row.innerHTML = `
${file.name}
${file.type} ${file.date} `; documentsList.appendChild(row); }); feather.replace(); } window.removeDocument = function(index) { uploadedFiles.splice(index, 1); updateDocumentsList(); if (uploadedFiles.length === 0) { uploadedDocuments.classList.add('hidden'); analysisSection.classList.add('hidden'); } }; window.viewDocument = function(index) { alert(`Visualizando documento: ${uploadedFiles[index].name}`); // In a real app, this would open a document viewer }; // Analyze button functionality analyzeBtn.addEventListener('click', function() { if (!documentInput.files[0] || !frameworksInput.files[0]) { alert('Por favor sube ambos: el documento a analizar y los marcos funcionales'); return; } // Simulate analysis (in a real app, this would call an API) simulateAnalysis(); }); function simulateAnalysis() { analyzeBtn.disabled = true; analyzeBtn.innerHTML = ' Analizando iniciativas...'; feather.replace(); // Simulate processing delay setTimeout(() => { // Generate mock initiatives analysis const initiatives = [ { name: 'Digitalización de procesos', pdiObjectives: ['OE1. Transformación digital', 'OE3. Eficiencia operativa'], cfirAspects: ['Intervención', 'Contexto interno'], match: 82, details: [ { aspect: 'Alineación con OE1', match: 90, comment: 'Excelente cobertura de objetivos de digitalización' }, { aspect: 'Alineación con OE3', match: 75, comment: 'Podría incluir más métricas de eficiencia' }, { aspect: 'CFIR: Intervención', match: 80, comment: 'Buen diseño de la intervención' }, { aspect: 'CFIR: Contexto interno', match: 65, comment: 'Necesita mayor análisis del contexto actual' } ] }, { name: 'Capacitación continua', pdiObjectives: ['OE2. Desarrollo de talento', 'OE4. Cultura organizacional'], cfirAspects: ['Características individuales', 'Proceso de implementación'], match: 78, details: [ { aspect: 'Alineación con OE2', match: 85, comment: 'Cubre bien los objetivos de desarrollo' }, { aspect: 'Alineación con OE4', match: 70, comment: 'Podría fortalecer aspectos culturales' }, { aspect: 'CFIR: Características individuales', match: 82, comment: 'Buena consideración de competencias' }, { aspect: 'CFIR: Proceso de implementación', match: 60, comment: 'Falta plan detallado de implementación' } ] } ]; const recommendations = [ 'Priorizar la iniciativa de digitalización por su alto alineamiento estratégico', 'Reforzar el análisis de contexto organizacional en todas las iniciativas', 'Establecer indicadores claros para medir impacto en cultura organizacional' ]; // Display initiatives analysis displayInitiativesAnalysis(initiatives, recommendations); analyzeBtn.disabled = false; analyzeBtn.innerHTML = ' Reanalizar'; feather.replace(); }, 3000); } function displayInitiativesAnalysis(initiatives, recommendations) { const pdiContainer = document.getElementById('pdiResults'); const cfirContainer = document.getElementById('cfirResults'); const recContainer = document.getElementById('recommendations'); // Clear previous results pdiContainer.innerHTML = ''; cfirContainer.innerHTML = ''; recContainer.innerHTML = ''; // Display initiatives analysis initiatives.forEach(initiative => { const initiativeCard = document.createElement('div'); initiativeCard.className = 'mb-6 p-4 bg-white border rounded-lg shadow-sm analysis-result'; initiativeCard.innerHTML = `

${initiative.name}

Alineamiento general: ${initiative.match}%
${initiative.pdiObjectives.length} objetivos PDI ${initiative.cfirAspects.length} aspectos CFIR

Objetivos PDI relacionados:

Aspectos CFIR:

Detalles de alineación:

${initiative.details.map(detail => `
${detail.aspect} ${detail.match}%

${detail.comment}

`).join('')}
`; pdiContainer.appendChild(initiativeCard); }); // Display recommendations const recHeader = document.createElement('h3'); recHeader.className = 'font-medium text-yellow-700 mb-3 flex items-center'; recHeader.innerHTML = ' Recomendaciones estratégicas'; recContainer.appendChild(recHeader); recommendations.forEach((rec, index) => { const recItem = document.createElement('div'); recItem.className = 'mb-3 p-3 bg-yellow-50 border border-yellow-100 rounded-lg flex items-start analysis-result'; recItem.innerHTML = ` ${index + 1} ${rec} `; recContainer.appendChild(recItem); }); } });