Key Risk Factors Identified
${riskFactors.length > 0 ? riskFactors.map(f => `
-
${f.name}
${f.impact} Impact
`).join('') : `- No significant risk factors identified.
`}
`;
const gaugeFill = resultsContainer.querySelector('.risk-gauge-fill');
const rotation = (score / 100) * 180;
gaugeFill.style.transform = `rotate(${rotation}deg)`;
lucide.createIcons();
document.getElementById('download-pdf-btn').addEventListener('click', generatePdf);
};
const renderConfigTab = () => {
const configContent = document.getElementById('content-config');
if (!configContent) return;
const { weights, thresholds } = appData;
configContent.innerHTML = `
`;
document.getElementById('config-form').addEventListener('submit', handleConfigUpdate);
};
const handleConfigUpdate = (e) => {
e.preventDefault();
Object.keys(appData.weights).forEach(key => {
appData.weights[key] = parseFloat(document.getElementById(`weight-${key}`).value);
});
appData.thresholds.amount = parseFloat(document.getElementById('threshold-amount').value);
alert('Risk model configuration saved!');
};
const generatePdf = () => {
if (!analysisResult) return;
loadingOverlay.style.display = 'flex';
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
let y = 40;
pdf.setFontSize(18);
pdf.setFont('helvetica', 'bold');
pdf.text('Fraud Risk Analysis Report', pdf.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 30;
pdf.setFontSize(10);
pdf.setFont('helvetica', 'normal');
pdf.text(`Generated on: ${new Date().toLocaleDateString()}`, 40, y);
y += 30;
// Transaction Details Table
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Transaction Details', 40, y);
y += 15;
const transactionData = Object.entries(transactionInputs).map(([key, value]) => [key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()), value]);
pdf.autoTable({ startY: y, head: [['Parameter', 'Value']], body: transactionData, theme: 'striped' });
y = pdf.autoTable.previous.finalY + 30;
// Analysis Result
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Analysis Result', 40, y);
y += 20;
pdf.setFontSize(10);
pdf.setFont('helvetica', 'normal');
pdf.text(`Fraud Risk Score:`, 50, y);
pdf.setFont('helvetica', 'bold');
pdf.text(`${analysisResult.score} / 100`, 150, y);
y += 20;
pdf.setFont('helvetica', 'normal');
pdf.text(`Recommendation:`, 50, y);
pdf.setFont('helvetica', 'bold');
pdf.text(analysisResult.recommendation, 150, y);
y += 30;
// Risk Factors Table
if (analysisResult.riskFactors.length > 0) {
pdf.setFontSize(12);
pdf.setFont('helvetica', 'bold');
pdf.text('Key Risk Factors Identified', 40, y);
y += 15;
pdf.autoTable({
startY: y,
head: [['Factor', 'Assessed Impact']],
body: analysisResult.riskFactors.map(f => [f.name, f.impact]),
theme: 'grid',
headStyles: { fillColor: [220, 53, 69] } // Red header
});
}
pdf.save(`Fraud-Analysis-Report.pdf`);
loadingOverlay.style.display = 'none';
};
// --- TAB NAVIGATION & INITIALIZATION ---
const switchTab = (tabIndex) => {
activeTabIndex = tabIndex;
document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex));
document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex));
updateNavButtons();
};
const updateNavButtons = () => {
prevTabBtn.disabled = activeTabIndex === 0;
nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1;
};
const initializeUI = () => {
const tabs = [
{ name: 'Transaction Analysis', id: 'analysis' },
{ name: 'Risk Model Configuration', id: 'config' }
];
tabIdentifiers = tabs.map(t => t.id);
tabsContainer.innerHTML = tabs.map(tab => `
`).join('');
mainContent.innerHTML = tabs.map(tab => `
`).join('');
tabs.forEach((tab, index) => {
document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index));
});
renderAnalysisTab();
renderConfigTab();
switchTab(0);
lucide.createIcons();
};
initializeUI();
prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); });
nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); });
});