// CSV Export utility
export const exportToCSV = (data: any[], filename: string) => {
if (!data.length) return;
const headers = Object.keys(data[0]);
const csvContent = [
headers.join(','),
...data.map(row =>
headers.map(header => {
const value = row[header];
// Escape quotes and wrap in quotes if contains comma
if (typeof value === 'string' && (value.includes(',') || value.includes('"'))) {
return `"${value.replace(/"/g, '""')}"`;
}
return value ?? '';
}).join(',')
)
].join('\n');
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
downloadBlob(blob, `${filename}.csv`);
};
// JSON Export utility
export const exportToJSON = (data: any, filename: string) => {
const jsonContent = JSON.stringify(data, null, 2);
const blob = new Blob([jsonContent], { type: 'application/json' });
downloadBlob(blob, `${filename}.json`);
};
// PDF Export utility (basic HTML to PDF using print)
export const exportToPDF = (elementId: string, filename: string) => {
const element = document.getElementById(elementId);
if (!element) return;
const printWindow = window.open('', '_blank');
if (!printWindow) return;
const styles = `
`;
printWindow.document.write(`
${filename}
${styles}
${filename}
Eksporteret: ${new Date().toLocaleString('da-DK')}
${element.innerHTML}
`);
printWindow.document.close();
printWindow.focus();
setTimeout(() => {
printWindow.print();
printWindow.close();
}, 250);
};
// Generate report data from dashboard
export const generateReportData = () => {
// Simulated data - in real app this would come from actual data sources
return {
summary: {
totalThreats: 1247,
criticalAlerts: 23,
resolvedIncidents: 892,
activeMonitors: 156,
},
threats: [
{ id: 'T001', name: 'Ransomware Attack', severity: 'Critical', status: 'Active', timestamp: new Date().toISOString() },
{ id: 'T002', name: 'DDoS Attempt', severity: 'High', status: 'Mitigated', timestamp: new Date().toISOString() },
{ id: 'T003', name: 'Phishing Campaign', severity: 'Medium', status: 'Investigating', timestamp: new Date().toISOString() },
{ id: 'T004', name: 'SQL Injection', severity: 'High', status: 'Blocked', timestamp: new Date().toISOString() },
{ id: 'T005', name: 'Brute Force', severity: 'Low', status: 'Monitored', timestamp: new Date().toISOString() },
],
regions: [
{ region: 'Nord Amerika', threats: 423, incidents: 34 },
{ region: 'Europa', threats: 312, incidents: 28 },
{ region: 'Asien', threats: 287, incidents: 41 },
{ region: 'Sydamerika', threats: 125, incidents: 12 },
{ region: 'Afrika', threats: 67, incidents: 8 },
{ region: 'Oceanien', threats: 33, incidents: 5 },
],
generatedAt: new Date().toISOString(),
};
};
// Helper to download blob
const downloadBlob = (blob: Blob, filename: string) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};