${item.why}
`;
outputContainer.appendChild(card);
});
};
/**
* Handles the "Add to Checklist" button click.
*/
const handleAddServices = () => {
let itemsToAdd = [];
if (configCheckboxes.payments.checked) {
itemsToAdd.push(...complianceDatabase.payments);
configCheckboxes.payments.checked = false;
}
if (configCheckboxes.lending.checked) {
itemsToAdd.push(...complianceDatabase.lending);
configCheckboxes.lending.checked = false;
}
if (configCheckboxes.investing.checked) {
itemsToAdd.push(...complianceDatabase.investing);
configCheckboxes.investing.checked = false;
}
if (configCheckboxes.crypto.checked) {
itemsToAdd.push(...complianceDatabase.crypto);
configCheckboxes.crypto.checked = false;
}
if (itemsToAdd.length > 0) {
renderChecklistItems(itemsToAdd);
}
showTab(0); // Switch back to the dashboard
};
// --- PDF Generation Function ---
const downloadPDF = () => {
if (typeof window.jspdf === 'undefined') {
alert("Error: PDF library (jsPDF) could not be loaded.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF("p", "mm", "a4");
const pageMargin = 20;
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
const maxY = pageHeight - pageMargin; // Max Y-pos before bottom margin
const contentWidth = pageWidth - (pageMargin * 2);
let yPos = pageMargin;
const checkPageBreak = (estimatedHeight) => {
if (yPos + estimatedHeight > maxY) {
doc.addPage();
yPos = pageMargin;
}
};
// --- Build PDF ---
doc.setFontSize(18);
doc.setFont("helvetica", "bold");
doc.text("FinTech Compliance Checklist Report", pageWidth / 2, yPos, { align: "center" });
yPos += 8;
doc.setFontSize(10);
doc.setFont("helvetica", "normal");
doc.text(`Generated on: ${new Date().toLocaleDateString()}`, pageWidth / 2, yPos, { align: "center" });
yPos += 15;
const checklistItems = outputContainer.querySelectorAll('.frcc-item-card');
if (checklistItems.length === 0) {
doc.text("No items found on the checklist.", pageMargin, yPos);
doc.save("FinTech_Checklist_Report.pdf");
return;
}
checklistItems.forEach((card, index) => {
const area = card.querySelector('h5').textContent;
const req = card.querySelector('p:nth-of-type(1)').textContent;
const why = card.querySelector('p:nth-of-type(2)').textContent;
const status = card.querySelector('select').value;
const notes = card.querySelector('textarea').value;
// Estimate height
const reqLines = doc.splitTextToSize(req, contentWidth);
const whyLines = doc.splitTextToSize(why, contentWidth);
const notesLines = doc.splitTextToSize(notes || "", contentWidth - 10);
let estHeight = 10 + (reqLines.length * 5) + (whyLines.length * 4) + 8;
if (notes) estHeight += 6 + (notesLines.length * 5);
checkPageBreak(estHeight);
// Draw Item
doc.setFontSize(12);
doc.setFont("helvetica", "bold");
doc.setTextColor(0, 86, 179); // Blue
doc.text(area, pageMargin, yPos);
yPos += 7;
doc.setFontSize(11);
doc.setFont("helvetica", "normal");
doc.setTextColor(0, 0, 0);
doc.text(reqLines, pageMargin, yPos);
yPos += (reqLines.length * 5) + 2;
doc.setFontSize(9);
doc.setFont("helvetica", "italic");
doc.setTextColor(80, 80, 80);
doc.text(whyLines, pageMargin, yPos);
yPos += (whyLines.length * 4) + 6;
// Status
doc.setFontSize(10);
doc.setFont("helvetica", "bold");
doc.text("Status:", pageMargin, yPos);
if (status === "Complete") doc.setTextColor(40, 167, 69); // Green
else if (status === "In Progress") doc.setTextColor(255, 193, 7); // Yellow/Orange
else doc.setTextColor(220, 53, 69); // Red
doc.setFont("helvetica", "normal");
doc.text(status, pageMargin + 15, yPos);
yPos += 6;
doc.setTextColor(0, 0, 0);
// Notes
if (notes) {
doc.setFontSize(10);
doc.setFont("helvetica", "bold");
doc.text("Notes:", pageMargin, yPos);
yPos += 5;
doc.setFont("helvetica", "normal");
doc.setFillColor(245, 245, 245);
doc.rect(pageMargin, yPos, contentWidth, (notesLines.length * 5) + 4, 'F');
doc.text(notesLines, pageMargin + 2, yPos + 4);
yPos += (notesLines.length * 5) + 8;
}
yPos += 5; // Extra padding
// Add a line between items
if (index < checklistItems.length - 1) {
checkPageBreak(5); // Check for line
doc.setDrawColor(220, 220, 220);
doc.line(pageMargin, yPos - 2, pageWidth - pageMargin, yPos - 2);
}
});
// Save the PDF
doc.save("FinTech_Checklist_Report.pdf");
};
// --- Event Listeners ---
prevBtn.addEventListener('click', () => {
showTab(currentTabIndex - 1);
});
nextBtn.addEventListener('click', () => {
showTab(currentTabIndex + 1);
});
addBtn.addEventListener('click', handleAddServices);
pdfBtn.addEventListener('click', downloadPDF);
// --- Initial Setup ---
createTabs();
showTab(0);
renderChecklistItems(complianceDatabase.universal); // Pre-populate
});