`;
// Assets for theme
themeDetailsHtml += '
';
} else {
themeDetailsHtml += '';
// Risks for theme
themeDetailsHtml += '';
themeDiv.innerHTML += themeDetailsHtml;
summaryInvestmentThemesEl.appendChild(themeDiv);
});
}
}
// --- Tab Navigation & Saving ---
function showTab(tabIndex) {
// Save data from current tab before switching (except for summary tab)
if (currentTab === 0) saveMacroOutlooks();
else if (currentTab === 1) saveInvestmentThemes();
else if (currentTab === 2) saveThemeAssets();
else if (currentTab === 3) saveThemeRisks();
currentTab = tabIndex;
tabLinks.forEach((link, index) => link.classList.toggle('active', index === currentTab));
tabContents.forEach((content, index) => content.classList.toggle('active', index === currentTab));
prevBtn.style.display = currentTab === 0 ? 'none' : 'inline-block';
nextBtn.style.display = currentTab === totalTabs - 1 ? 'none' : 'inline-block';
// Render content for newly selected tab if it depends on previous tabs' data
if (currentTab === 2) renderThemeAssets(); // Assets depend on themes
else if (currentTab === 3) renderThemeRisks(); // Risks depend on themes
else if (currentTab === 4) renderSummary(); // Summary depends on all
}
prevBtn.addEventListener('click', () => { if (currentTab > 0) showTab(currentTab - 1); });
nextBtn.addEventListener('click', () => { if (currentTab < totalTabs - 1) showTab(currentTab + 1); });
tabLinks.forEach((link, index) => {
link.addEventListener('click', () => showTab(index));
});
// --- PDF Generation ---
downloadPdfBtn.addEventListener('click', async () => {
if (typeof window.html2canvas === 'undefined' || typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert("PDF generation libraries are not loaded.");
return;
}
const { jsPDF: JsPDFConstructor } = window.jspdf;
const pdf = new JsPDFConstructor('p', 'pt', 'a4');
const pdfContentElement = toolContainer.querySelector('#gmisp-strategySummaryReport');
if(pdfHeaderEl) pdfHeaderEl.style.display = 'block';
if(pdfDateEl) {
pdfDateEl.textContent = `Report Generated: ${new Date().toLocaleString()}`;
pdfDateEl.style.display = 'block';
}
toolContainer.classList.add('gmisp-pdf-view'); // Apply PDF-specific styles
try {
const canvas = await html2canvas(pdfContentElement, { scale: 2, useCORS: true, logging: false, width: pdfContentElement.scrollWidth, windowWidth: pdfContentElement.scrollWidth });
const imgData = canvas.toDataURL('image/png');
const imgProps = pdf.getImageProperties(imgData);
const pdfPageWidth = pdf.internal.pageSize.getWidth();
const pdfPageHeight = pdf.internal.pageSize.getHeight();
const margin = 40; // points
const contentWidth = pdfPageWidth - (margin * 2);
const contentHeight = (imgProps.height * contentWidth) / imgProps.width;
let currentPosition = 0;
let remainingImgHeight = contentHeight;
pdf.addImage(imgData, 'PNG', margin, margin + currentPosition, contentWidth, contentHeight);
remainingImgHeight -= (pdfPageHeight - (margin * 2));
while (remainingImgHeight > 0) {
currentPosition -= (pdfPageHeight - (margin*2));
pdf.addPage();
pdf.addImage(imgData, 'PNG', margin, currentPosition + margin, contentWidth, contentHeight);
remainingImgHeight -= (pdfPageHeight - (margin*2));
}
pdf.save('Global_Macro_Strategy_Plan.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("An error occurred during PDF generation.");
} finally {
if(pdfHeaderEl) pdfHeaderEl.style.display = 'none';
if(pdfDateEl) pdfDateEl.style.display = 'none';
toolContainer.classList.remove('gmisp-pdf-view');
}
});
// --- Initialization ---
function init() {
renderMacroOutlooks(); // For initial example or empty state
renderInvestmentThemes();
showTab(0); // Show first tab
}
init();
});
Asset Expression:
'; if (theme.assets && theme.assets.length > 0) { themeDetailsHtml += '| Asset Class | Instrument/Market | Direction | Justification |
|---|---|---|---|
| ${asset.assetClass || 'N/A'} | ${asset.instrument || 'N/A'} | ${asset.direction || 'N/A'} | ${asset.justification || 'N/A'} |
No specific assets or instruments defined for this theme.
'; } themeDetailsHtml += 'Risk Assessment:
'; if (theme.risks) { themeDetailsHtml += `Key Risks: ${theme.risks.keyRisks || 'N/A'}
Alternative Scenarios: ${theme.risks.altScenarios || 'N/A'}
Mitigation: ${theme.risks.mitigation || 'N/A'}
`; } else { themeDetailsHtml += 'No risk assessment defined for this theme.
'; } themeDetailsHtml += '