import { useEffect, useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Shield, AlertTriangle, Activity, TrendingUp, TrendingDown, ExternalLink, RefreshCw, Clock, Globe, Server, Users, CheckCircle, XCircle, AlertCircle, Eye, Lock, Wifi, Zap, Info, Code, Database } from 'lucide-react'; import { useSecuritySimulation, SecurityEvent } from '@/hooks/useSecuritySimulation'; import { WidgetSchemaViewer } from './WidgetSchemaViewer'; import { widgetRegistry } from '@/lib/widgetRegistry'; interface WidgetDetailModalProps { isOpen: boolean; onClose: () => void; widget: { id: string; name: string; category: string; icon: React.ElementType; component: React.ReactNode; } | null; } // Widget descriptions const widgetDescriptions: Record = { 'soc-dashboard': 'Security Operations Center dashboard viser real-time oversigt over alle sikkerhedshændelser, trusler og systemstatus på tværs af infrastrukturen.', 'threat-map': 'Geografisk visualisering af aktive cyberangreb og trusselsaktivitet i realtid. Viser angrebskilder, mål og angrebstyper.', 'malware-detection': 'Real-time malware detektion og klassificering. Overvåger alle endpoints og netværkstrafik for kendte og ukendte trusler.', 'intrusion-detection': 'Intrusion Detection System (IDS) overvåger netværkstrafik for mistænkelig aktivitet og kendte angrebsmønstre.', 'ddos-monitor': 'DDoS beskyttelse og monitoring. Overvåger båndbredde, pakkerater og anvender automatisk mitigation ved angreb.', 'phishing-detector': 'Email sikkerhed med avanceret phishing detektion, URL analyse og attachment sandboxing.', 'dark-web-monitor': 'Overvåger dark web forums, markedspladser og paste sites for lækkede credentials og virksomhedsdata.', 'zero-day-alert': 'Overvåger for zero-day sårbarheder og nye CVEs der påvirker jeres infrastruktur.', 'threat-level': 'Samlet trusselsniveau baseret på global threat intelligence, interne alerts og systemstatus.', 'firewall': 'Next-generation firewall status med deep packet inspection, application control og intrusion prevention.', 'siem-alerts': 'Security Information and Event Management - korrelerer logs og events på tværs af hele infrastrukturen.', 'waf-status': 'Web Application Firewall beskytter web apps mod OWASP Top 10 og avancerede angreb.', 'vpn-status': 'VPN gateway status og connected users. Overvåger tunnels, performance og sikkerhed.', 'security-alerts': 'Samlet oversigt over alle kritiske sikkerhedsadvarsler der kræver øjeblikkelig handling.', }; const widgetActions: Record = { 'soc-dashboard': ['Eskalér til Tier 2', 'Bloker IP', 'Kør forensic scan'], 'threat-map': ['Aktivér GeoBlock', 'Rate Limiting', 'Kontakt ISP'], 'malware-detection': ['Isolér Endpoint', 'Kør Full Scan', 'Opdater Signatures'], 'intrusion-detection': ['Bloker Kilde IP', 'Opdater IDS Regler', 'Eksporter PCAP'], 'ddos-monitor': ['Aktivér Scrubbing', 'Whitelist IPs', 'Kontakt Upstream'], 'phishing-detector': ['Rapporter til CERT', 'Block Domain', 'Notify User'], 'dark-web-monitor': ['Force Password Reset', 'Notify Users', 'Enable MFA'], 'firewall': ['View Blocked IPs', 'Update Rules', 'Export Logs'], 'vpn-status': ['Disconnect User', 'View Sessions', 'Rotate Keys'], }; // Type for metrics type MetricStatus = 'good' | 'warning' | 'critical'; type MetricTrend = 'up' | 'down' | 'stable'; interface DynamicMetric { label: string; value: string; status?: MetricStatus; trend?: MetricTrend; } export const WidgetDetailModal = ({ isOpen, onClose, widget }: WidgetDetailModalProps) => { const simulation = useSecuritySimulation(1500); const [pulseMetric, setPulseMetric] = useState(null); // Pulse effect when metrics update useEffect(() => { if (isOpen) { const randomMetric = Math.floor(Math.random() * 4); setPulseMetric(randomMetric); const timeout = setTimeout(() => setPulseMetric(null), 500); return () => clearTimeout(timeout); } }, [simulation.socMetrics.activeIncidents, simulation.threatData.blockedAttacks, isOpen]); if (!widget) return null; const Icon = widget.icon; const description = widgetDescriptions[widget.id] || 'Dette sikkerhedsmodul overvåger og beskytter din infrastruktur i realtid.'; const actions = widgetActions[widget.id] || ['View Details', 'Configure', 'Export Report']; // Helper to get status const getStatus = (condition: boolean, ifTrue: MetricStatus, ifFalse: MetricStatus): MetricStatus => condition ? ifTrue : ifFalse; // Generate dynamic metrics based on widget type const getDynamicMetrics = (): DynamicMetric[] => { switch (widget.id) { case 'soc-dashboard': return [ { label: 'Aktive Incidents', value: String(simulation.socMetrics.activeIncidents), status: getStatus(simulation.socMetrics.activeIncidents > 3, 'critical', 'warning') }, { label: 'Løste (24h)', value: String(simulation.socMetrics.resolvedToday), status: 'good' as MetricStatus }, { label: 'MTTD', value: `${simulation.socMetrics.mttd} min`, trend: 'down' as MetricTrend }, { label: 'MTTR', value: `${simulation.socMetrics.mttr} min`, trend: 'down' as MetricTrend }, ]; case 'threat-map': return [ { label: 'Live Angreb', value: String(simulation.liveAttacks), status: 'warning' as MetricStatus }, { label: 'Blokerede IPs', value: simulation.networkMetrics.blockedIPs.toLocaleString(), status: 'good' as MetricStatus }, { label: 'Top Kilde', value: 'CN (34%)', status: 'warning' as MetricStatus }, { label: 'Traffic', value: `${simulation.networkMetrics.inboundGbps} Gbps`, trend: 'stable' as MetricTrend }, ]; case 'malware-detection': return [ { label: 'Detekteret (24h)', value: String(simulation.malwareMetrics.detected24h), status: 'warning' as MetricStatus }, { label: 'Ransomware', value: String(simulation.malwareMetrics.ransomware), status: getStatus(simulation.malwareMetrics.ransomware > 2, 'critical', 'warning') }, { label: 'Trojans', value: String(simulation.malwareMetrics.trojans), status: 'warning' as MetricStatus }, { label: 'Quarantined', value: String(simulation.malwareMetrics.quarantined), status: 'good' as MetricStatus }, ]; case 'firewall': return [ { label: 'Status', value: simulation.firewallMetrics.status.toUpperCase(), status: 'good' as MetricStatus }, { label: 'Blocked (24h)', value: simulation.firewallMetrics.blocked24h.toLocaleString(), status: 'good' as MetricStatus }, { label: 'Allowed', value: simulation.firewallMetrics.allowed24h.toLocaleString(), trend: 'stable' as MetricTrend }, { label: 'Rules', value: simulation.firewallMetrics.rulesActive.toLocaleString(), status: 'good' as MetricStatus }, ]; case 'ddos-monitor': { const ddosStatus: MetricStatus = simulation.networkMetrics.ddosStatus === 'normal' ? 'good' : simulation.networkMetrics.ddosStatus === 'elevated' ? 'warning' : 'critical'; return [ { label: 'Status', value: simulation.networkMetrics.ddosStatus.toUpperCase(), status: ddosStatus }, { label: 'Inbound', value: `${simulation.networkMetrics.inboundGbps} Gbps`, trend: 'stable' as MetricTrend }, { label: 'Packets/sec', value: `${(simulation.networkMetrics.packetsPerSec / 1000000).toFixed(2)}M`, trend: 'stable' as MetricTrend }, { label: 'Connections', value: simulation.networkMetrics.activeConnections.toLocaleString(), trend: 'up' as MetricTrend }, ]; } case 'vpn-status': return [ { label: 'Status', value: 'CONNECTED', status: 'good' as MetricStatus }, { label: 'Users Online', value: String(simulation.vpnUsers), trend: 'stable' as MetricTrend }, { label: 'Bandwidth', value: `${simulation.networkMetrics.outboundGbps} Gbps`, trend: 'up' as MetricTrend }, { label: 'Tunnels', value: '12', status: 'good' as MetricStatus }, ]; case 'threat-level': { const threatStatus: MetricStatus = simulation.threatData.level === 'LOW' ? 'good' : simulation.threatData.level === 'MEDIUM' ? 'warning' : 'critical'; const threatTrend: MetricTrend = simulation.threatData.score > 50 ? 'up' : 'down'; return [ { label: 'Threat Level', value: simulation.threatData.level, status: threatStatus }, { label: 'Risk Score', value: `${simulation.threatData.score}/100`, trend: threatTrend }, { label: 'Active Threats', value: String(simulation.threatData.activeThreats), status: getStatus(simulation.threatData.activeThreats > 2, 'warning', 'good') }, { label: 'Blocked', value: simulation.threatData.blockedAttacks.toLocaleString(), status: 'good' as MetricStatus }, ]; } case 'security-alerts': return [ { label: 'Active Alerts', value: String(simulation.socMetrics.activeIncidents + simulation.socMetrics.criticalAlerts), status: 'critical' as MetricStatus }, { label: 'Critical', value: String(simulation.socMetrics.criticalAlerts), status: 'critical' as MetricStatus }, { label: 'Warning', value: String(simulation.socMetrics.warningAlerts), status: 'warning' as MetricStatus }, { label: 'Info', value: String(simulation.socMetrics.infoAlerts), status: 'good' as MetricStatus }, ]; default: return [ { label: 'Status', value: 'ACTIVE', status: 'good' as MetricStatus }, { label: 'Last Check', value: '< 1 min', trend: 'stable' as MetricTrend }, { label: 'Health', value: `${simulation.complianceScore}%`, status: 'good' as MetricStatus }, { label: 'Uptime', value: '99.9%', status: 'good' as MetricStatus }, ]; } }; const metrics = getDynamicMetrics(); const getStatusColor = (status?: MetricStatus) => { switch (status) { case 'good': return 'text-green-400'; case 'warning': return 'text-yellow-400'; case 'critical': return 'text-red-400'; default: return 'text-primary'; } }; const getSeverityBadge = (severity: 'info' | 'warning' | 'critical') => { switch (severity) { case 'critical': return CRITICAL; case 'warning': return WARNING; default: return INFO; } }; const getTrendIcon = (trend?: 'up' | 'down' | 'stable') => { switch (trend) { case 'up': return ; case 'down': return ; default: return ; } }; return (
{widget.name} {widget.category.toUpperCase()}
LIVE
{/* Description */}

