`;
const outputContainer = document.getElementById('resolution-output-content');
if(outputContainer) outputContainer.innerHTML = finalHTML;
};
const handleDownloadPdf = async () => {
const { jsPDF } = window.jspdf;
const content = document.getElementById('resolution-output-content');
if (!content) return;
const originalButtonText = downloadPdfBtn.innerHTML;
downloadPdfBtn.innerHTML = 'Generating...';
downloadPdfBtn.disabled = true;
try {
const canvas = await html2canvas(content, { scale: 2, useCORS: true, backgroundColor: '#ffffff' });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth();
const margin = 20;
const contentWidth = pdfWidth - (margin * 2);
const imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * contentWidth) / imgProps.width;
let heightLeft = imgHeight;
let position = margin;
pdf.addImage(imgData, 'PNG', margin, position, contentWidth, imgHeight);
heightLeft -= (pdf.internal.pageSize.getHeight() - margin * 2);
while (heightLeft > 0) {
position = heightLeft - imgHeight + margin;
pdf.addPage();
pdf.addImage(imgData, 'PNG', margin, position, contentWidth, imgHeight);
heightLeft -= (pdf.internal.pageSize.getHeight() - margin);
}
pdf.save('Board_Resolution.pdf');
} catch (error) {
console.error("PDF generation failed:", error);
} finally {
downloadPdfBtn.innerHTML = originalButtonText;
downloadPdfBtn.disabled = false;
}
};
// Event Listeners
tabButtons.forEach((btn, i) => btn.addEventListener('click', () => switchTab(i + 1)));
prevBtn.addEventListener('click', () => switchTab(currentTab - 1));
nextBtn.addEventListener('click', () => switchTab(currentTab + 1));
addResolutionBtn.addEventListener('click', () => addResolution());
downloadPdfBtn.addEventListener('click', handleDownloadPdf);
// Initial setup with sample data
addResolution({type: 'WHEREAS', text: 'the Company requires a new corporate bank account for its operational needs.'});
addResolution({type: 'RESOLVED', text: 'the officers of the Company are authorized to open a corporate checking account with Bank of America.'});
addResolution({type: 'RESOLVED', text: 'the President or Treasurer of the Company is authorized to execute all necessary documents to establish said account.'});
updateNavButtons();
});
