`).join('');
aiRecommendationEl.innerHTML = generateAIRecommendation(results);
renderResultsChart(results);
}
function renderResultsChart(results) {
const ctx = document.getElementById('resultsChart');
if (!ctx) return;
const labels = results.map(r => r.name).reverse();
const data = results.map(r => r.score).reverse();
if (resultsChart) resultsChart.destroy();
resultsChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Overall Score',
data: data,
backgroundColor: 'rgba(79, 70, 229, 0.8)',
borderColor: 'rgba(79, 70, 229, 1)',
borderWidth: 1
}]
},
options: {
indexAxis: 'y',
responsive: true, maintainAspectRatio: false,
scales: { x: { beginAtZero: true, max: 100 } },
plugins: { legend: { display: false } }
}
});
}
// --- PDF GENERATION --- //
function generatePDF() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ unit: 'pt', format: 'a4' });
const results = calculateScores();
let y = 40;
const margin = 40;
const pdfWidth = pdf.internal.pageSize.getWidth();
pdf.setFontSize(20);
pdf.setFont('helvetica', 'bold');
pdf.text('Decision Analysis Report', pdfWidth / 2, y, { align: 'center' });
y += 20;
pdf.setFontSize(14);
pdf.setFont('helvetica', 'normal');
pdf.text(decision.title, pdfWidth / 2, y, { align: 'center' });
y += 40;
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Recommendation:', margin, y);
y += 15;
pdf.setFont('helvetica', 'normal');
const recLines = pdf.splitTextToSize(generateAIRecommendation(results).replace(/<\/?b>/g, ''), pdfWidth - margin * 2);
pdf.text(recLines, margin, y);
y += recLines.length * 12 + 20;
const headers = [['Rank', 'Option', 'Score']];
const body = results.map((r, i) => [i + 1, r.name, r.score.toFixed(1)]);
pdf.autoTable({
startY: y,
head: headers,
body: body,
theme: 'grid',
headStyles: { fillColor: [31, 41, 55] }
});
pdf.save('Decision-Report.pdf');
}
// --- TAB NAVIGATION --- //
function setActiveTab(index) {
tabs.forEach((tab, i) => tab.classList.toggle('active', i === index));
tabPanels.forEach((panel, i) => panel.classList.toggle('hidden', i !== index));
}
// --- KICK IT OFF --- //
initializeApp();
});