{description}

LIVE DATA SCHEMA {/* Widget Preview */}
REAL-TIME
{widget.component}
{/* Metrics Grid - Live updating */}

KEY METRICS ● Live

{metrics.map((metric, i) => (
{metric.label}
{metric.value} {metric.trend && getTrendIcon(metric.trend)}
))}
{/* Recent Events - Live feed */}

LIVE EVENT FEED ● Live

{simulation.events.slice(0, 5).map((event, i) => (
{event.time} {event.event} {getSeverityBadge(event.severity)}
))}
{/* Quick Actions */}

QUICK ACTIONS

{actions.map((action, i) => ( ))}
{/* Widget Schema / Metadata */}
Widget metadata definerer hvad denne widget kan og kræver i økosystemet
{widgetRegistry.get(widget.id) ? ( ) : (

Schema metadata er endnu ikke defineret for denne widget.

Tilføj widget til registret for at aktivere økosystem-integration.

)} {widgetRegistry.get(widget.id) && (
KOMPATIBLE WIDGETS
{widgetRegistry.findCompatible(widget.id).slice(0, 5).map(compatible => ( {compatible.name} ))} {widgetRegistry.findCompatible(widget.id).length === 0 && ( Ingen kompatible widgets fundet )}
)}
); }; export default WidgetDetailModal;