`;
inputsSummaryHtml += ``;
}
let analysisHtml = "";
if (analysis.strengths.length > 0) {
analysisHtml += `
II. User Assessment of Risks & Terms
`;
const createInputSection = (title, data) => {
let sectionHtml = `${title}
`;
for(const key in data) {
if(key.endsWith('Text')) continue; // Skip text versions if value exists
let label = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
let value = data[key.replace('Exists','Value')] !== undefined ? data[key.replace('Exists','Value')] : data[key]; // for hurdle rate
if (data[key+'Text']) value = data[key+'Text']; // Use text for dropdowns
else if (typeof data[key] === 'boolean') value = data[key] ? 'Yes' : 'No';
else if (typeof data[key] === 'number' && (key.includes('Fee') || key.includes('Value'))) value = data[key] + (key.includes('Fee') ? '%' : '');
if(key === 'hurdleRateExists'){
label = "Hurdle Rate Exists?";
value = data.hurdleRateExists === 'yes' ? `Yes (${data.hurdleRateValue !== null ? data.hurdleRateValue + '%' : 'N/A'})` : 'No';
} else if (key === 'hurdleRateValue' && data.hurdleRateExists !== 'yes') continue;
if (data[key] !== undefined && data[key] !== null) { // Only print if there's a value
sectionHtml += `
`;
};
inputsSummaryHtml += createInputSection("Strategy & Market Risk", inputs.strategyMarket);
inputsSummaryHtml += createInputSection("Operational & Counterparty Risk", inputs.operational);
inputsSummaryHtml += createInputSection("Liquidity Terms, Fees & Transparency", inputs.termsFees);
if (inputs.userNotes) {
inputsSummaryHtml += `${label}: ${value || "N/A"}
`; } } return sectionHtml + `User's Overall Notes:
${inputs.userNotes}
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.");
}
});
