Management Strategy: Focus on ${inputs.age === "Mature" ? "harvest planning and regeneration" : "growth promotion and health"} while prioritizing ${inputs.goals[0].toLowerCase()}.
`;
// Recommendations HTML
const recsContainer = document.getElementById('sfpg-recs-container');
recsContainer.innerHTML = "";
recs.forEach(r => {
recsContainer.innerHTML += `
`;
});
// Schedule Table
const tbody = document.getElementById('sfpg-schedule-body');
tbody.innerHTML = "";
// Ensure chronological order sort of (basic assignment above was chronological ish)
schedule.forEach(s => {
tbody.innerHTML += `
| Year ${s.year} |
${s.act} |
$${s.cost.toLocaleString()} |
`;
});
// Store data for PDF
sfpgData = { generated: true, inputs, score, recs, schedule };
// Switch Tab
sfpgSwitchTab('preview');
}
// --- PDF Generation ---
async function sfpgDownloadPDF() {
if(!sfpgData.generated) {
alert("Please generate the plan first.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, score, recs, schedule } = sfpgData;
// Header
doc.setFillColor(46, 125, 50); // Forest Green
doc.rect(0, 0, 210, 40, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(22);
doc.text("Forest Stewardship Plan", 14, 25);
doc.setFontSize(10);
doc.text(`Prepared for: ${inputs.name} | Date: ${new Date().toLocaleDateString()}`, 14, 32);
let y = 50;
// Property Info
doc.setTextColor(0, 0, 0);
doc.setFontSize(14);
doc.text("1. Property Summary", 14, y);
y += 10;
doc.setFontSize(11);
doc.text(`Location: ${inputs.location}`, 14, y);
doc.text(`Acreage: ${inputs.acres} Acres`, 100, y);
y += 7;
doc.text(`Forest Type: ${inputs.type}`, 14, y);
doc.text(`Stand Age: ${inputs.age}`, 100, y);
y += 7;
doc.text(`Health Status: ${inputs.health}`, 14, y);
doc.text(`Sustainability Score: ${score}/100`, 100, y);
y += 15;
// Goals
doc.setFontSize(14);
doc.text("2. Management Objectives", 14, y);
y += 10;
doc.setFontSize(11);
inputs.goals.forEach(g => {
doc.text(`• ${g}`, 14, y);
y += 6;
});
y += 10;
// Recommendations
doc.setFontSize(14);
doc.text("3. Management Recommendations", 14, y);
y += 10;
doc.setFontSize(11);
recs.forEach(r => {
if (y > 270) { doc.addPage(); y = 20; } // Page break check
doc.setFont(undefined, 'bold');
doc.text(r.title, 14, y);
y += 6;
doc.setFont(undefined, 'normal');
const splitText = doc.splitTextToSize(r.text, 180);
doc.text(splitText, 14, y);
y += (splitText.length * 5) + 8;
});
// Schedule Table
y += 5;
if (y > 250) { doc.addPage(); y = 20; }
doc.setFontSize(14);
doc.text("4. Five-Year Activity Schedule", 14, y);
y += 5;
const tableData = schedule.map(s => [`Year ${s.year}`, s.act, `$${s.cost.toLocaleString()}`]);
doc.autoTable({
startY: y,
head: [['Timeline', 'Activity', 'Est. Cost (USD)']],
body: tableData,
theme: 'grid',
headStyles: { fillColor: [46, 125, 50] }
});
// Disclaimer Footer
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(8);
doc.setTextColor(150);
doc.text("Generated by ForestSteward. Consult a certified forester before major harvests.", 105, 290, null, null, "center");
}
doc.save(`ForestPlan_${inputs.name.replace(/\s+/g, '_')}.pdf`);
}