${results.description}
Key Consideration:
The selected muscle group (${muscleGroupSelect.options[muscleGroupSelect.selectedIndex].text}) has a significant impact on appropriate pressure levels.
`;
textResultsContainer.innerHTML = textHTML;
// Show the results section
resultsSection.style.display = 'block';
resultsSection.scrollIntoView({ behavior: 'smooth' });
}
/**
* Generates and downloads a PDF session plan.
*/
async function generatePdf() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const results = calculatePressure();
const clientName = clientNameInput.value || 'N/A';
const sessionDate = sessionDateInput.value ? new Date(sessionDateInput.value).toLocaleDateString() : 'N/A';
// --- PDF STYLING & STRUCTURE ---
const pageHeight = doc.internal.pageSize.height;
const pageWidth = doc.internal.pageSize.width;
const margin = 20;
let y = margin;
// 1. HEADER
doc.setFont('helvetica', 'bold');
doc.setFontSize(20);
doc.setTextColor(30, 41, 59); // slate-800
doc.text('Massage Session Plan', margin, y);
y += 8;
doc.setFontSize(12);
doc.setFont('helvetica', 'normal');
doc.setTextColor(100, 116, 139); // slate-500
doc.text('Pressure Estimation & Recommendations', margin, y);
doc.setDrawColor(226, 232, 240); // slate-200
doc.line(margin, y + 5, pageWidth - margin, y + 5);
y += 15;
// 2. CLIENT INFO
doc.setFont('helvetica', 'bold');
doc.setFontSize(11);
doc.setTextColor(51, 65, 85); // slate-700
doc.text('Client Name:', margin, y);
doc.setFont('helvetica', 'normal');
doc.text(clientName, margin + 30, y);
doc.setFont('helvetica', 'bold');
doc.text('Session Date:', pageWidth / 2 + 10, y);
doc.setFont('helvetica', 'normal');
doc.text(sessionDate, pageWidth / 2 + 40, y);
y += 15;
// 3. INPUT PARAMETERS
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(30, 41, 59);
doc.text('Session Input Parameters', margin, y);
y += 8;
const inputs = [
{ label: 'Pain Tolerance', value: painToleranceSelect.options[painToleranceSelect.selectedIndex].text },
{ label: 'Target Muscle Group', value: muscleGroupSelect.options[muscleGroupSelect.selectedIndex].text },
{ label: 'Body Type', value: bodyTypeSelect.options[bodyTypeSelect.selectedIndex].text },
{ label: 'Primary Technique', value: techniqueSelect.options[techniqueSelect.selectedIndex].text }
];
doc.setFontSize(10);
inputs.forEach(input => {
doc.setFont('helvetica', 'bold');
doc.setTextColor(51, 65, 85);
doc.text(input.label + ':', margin + 5, y);
doc.setFont('helvetica', 'normal');
doc.setTextColor(71, 85, 105); // slate-600
doc.text(input.value, margin + 45, y);
y += 7;
});
y += 5;
// 4. ESTIMATION RESULTS
doc.setDrawColor(226, 232, 240);
doc.line(margin, y, pageWidth - margin, y);
y += 10;
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(30, 41, 59);
doc.text('Pressure Estimation & Analysis', margin, y);
y += 10;
doc.setFontSize(12);
doc.text('Estimated Level:', margin, y);
doc.setFont('helvetica', 'bold');
if (results.level.includes('Deep')) doc.setTextColor(190, 18, 60); // rose-700
else if (results.level.includes('Firm')) doc.setTextColor(202, 138, 4); // yellow-600
else doc.setTextColor(21, 128, 61); // green-700
doc.text(results.level, margin + 35, y);
y += 10;
doc.setFont('helvetica', 'normal');
doc.setTextColor(71, 85, 105);
doc.setFontSize(10);
const recommendationLines = doc.splitTextToSize(results.description, pageWidth - (margin * 2));
doc.text(recommendationLines, margin, y);
y += recommendationLines.length * 5 + 10;
// 5. FOOTER
doc.setFontSize(8);
doc.setTextColor(148, 163, 184); // slate-400
doc.text(`This report is an estimation based on the provided parameters and should be used as a guideline.`, margin, pageHeight - 15);
doc.text(`Always maintain open communication with the client to ensure their comfort and safety.`, margin, pageHeight - 10);
doc.save(`Massage_Plan_${clientName.replace(/ /g, '_')}.pdf`);
}
// --- EVENT LISTENERS ---
if(estimateBtn) {
estimateBtn.addEventListener('click', displayResults);
}
if(downloadPdfBtn) {
downloadPdfBtn.addEventListener('click', generatePdf);
}
// --- INITIALIZATION ---
sessionDateInput.valueAsDate = new Date(); // Set today's date
});