`;
});
resultDiv.innerHTML = headerHTML + '
';
resultsContainer.appendChild(resultDiv);
});
}
// --- PDF DOWNLOAD ---
window.downloadPDF = function() {
if (!lastResults) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'pt', 'a4');
const { slots, timezones, date } = lastResults;
const duration = document.getElementById('meetingDuration').value;
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFillColor(41, 128, 185);
doc.rect(0, 0, pageWidth, 60, 'F');
doc.setFontSize(20); doc.setTextColor(255); doc.setFont('helvetica', 'bold');
doc.text('Suggested Meeting Times', 30, 38);
doc.setFontSize(10); doc.setFont('helvetica', 'normal'); doc.setTextColor(50);
doc.text(`Meeting Date: ${new Date(date + 'T12:00:00').toLocaleDateString('en-US', { dateStyle: 'long' })}`, 30, 90);
doc.text(`Meeting Duration: ${duration} minutes`, 30, 105);
const tableHead = [timezones.map(tz => tz.split('/').pop().replace(/_/g, ' '))];
const tableBody = slots.map(utcStartMinutes => {
return timezones.map(tz => {
const localTime = new Date(`${date}T00:00:00.000Z`);
localTime.setUTCHours(0, utcStartMinutes, 0, 0);
return localTime.toLocaleTimeString('en-US', { timeZone: tz, hour: '2-digit', minute: '2-digit', hour12: true });
});
});
doc.autoTable({
head: tableHead,
body: tableBody,
startY: 130,
theme: 'grid',
headStyles: { fillColor: [41, 128, 185] },
});
const pageCount = doc.internal.getNumberOfPages();
for(let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(8); doc.setTextColor(150);
doc.text(`Page ${i} of ${pageCount}`, pageWidth / 2, pageHeight - 20, { align: 'center' });
}
doc.save('Meeting_Times.pdf');
};
// --- EVENT LISTENERS ---
addLocationBtn.addEventListener('click', addLocation);
// --- INITIALIZE ---
initializeApp();
});
