'use client' import { useMemo } from 'react' import { TOMGeneratorState, GapAnalysisResult, DerivedTOM } from '@/lib/sdk/tom-generator/types' import { getControlById, getAllControls } from '@/lib/sdk/tom-generator/controls/loader' import { SDM_GOAL_LABELS, SDM_GOAL_DESCRIPTIONS, getSDMCoverageStats, MODULE_LABELS, getModuleCoverageStats, SDMGewaehrleistungsziel, TOMModuleCategory, } from '@/lib/sdk/tom-generator/sdm-mapping' interface TOMGapExportTabProps { state: TOMGeneratorState onRunGapAnalysis: () => void } function getScoreColor(score: number): string { if (score >= 75) return 'text-green-600' if (score >= 50) return 'text-yellow-600' return 'text-red-600' } function getScoreBgColor(score: number): string { if (score >= 75) return 'bg-green-50 border-green-200' if (score >= 50) return 'bg-yellow-50 border-yellow-200' return 'bg-red-50 border-red-200' } function getBarColor(score: number): string { if (score >= 75) return 'bg-green-500' if (score >= 50) return 'bg-yellow-500' return 'bg-red-500' } function downloadJSON(data: unknown, filename: string) { const json = JSON.stringify(data, null, 2) const blob = new Blob([json], { type: 'application/json' }) 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) } export function TOMGapExportTab({ state, onRunGapAnalysis }: TOMGapExportTabProps) { const gap = state.gapAnalysis as GapAnalysisResult | null | undefined const sdmGoals = useMemo(() => { const goals = Object.keys(SDM_GOAL_LABELS) as SDMGewaehrleistungsziel[] const allStats = getSDMCoverageStats(state.derivedTOMs) return goals.map(key => { const stats = allStats[key] || { total: 0, implemented: 0, partial: 0, missing: 0 } const total = stats.total || 1 const percent = Math.round((stats.implemented / total) * 100) return { key, label: SDM_GOAL_LABELS[key], description: SDM_GOAL_DESCRIPTIONS[key], stats, percent, } }) }, [state.derivedTOMs]) const modules = useMemo(() => { const moduleKeys = Object.keys(MODULE_LABELS) as TOMModuleCategory[] const allStats = getModuleCoverageStats(state.derivedTOMs) return moduleKeys.map(key => { const stats = allStats[key] || { total: 0, implemented: 0 } const total = stats.total || 1 const percent = Math.round((stats.implemented / total) * 100) return { key, label: MODULE_LABELS[key], stats: { ...stats, partial: 0, missing: total - stats.implemented }, percent, } }) }, [state.derivedTOMs]) const handleExportTOMs = () => { downloadJSON(state.derivedTOMs, `tom-export-${new Date().toISOString().slice(0, 10)}.json`) } const handleExportGap = () => { if (!gap) return downloadJSON(gap, `gap-analyse-${new Date().toISOString().slice(0, 10)}.json`) } return (
Fuehren Sie die Gap-Analyse aus, um Luecken in Ihren TOMs zu identifizieren.