`;
container.innerHTML = html;
}
function wmhlSwitchTab(tabId) {
document.querySelectorAll('.wmhl-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.wmhl-content').forEach(c => c.classList.remove('active'));
const idx = tabId === 'builder' ? 0 : 1;
document.querySelectorAll('.wmhl-tab-btn')[idx].classList.add('active');
document.getElementById('wmhl-' + tabId).classList.add('active');
if (tabId === 'preview') {
wmhlRenderReport();
}
}
function wmhlLoadExample() {
if(!confirm("Overwrite current inputs with example workshop data?")) return;
document.getElementById('inp-workshop-name').value = "Agile Principles for Engineers";
document.getElementById('inp-trainer').value = "Dr. S. Chen / Global Consulting";
document.getElementById('inp-attendees').value = "15";
document.getElementById('inp-location').value = "Training Room C / 2026-01-15";
// Clear and fill dynamic rows
document.getElementById('wmhl-equipment-rows').innerHTML = '';
document.getElementById('wmhl-supplies-rows').innerHTML = '';
document.getElementById('wmhl-handouts-rows').innerHTML = '';
wmhlAddRow('equipment', "Whiteboard & Markers", 1, "Must be portable.");
wmhlAddRow('equipment', "HDMI Cable (15ft)", 1, "Check compatibility with trainer's laptop.");
wmhlAddRow('supplies', "Post-It Notes (Assorted)", 10, "For affinity mapping exercise.");
wmhlAddRow('supplies', "Printed Workbook (50 pages)", 15, "Check printer ink levels.");
wmhlAddRow('supplies', "Pens/Pencils", 20, "Generic supplies.");
wmhlAddRow('handouts', "PDF Slides Final Version", 1, "Link provided via Google Drive.");
wmhlAddRow('handouts', "Quick Reference Agile Cheat Sheet", 1, "Printed on cardstock.");
wmhlRenderReport();
wmhlSwitchTab('preview');
}
/* --- PDF Generation --- */
async function wmhlGeneratePDF() {
wmhlRenderReport(); // Final render check
const data = {
name: document.getElementById('inp-workshop-name').value || "Workshop Name",
trainer: document.getElementById('inp-trainer').value || "N/A Trainer",
attendees: document.getElementById('inp-attendees').value || "N/A",
location: document.getElementById('inp-location').value || "N/A",
equipment: wmhlGetRowData('equipment'),
supplies: wmhlGetRowData('supplies'),
handouts: wmhlGetRowData('handouts')
};
if (data.equipment.length + data.supplies.length + data.handouts.length === 0) {
alert("Please add items to the inventory before generating the PDF.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const green = [39, 174, 96];
let y = 20;
// 1. Header
doc.setFillColor(...green);
doc.rect(0, 0, 210, 20, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(16);
doc.text("Workshop Resource Inventory", 14, 13);
// 2. Metadata
doc.setTextColor(0, 0, 0);
doc.setFontSize(10);
doc.setFont("helvetica", "normal");
doc.text(`Workshop: ${data.name}`, 14, y + 10);
doc.text(`Host: ${data.trainer}`, 14, y + 15);
doc.text(`Location/Date: ${data.location}`, 100, y + 15);
doc.text(`Attendees: ${data.attendees}`, 100, y + 10);
y += 35;
// Helper to add tables
const addResourceTable = (title, items, startY) => {
if (items.length === 0) return startY;
if (startY > 260) { doc.addPage(); startY = 20; }
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(...green);
doc.text(title, 14, startY);
startY += 5;
const tableBody = items.map((item, index) => [
index + 1,
item.item,
item.qty,
item.notes
]);
doc.autoTable({
startY: startY,
head: [['#', 'Item Description', 'Qty', 'Notes / Logistics']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: green, fontSize: 10 },
styles: { fontSize: 9 },
columnStyles: {
0: { cellWidth: 10, halign: 'center' },
2: { cellWidth: 15, halign: 'center', fontStyle: 'bold' },
3: { cellWidth: 'auto', overflow: 'linebreak' }
}
});
return doc.lastAutoTable.finalY + 10;
};
// 3. Resource Tables
y = addResourceTable("A. EQUIPMENT & SETUP (Technical)", data.equipment, y);
y = addResourceTable("B. PHYSICAL SUPPLIES (Consumables)", data.supplies, y);
y = addResourceTable("C. DIGITAL HANDOUTS & RESOURCES", data.handouts, y);
// 4. Approval Block
y += 10;
doc.setFontSize(10);
doc.text("Logistics Approval: ___________________________", 14, y);
doc.text("Date Checked: _______________", 140, y);
doc.save(`Workshop_Inventory_${data.name.replace(/\s/g, '_')}.pdf`);
}
