${priorityMap[task.priority].label}
`).join('')}
`;
};
roadmapOutput.innerHTML = `
${renderSection('Immediate Priorities (Now)', tasks.immediate)}
${renderSection('Next 90 Days', tasks.next_90_days)}
${renderSection('Long-Term (6-12 Months)', tasks.long_term)}
`;
}
// --- PDF DOWNLOAD FUNCTION ---
async function downloadPDF() {
downloadPdfButton.disabled = true;
pdfLoadingMessage.classList.remove('hidden');
// Generate a fresh set of data for the PDF
const tasks = getRoadmapDataForPdf();
// Build a clean HTML structure for the PDF content
const pdfContainer = document.getElementById('pdf-clone-container');
const pdfTitle = document.createElement('h2');
pdfTitle.id = 'pdf-title-clone';
pdfTitle.textContent = 'Startup Legal Strategy Roadmap';
const pdfContent = document.createElement('div');
pdfContent.id = 'pdf-content-wrapper';
pdfContent.innerHTML = `
${renderPdfSection('Immediate Priorities (Now)', tasks.immediate)}
${renderPdfSection('Next 90 Days', tasks.next_90_days)}
${renderPdfSection('Long-Term (6-12 Months)', tasks.long_term)}
`;
pdfContainer.innerHTML = ''; // Clear previous content
pdfContainer.appendChild(pdfTitle);
pdfContainer.appendChild(pdfContent);
pdfContainer.style.display = 'block';
try {
const canvas = await html2canvas(pdfContainer, { scale: 2, useCORS: true });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Startup-Legal-Roadmap.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("An error occurred while generating the PDF.");
} finally {
downloadPdfButton.disabled = false;
pdfLoadingMessage.classList.add('hidden');
pdfContainer.style.display = 'none'; // Hide the clone container again
}
}
// Helper function to re-generate data just for the PDF
function getRoadmapDataForPdf() {
const tasks = { immediate: [], next_90_days: [], long_term: [] };
// This is a duplication of the logic from generateRoadmap() to ensure fresh data.
const structure = document.getElementById('business-structure').value;
if (structure === 'not-decided') tasks.immediate.push({ text: 'Consult with legal counsel to choose the correct business entity (LLC vs. C-Corp).', priority: 'high' });
else {
tasks.immediate.push({ text: `File for incorporation as a ${structure === 'llc' ? 'LLC' : 'Corporation'}.`, priority: 'high' });
tasks.immediate.push({ text: 'Apply for a Federal Employer Identification Number (EIN).', priority: 'high' });
}
if (document.getElementById('founder-agreements').value === 'no') tasks.immediate.push({ text: 'Draft and sign a comprehensive Founder Agreement.', priority: 'high' });
if (document.getElementById('vesting-implemented').checked) tasks.immediate.push({ text: 'Implement stock purchase agreements with vesting.', priority: 'high' });
if(document.getElementById('ip-assignments').checked) tasks.immediate.push({ text: 'Ensure all team members sign IP Assignment Agreements.', priority: 'high' });
if(document.getElementById('ip-trademark').checked) tasks.next_90_days.push({ text: 'File a trademark for your brand name/logo.', priority: 'medium' });
if(document.getElementById('ip-patent').checked) tasks.next_90_days.push({ text: 'Consult a patent attorney and consider a provisional patent.', priority: 'high' });
document.querySelectorAll('.key-contract:checked').forEach(el => tasks.next_90_days.push({ text: `Develop templates for ${el.dataset.contract} agreements.`, priority: 'medium' }));
if(document.getElementById('privacy-policy').checked) tasks.next_90_days.push({ text: 'Draft and publish a Privacy Policy.', priority: 'medium' });
if(document.getElementById('terms-of-service').checked) tasks.next_90_days.push({ text: 'Draft and publish Terms of Service.', priority: 'medium' });
const fundraisingStage = document.getElementById('fundraising-stage').value;
const isFundraising = document.querySelector('input[name="is-fundraising"]:checked').value;
if (isFundraising === 'yes') {
tasks.immediate.push({ text: 'Prepare fundraising documents (SAFE/Note) and data room.', priority: 'high' });
tasks.immediate.push({ text: 'Develop a capitalization table (cap table).', priority: 'high' });
} else if (['pre-seed', 'seed'].includes(fundraisingStage)) {
tasks.next_90_days.push({ text: 'Clean up corporate records for due diligence.', priority: 'medium' });
}
tasks.long_term.push({ text: 'Establish a formal board and governance policies.', priority: 'low' });
tasks.long_term.push({ text: 'Review data privacy and security policies annually.', priority: 'low' });
return tasks;
}
// Helper function to render a clean section for PDF
function renderPdfSection(title, taskList) {
if(taskList.length === 0) return '';
const priorityMap = {
high: { label: 'High', class: 'pdf-priority-high' },
medium: { label: 'Medium', class: 'pdf-priority-medium' },
low: { label: 'Low', class: 'pdf-priority-low' }
};
return `
${title}
${taskList.map(task => `
${task.text}
${priorityMap[task.priority].label}
`).join('')}
`;
}
// --- EVENT LISTENER ATTACHMENT ---
prevButton.addEventListener('click', () => navigateTabs(-1));
nextButton.addEventListener('click', () => navigateTabs(1));
downloadPdfButton.addEventListener('click', downloadPDF);
tabButtons.forEach(button => {
button.addEventListener('click', () => {
showTab(parseInt(button.dataset.tab, 10));
});
});
// --- INITIALIZATION ---
showTab(1);
});