`;
}
let analysisHtml = "";
if (analysis.strengths.length > 0) {
analysisHtml += `
Potential Strengths / Positive Factors Noted:
- ${analysis.strengths.map(s => `
- ${s.replace(/`).join('')}
Potential Concerns / Areas for Deeper Due Diligence:
- ${analysis.concerns.map(c => `
- ${c.replace(/`).join('')}
Neutral Observations / Points to Consider:
- ${analysis.neutrals.map(n => `
- ${n.replace(/`).join('')}
General Notes for '${inputs.basics.strategyText}' Strategy:
- ${analysis.generalNotes.map(gn => `
- ${gn.replace(/`).join('')}
${analysis.overall}
`;
const disclaimer_pdf = `This checklist is an educational tool based on user inputs. It is NOT financial advice. Hedge funds are complex, high-risk investments. Always conduct thorough independent due diligence and consult qualified professionals.`;
pdfContentEl.innerHTML = `
Hedge Fund Due Diligence & Risk Checklist
${inputsSummaryHtml}
III. Generated Risk Considerations Summary
${analysisHtml}
Disclaimer: ${disclaimer_pdf}
`;
document.body.appendChild(pdfContentEl);
html2canvas(pdfContentEl, { scale: 2, useCORS: true, logging:true, windowWidth: pdfContentEl.scrollWidth, windowHeight: pdfContentEl.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
let numPages = Math.ceil(canvas.height / ( (pdfHeight - 40) * (canvas.width / (pdfWidth - 40)) ) );
let pageCanvasHeight = (pdfHeight - 40) * (canvas.width / (pdfWidth - 40));
for (let i = 0; i < numPages; i++) {
if (i > 0) pdf.addPage();
let sourceY = i * pageCanvasHeight;
let sourceHeight = Math.min(pageCanvasHeight, canvas.height - sourceY);
const tempCanvas = document.createElement('canvas');
tempCanvas.width = canvas.width;
tempCanvas.height = sourceHeight;
const ctx = tempCanvas.getContext('2d');
ctx.drawImage(canvas, 0, sourceY, canvas.width, sourceHeight, 0, 0, canvas.width, sourceHeight);
const pageImgData = tempCanvas.toDataURL('image/png');
const pageImgHeight = (sourceHeight * (pdfWidth - 40)) / canvas.width;
pdf.addImage(pageImgData, 'PNG', 20, 20, pdfWidth - 40, pageImgHeight, undefined, 'FAST');
}
pdf.save(`${(inputs.basics.fundName || "HedgeFund").replace(/[^a-z0-9]/gi, '_')}_Risk_Checklist.pdf`);
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("HFR PDF Error:", err); alert("Error generating PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
hfr_openTab({}, 'hfr_tab_fund_basics');
// Default hurdle rate value field visibility
const hurdleExistsEl = document.getElementById('hfr_hurdleRate_exists');
const hurdleValueEl = document.getElementById('hfr_hurdleRate_value');
if(hurdleExistsEl && hurdleValueEl) {
hurdleValueEl.style.display = hurdleExistsEl.value === 'yes' ? 'block' : 'none';
}
if (!document.getElementById('hfr_fundName')) {
console.error("Critical input 'hfr_fundName' not found.");
}
});
