IV. Property & Market
`;
for (const key in inputs.propertyMarket) {
inputsSummaryHtml += `
${key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}: ${document.getElementById('cre_'+key).selectedOptions[0].text}
`; } inputsSummaryHtml += `V. Personal Fit
`;
inputsSummaryHtml += `
`;
let analysisHtml = "";
if (analysis.strengths.length > 0) {
analysisHtml += `Portfolio Percentage: ${inputs.personalFit.portfolioPercentage !== null ? inputs.personalFit.portfolioPercentage + '%' : 'N/A'}
`; inputsSummaryHtml += `Risk Understanding: ${document.getElementById('cre_userRiskUnderstanding').selectedOptions[0].text}
`; inputsSummaryHtml += `Potential Strengths Identified:
- ${analysis.strengths.map(s => `
- ${s} `).join('')}
Potential Concerns / Red Flags:
- ${analysis.concerns.map(c => `
- ${c} `).join('')}
Neutral / Points to Consider:
- ${analysis.neutrals.map(n => `
- ${n} `).join('')}
${analysis.overallAssessment}
`;
const generalTipsHtmlPdf = document.getElementById('cshw_generalSecurityTips') ? document.getElementById('cshw_generalSecurityTips').innerHTML.replace(/.*?<\/h4>/g, 'General Security Best Practices (Applicable if crypto is involved):') : "
General security tips section not found.
"; const disclaimer_pdf = `This analysis is based on user-provided assessments. It is not exhaustive and NOT financial, legal, or investment advice. Crowdfunded real estate is risky. Always DYOR and consult professionals.`; pdfContentEl.innerHTML = `Crowdfunded Real Estate Investment Risk Analysis
${inputs.overview.dealName} (Platform: ${inputs.overview.platformName})
User Input Summary
${inputsSummaryHtml}
Risk Profile Analysis
${analysisHtml}
${generalTipsHtmlPdf}
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.overview.dealName || "CRE_Risk").replace(/[^a-z0-9]/gi, '_')}_Analysis.pdf`);
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("CRE PDF Error:", err); alert("Error generating PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
cre_openTab({}, 'cre_tab_overview');
// Set default selections for dropdowns
const selectsToDefault = [
'cre_platformReputation', 'cre_sponsorTrackRecord', 'cre_platformTransparency',
'cre_sponsorAlignment', 'cre_dealClarity', 'cre_projectionsRealistic',
'cre_exitStrategyStrength', 'cre_locationQuality', 'cre_propertyCondition',
'cre_marketDemand', 'cre_userRiskUnderstanding'
];
selectsToDefault.forEach(id => {
const el = document.getElementById(id);
if (el && el.options.length > 1 && el.selectedIndex === 0) { // If default is first option (e.g. "Good") and we want "Average"
// Find "average" or "moderate" or similar and set it, or keep current default from HTML
const optToSelect = Array.from(el.options).find(opt => opt.text.toLowerCase().includes('average') || opt.text.toLowerCase().includes('moderate'));
if (optToSelect) el.value = optToSelect.value;
}
});
if (!document.getElementById('cre_dealName')) {
console.error("Critical input 'cre_dealName' not found.");
}
});
