`;
container.innerHTML = html;
}
function wscgSwitchTab(tabId) {
document.querySelectorAll('.wscg-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.wscg-content').forEach(c => c.classList.remove('active'));
const idx = tabId === 'builder' ? 0 : 1;
document.querySelectorAll('.wscg-tab-btn')[idx].classList.add('active');
document.getElementById('wscg-' + tabId).classList.add('active');
if (tabId === 'preview') {
wscgRenderSheet();
}
}
/* --- PDF Generation --- */
function wscgGeneratePDF() {
wscgRenderSheet(); // Final render
const data = wscgGetFormData();
if (data.components.length === 0) {
alert("Please add components before generating the PDF.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const purple = [74, 20, 140];
const gold = [255, 193, 7];
let y = 20;
// 1. Header
doc.setFillColor(...purple);
doc.rect(0, 0, 210, 20, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(16);
doc.text(`Magical Working Log: ${data.title}`, 14, 13);
y = 30;
// 2. Intention & Timing
doc.setTextColor(0, 0, 0);
doc.setFontSize(10);
doc.setFont("helvetica", "bold");
doc.text("INTENTION:", 14, y);
doc.setFont("helvetica", "normal");
doc.text(data.outcome, 40, y);
y += 5;
doc.setFont("helvetica", "bold");
doc.text("FOCUS:", 14, y);
doc.setFont("helvetica", "normal");
doc.text(data.focus, 40, y);
y += 5;
const dayCorr = WSCG_CORRESPONDENCES[data.day] || {};
doc.text(`TIMING: ${data.moon} Moon, ${data.day} (Focus: ${dayCorr.focus || 'General'})`, 14, y);
y += 10;
// 3. Components Table
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(...purple);
doc.text("Material Components", 14, y);
y += 5;
const componentTableBody = data.components.map(c => [c.item, c.type, c.prop]);
doc.autoTable({
startY: y,
head: [['Item', 'Type', 'Magical Property']],
body: componentTableBody,
theme: 'grid',
headStyles: { fillColor: purple, fontSize: 10 },
styles: { fontSize: 9 },
columnStyles: {
0: { cellWidth: 50, fontStyle: 'bold' },
1: { cellWidth: 30 },
2: { cellWidth: 'auto', overflow: 'linebreak' }
}
});
y = doc.lastAutoTable.finalY + 10;
// 4. Procedure
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(...purple);
doc.text("Procedure / Steps", 14, y);
y += 5;
const procedureList = data.procedure.map((step, index) => [`${index + 1}.`, step]);
doc.autoTable({
startY: y,
body: procedureList,
theme: 'plain',
headStyles: { fillColor: [240, 240, 240] },
styles: { fontSize: 10, cellPadding: 2 },
columnStyles: { 0: { cellWidth: 10, fontStyle: 'bold' }, 1: { cellWidth: 170 } }
});
y = doc.lastAutoTable.finalY + 10;
// 5. Verification Log
if (y > 250) { doc.addPage(); y = 20; }
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.text("Verification & Result Log", 14, y);
y += 5;
doc.setDrawColor(255, 193, 7);
doc.setLineWidth(1);
doc.rect(14, y, 180, 50, 'S'); // Result box
doc.setFontSize(10);
doc.setFont("times", "normal");
doc.text("Fulfillment Date: _______________", 18, y + 10);
doc.text("Observed Result / Effectiveness Assessment:", 18, y + 20);
doc.save(`SpellLog_${data.title.replace(/\s/g, '_')}.pdf`);
}
