Recommended Action
${lastAnalysis.action}
`;
document.getElementById('pdf-steps').innerHTML = lastAnalysis.steps.map((s, i) => `
${i+1}. ${s.title}
${s.details}
`).join('');
const reportEl = document.getElementById('pdf-report');
reportEl.classList.remove('hidden');
const canvas = await html2canvas(reportEl, { scale: 2 });
reportEl.classList.add('hidden');
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'in', format: 'letter' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Payment-Troubleshooting-Report.pdf');
}
document.getElementById('troubleshootBtn').addEventListener('click', troubleshoot);
document.getElementById('downloadPdfBtn').addEventListener('click', generatePdf);
document.getElementById('results-panel').addEventListener('click', e => {
if (e.target.classList.contains('step-header')) {
const details = e.target.nextElementSibling;
if (details.style.maxHeight) {
details.style.maxHeight = null;
} else {
details.style.maxHeight = details.scrollHeight + "px";
}
}
});
});