`;
};
const downloadTxt = () => {
const data = getData();
let content = `RENTAL APPLICATION FORM\n`;
content += "========================================================\n";
content += `Property Address: ${data.propertyAddress}\n\n`;
content += "1. APPLICANT INFO\n";
content += "-------------------\n";
content += `Name: ${data.fullName}\n`;
content += `DOB: ${data.dob}\n`;
content += `Phone: ${data.phone}\n`;
content += `Email: ${data.email}\n`;
content += `Other Occupants: ${data.otherOccupants}\n\n`;
content += "2. RESIDENCY HISTORY\n";
content += "---------------------\n";
content += `Current Address: ${data.currentAddress}\n`;
content += `Occupancy Dates: ${data.currentDates}\n`;
content += `Monthly Rent: ${formatCurrency(data.currentRent)}\n`;
content += `Landlord: ${data.currentLandlord}\n`;
content += `Landlord Phone: ${data.currentLandlordPhone}\n\n`;
content += "3. EMPLOYMENT & INCOME\n";
content += "----------------------\n";
content += `Employer: ${data.employerName}\n`;
content += `Job Title: ${data.jobTitle}\n`;
content += `Employment Dates: ${data.employmentDates}\n`;
content += `Annual Income: ${formatCurrency(data.annualIncome)}\n`;
content += `Supervisor: ${data.supervisorName}\n`;
content += `Supervisor Phone: ${data.supervisorPhone}\n\n`;
content += "4. OTHER DETAILS\n";
content += "----------------\n";
content += `Vehicle: ${data.vehicleYear} ${data.vehicleMake} (Plate: ${data.vehiclePlate})\n`;
content += `Emergency Contact: ${data.emergencyName} (${data.emergencyRelationship}) - ${data.emergencyPhone}\n`;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `rental_app_${data.fullName.replace(/ /g, '_')}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
};
const downloadPDF = () => {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('Error: jsPDF library not loaded.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const data = getData();
const margin = 20;
const pageWidth = doc.internal.pageSize.getWidth();
let yPos = 20;
const addTitle = (text, isMain = false) => {
if (yPos > 270) { doc.addPage(); yPos = 20; }
yPos += 5;
doc.setFontSize(isMain ? 16 : 14);
doc.setFont(undefined, 'bold');
doc.setTextColor(isMain ? 44 : 243, isMain ? 62 : 156, isMain ? 80 : 18); // Main dark, Section orange
doc.text(text, margin, yPos);
yPos += isMain ? 8 : 6;
};
const addDetail = (label, text, value) => {
if (yPos > 280) { doc.addPage(); yPos = 20; }
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.setTextColor(44, 62, 80);
doc.text(label, margin, yPos);
doc.setFont(undefined, 'normal');
doc.setTextColor(52, 73, 94);
doc.text(value, margin + 40, yPos); // Indent value
yPos += 6;
};
// --- Build PDF Document ---
// Header
addTitle("Rental Application Summary", true);
doc.setFontSize(12);
doc.setFont(undefined, 'normal');
doc.text(`For Property: ${data.propertyAddress}`, pageWidth / 2, yPos, { align: 'center' });
yPos += 10;
// 1. Applicant Info
addTitle("1. Applicant Info", false);
addDetail("Name:", 40, data.fullName);
addDetail("Date of Birth:", 40, data.dob);
addDetail("Phone:", 40, data.phone);
addDetail("Email:", 40, data.email);
addDetail("Other Occupants:", 40, data.otherOccupants);
yPos += 5;
// 2. Residency History
addTitle("2. Residency History", false);
addDetail("Current Address:", 40, data.currentAddress);
addDetail("Occupancy Dates:", 40, data.currentDates);
addDetail("Monthly Rent:", 40, formatCurrency(data.currentRent));
addDetail("Landlord:", 40, data.currentLandlord);
addDetail("Landlord Phone:", 40, data.currentLandlordPhone);
yPos += 5;
// 3. Employment & Income
addTitle("3. Employment & Income", false);
addDetail("Employer:", 40, data.employerName);
addDetail("Job Title:", 40, data.jobTitle);
addDetail("Employment Dates:", 40, data.employmentDates);
addDetail("Annual Income:", 40, formatCurrency(data.annualIncome));
addDetail("Supervisor:", 40, data.supervisorName);
addDetail("Supervisor Phone:", 40, data.supervisorPhone);
yPos += 5;
// 4. Other Details
addTitle("4. Other Details", false);
addDetail("Vehicle:", 40, `${data.vehicleYear} ${data.vehicleMake} (Plate: ${data.vehiclePlate})`);
addDetail("Emergency Contact:", 40, `${data.emergencyName} (${data.emergencyRelationship}) - ${data.emergencyPhone}`);
yPos += 10;
doc.setFontSize(8);
doc.setFont(undefined, 'italic');
doc.text('This is a summary form. Full application subject to screening and verification.', pageWidth / 2, 285, { align: 'center' });
doc.save(`rental_app_${data.fullName.replace(/ /g, '_')}.pdf`);
};
// --- Event Listeners ---
// Tab Buttons
tabButtons.forEach((btn, index) => {
btn.addEventListener('click', () => showTab(index + 1));
});
// Next/Prev Navigation
nextBtn.addEventListener('click', () => showTab(currentTab + 1));
prevBtn.addEventListener('click', () => showTab(currentTab - 1));
// Tab 5 Actions
downloadPdfBtn.addEventListener('click', downloadPDF);
downloadTxtBtn.addEventListener('click', downloadTxt);
// --- Initialization ---
showTab(1);
});
