PRO Side Arguments
${proHtml || '
No Pro arguments logged.
'}
CON Side Arguments
${conHtml || '
No Con arguments logged.
'}
`;
}
// --- Tab Switching ---
function sdsg_showTab(targetId, element) {
tabButtons.forEach(btn => btn.classList.remove('sdsg-active'));
document.querySelectorAll('.sdsg-tab-content').forEach(content => content.classList.remove('active'));
if (element) {
element.classList.add('sdsg-active');
}
document.getElementById(targetId).classList.add('active');
if (targetId === 'viewer') {
sdsg_renderReview();
}
}
window.sdsg_showTab = sdsg_showTab;
// --- PDF Export ---
function sdsg_downloadPDF() {
sdsg_renderReview();
if (typeof jspdf === 'undefined' || typeof jspdf.plugin.autotable === 'undefined') {
alert('Error: PDF library not fully loaded for export.');
return;
}
if (SDSG_STATE.proArguments.length === 0 && SDSG_STATE.conArguments.length === 0) {
alert('Please define arguments for the debate before generating the PDF.');
return;
}
const H = SDSG_STATE.header;
const M = SDSG_STATE.metrics;
const P = SDSG_STATE.proArguments;
const C = SDSG_STATE.conArguments;
const { jsPDF } = jspdf;
const doc = new jsPDF({ orientation: 'l', unit: 'pt', format: 'a4' }); // Landscape for side-by-side
doc.setFont('sans-serif', 'normal');
const margin = 40;
const pageWidth = doc.internal.pageSize.getWidth();
const contentWidth = pageWidth - margin * 2;
let yPos = margin;
// --- Header ---
doc.setFontSize(16);
doc.setFont('sans-serif', 'bold');
doc.setTextColor('#1e3a8a');
doc.text("Scientific Debate Sheet", pageWidth / 2, yPos, { align: 'center' });
yPos += 20;
doc.setFontSize(12);
doc.text("Resolution:", margin, yPos);
doc.setFont('sans-serif', 'normal');
const resLines = doc.splitTextToSize(H.resolution, contentWidth - 60);
doc.text(resLines, margin + 60, yPos);
yPos += (resLines.length * 14) + 10;
// --- Metrics Table ---
if (yPos > doc.internal.pageSize.getHeight() - 150) { doc.addPage(); yPos = margin; }
doc.setFontSize(12);
doc.setFont('sans-serif', 'bold');
doc.text("Judging Criteria:", margin, yPos);
yPos += 15;
const metricBody = M.map((m, i) => [`${i + 1}.`, m.text]);
doc.autoTable({
head: [['#', 'Metric']],
body: metricBody,
startY: yPos,
theme: 'striped',
styles: { fontSize: 9, cellPadding: 4 },
headStyles: { fillColor: [51, 65, 85], textColor: 255 }, // Slate-700
columnStyles: { 0: { cellWidth: 30, halign: 'center' } },
didDrawPage: function(data) { yPos = data.cursor.y; }
});
yPos = doc.lastAutoTable.finalY + 25;
// --- Arguments (Side-by-Side) ---
if (yPos > doc.internal.pageSize.getHeight() - 80) { doc.addPage(); yPos = margin; }
const proTable = P.map((arg, i) => [`${i + 1}.`, arg.point, arg.evidence]);
const conTable = C.map((arg, i) => [`${i + 1}.`, arg.point, arg.evidence]);
const tableSettings = {
styles: { fontSize: 8, cellPadding: 3, overflow: 'linebreak' },
headStyles: { fillColor: [34, 197, 94], textColor: 255, fontStyle: 'bold' }, // Green-500
columnStyles: { 0: { cellWidth: 20, halign: 'center' }, 1: { cellWidth: 90 }, 2: { cellWidth: 150 } }
};
// PRO Table (Left)
doc.setFontSize(12);
doc.text("PRO Arguments:", margin, yPos);
doc.autoTable({
head: [['#', 'Point', 'Evidence/Source']],
body: proTable,
startY: yPos + 15,
theme: 'grid',
margin: { left: margin, right: pageWidth / 2 - margin / 2 },
...tableSettings
});
const proTableEnd = doc.lastAutoTable.finalY;
// CON Table (Right)
doc.setFontSize(12);
doc.text("CON Arguments:", pageWidth / 2 + margin / 2, yPos);
doc.autoTable({
head: [['#', 'Point', 'Evidence/Source']],
body: conTable,
startY: yPos + 15,
theme: 'grid',
margin: { left: pageWidth / 2 + margin / 2, right: margin },
...tableSettings,
headStyles: { fillColor: [239, 68, 68], textColor: 255, fontStyle: 'bold' } // Red-500
});
const conTableEnd = doc.lastAutoTable.finalY;
// Advance yPos to the lower of the two tables
yPos = Math.max(proTableEnd, conTableEnd) + 20;
doc.save(`Science_Debate_Sheet_${H.topic.replace(/\s/g, '_')}.pdf`);
}
// --- Initialization ---
document.addEventListener('DOMContentLoaded', () => {
// 1. Attach listeners
document.getElementById('sdsg-add-metric-btn').addEventListener('click', sdsg_addMetric);
document.getElementById('sdsg-add-pro-btn').addEventListener('click', () => sdsg_addArgument('pro'));
document.getElementById('sdsg-add-con-btn').addEventListener('click', () => sdsg_addArgument('con'));
document.getElementById('input-next-btn').addEventListener('click', () => sdsg_showTab('viewer', document.querySelector('.sdsg-tab-btn[data-tab="viewer"]')));
document.getElementById('sdsg-download-pdf').addEventListener('click', sdsg_downloadPDF);
tabButtons.forEach(btn => {
btn.addEventListener('click', (e) => sdsg_showTab(e.target.dataset.tab, e.target));
});
// 2. Initial population
sdsg_renderMetrics();
sdsg_renderArgumentTable('pro');
sdsg_renderArgumentTable('con');
});