`; // Close previous section
}
html += ``; // Close last section
// Signatures Section
const roommates = data['roommates-list'].split('\n').filter(r => r.trim() !== '');
if (roommates.length > 0) {
html += `
`;
}
reviewArea.innerHTML = html;
pdfDownloadBtn.disabled = false;
switchTab(1); // Switch to review tab
}
/**
* PDF Generation Function
*/
function downloadPDF() {
const data = getFormData();
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'pt', 'a4');
let currentY = 40;
const margin = 40;
const pageWidth = doc.internal.pageSize.width;
const maxWidth = pageWidth - (margin * 2);
const checkPageBreak = (spaceNeeded) => {
if (currentY + spaceNeeded > doc.internal.pageSize.height - margin) {
doc.addPage();
currentY = margin;
}
};
const addSectionHeader = (title) => {
checkPageBreak(25);
doc.setFontSize(16);
doc.setFont('Helvetica', 'bold');
doc.setTextColor(52, 73, 94); /* Secondary color */
doc.text(title, margin, currentY);
currentY += 10;
doc.setLineWidth(0.5);
doc.setDrawColor(200);
doc.line(margin, currentY, pageWidth - margin, currentY);
currentY += 15;
doc.setTextColor(0);
};
const addItem = (label, text, isList) => {
doc.setFontSize(11);
doc.setFont('Helvetica', 'bold');
checkPageBreak(15);
doc.text(label, margin, currentY);
currentY += 10;
doc.setFont('Helvetica', 'normal');
let content = text || 'N/A - To be defined.';
let indent = 10;
if (isList && content !== 'N/A - To be defined.') {
const items = content.split('\n').filter(line => line.trim() !== '');
items.forEach(item => {
checkPageBreak(15);
doc.text("•", margin + indent, currentY);
const lines = doc.splitTextToSize(item.trim(), maxWidth - indent - 10);
doc.text(lines, margin + indent + 10, currentY);
currentY += (lines.length * 12);
});
currentY += 5;
} else {
const lines = doc.splitTextToSize(content, maxWidth - indent);
checkPageBreak(lines.length * 12 + 5);
doc.text(lines, margin + indent, currentY);
currentY += (lines.length * 12) + 5;
}
};
// --- PDF Content ---
// Title Block
doc.setFontSize(22);
doc.setFont('Helvetica', 'bold');
doc.setTextColor(26, 188, 156); /* Primary color */
doc.text("ROOMMATE AGREEMENT OUTLINE", pageWidth / 2, currentY, { align: 'center' });
currentY += 15;
doc.setFontSize(12);
doc.setFont('Helvetica', 'normal');
doc.setTextColor(108, 117, 125);
doc.text(`Property: ${data['property-address'] || 'N/A'} | Start Date: ${data['start-date'] || 'N/A'}`, pageWidth / 2, currentY, { align: 'center' });
currentY += 30;
doc.setTextColor(0);
// Sections
let currentSection = '';
fields.forEach(field => {
if (field.section !== currentSection) {
addSectionHeader(field.section.toUpperCase());
currentSection = field.section;
}
addItem(field.label, data[field.id], field.isList);
});
// Signatures
const roommates = data['roommates-list'].split('\n').filter(r => r.trim() !== '');
if (roommates.length > 0) {
addSectionHeader("SIGNATURES");
const sigY = currentY + 40;
const colWidth = maxWidth / roommates.length;
roommates.forEach((name, index) => {
const startX = margin + (colWidth * index);
checkPageBreak(80);
doc.setLineWidth(1);
doc.line(startX, sigY, startX + colWidth - 20, sigY);
doc.setFontSize(10);
doc.setFont('Helvetica', 'normal');
doc.text(`${name.trim()} (Roommate)`, startX, sigY + 10);
});
currentY = sigY + 40;
}
doc.save('roommate_agreement_outline.pdf');
}
// --- Event Listeners ---
generateBtn.addEventListener('click', generateAgreement);
pdfDownloadBtn.addEventListener('click', downloadPDF);
// --- Tab Navigation ---
function switchTab(tabIndex) {
tabs.forEach((tab, index) => {
tab.classList.toggle('active', index === tabIndex);
contents[index].classList.toggle('active', index === tabIndex);
});
currentTab = tabIndex;
updateNavButtons();
}
function updateNavButtons() {
prevBtn.disabled = currentTab === 0;
nextBtn.disabled = currentTab === tabs.length - 1;
}
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => switchTab(index));
});
nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); });
prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); });
// --- Initial Setup ---
setInitialDate();
updateNavButtons();
});
${field.section.toUpperCase()}
`; currentSection = field.section; } const value = data[field.id]; html += `
${field.label}
${formatText(value, field.isList)}
`;
});
html += `SIGNATURES
By signing below, the roommates agree to abide by the terms outlined in this document.
`;
roommates.forEach(name => {
html += `
${name.trim()} (Roommate)
`;
});
html += `