+ {!layerEnabled ? (
+
+ {t('gtBacktest.layerOff')}
+
+ ) : (
+ <>
+
+ {(['operational', 'benchmark'] as TabId[]).map((tab) => (
+
+ ))}
+
+
+ {activeTab === 'benchmark' ? (
+ !benchmark?.enabled ? (
+
+ {t('gtBacktest.disabled')}
+
+ ) : loadingBenchmark && !benchmark.accuracy ? (
+
+ {t('gtBacktest.loading')}
+
+ ) : (
+ <>
+
+ {t('gtBacktest.benchmarkNote')}
+
+
+
+
+ {t('gtBacktest.accuracy')}
+
+
+ {pct(benchmark.accuracy)}
+
+
+
+
+ {t('gtBacktest.confidence')}
+
+
+ {pct(benchmark.confidence_rate)}
+
+
+
+
+
+ {t('gtBacktest.cases').replace('{count}', String(benchmark.total_cases))} ·{' '}
+ {t('gtBacktest.threshold').replace('{value}', benchmark.alert_threshold.toFixed(2))} ·{' '}
+ {t('gtBacktest.target').replace('{value}', pct(benchmark.target_confidence))}
+
+
+
+ TP {benchmark.true_positives}
+ TN {benchmark.true_negatives}
+ FP {benchmark.false_positives}
+ FN {benchmark.false_negatives}
+
+
+
+ {benchmark.meets_target ? (
+
+ ) : (
+
+ )}
+
+ {benchmark.meets_target
+ ? t('gtBacktest.meetsTarget')
+ : t('gtBacktest.belowTarget')}
+
+
+
+ {failures.length > 0 && (
+
+
+ {showFailures && (
+
+ {failures.map((row) => (
+
+ {row.name} ({row.kind})
+
+ ))}
+
+ )}
+
+ )}
+ >
+ )
+ ) : !rolling?.enabled && !micro?.enabled ? (
+
+ {t('gtBacktest.disabled')}
+
+ ) : (loadingRolling || loadingMicro) && !rolling?.latest && !micro?.regions_tracked ? (
+
+ {t('gtBacktest.operationalLoading')}
+
+ ) : (
+ <>
+
+
+ {t('gtBacktest.microTitle').toUpperCase()}
+
+ {micro?.enabled ? (
+ <>
+
+ {t('gtBacktest.microWindow')
+ .replace('{days}', String(micro.window_days))
+ .replace('{delta}', micro.ignition_delta.toFixed(2))}
+
+
+
+ {t('gtBacktest.microIgnitions').replace(
+ '{count}',
+ String(micro.ignition_count)
+ )}
+
+
+ {t('gtBacktest.microAlerted3d').replace(
+ '{count}',
+ String(micro.alerted_3d_count)
+ )}
+
+
+ {microRegions.length > 0 ? (
+
+ {microRegions.map((row) => (
+
+ {row.ignition && (
+
+ {t('gtBacktest.microIgnitionBadge')}
+
+ )}
+
+ {t('gtBacktest.microRegionLine')
+ .replace('{region}', row.region)
+ .replace('{spot}', pct(row.spot_risk))
+ .replace('{avg}', pct(row.risk_3d_avg))
+ .replace('{delta}', pct(row.risk_delta))}
+
+
+ ))}
+
+ ) : (
+
+ {t('gtBacktest.microEmpty')}
+
+ )}
+ >
+ ) : (
+
+ {t('gtBacktest.microEmpty')}
+
+ )}
+
+
+
+ {t('gtBacktest.tabOperational').toUpperCase()} — {t('gtBacktest.operationalTrend')}
+
+
+ {!rolling || rolling.weeks_stored === 0 ? (
+
+ {t('gtBacktest.operationalEmpty')}
+
+ ) : (
+ <>
+
+
+
+ {t('gtBacktest.accuracy')}
+
+
+ {latest?.scorable ? pct(latest.accuracy) : '—'}
+
+
+
+
+ {t('gtBacktest.confidence')}
+
+
+ {latest?.scorable ? pct(latest.confidence_rate) : '—'}
+
+
+
+
+
+ {t('gtBacktest.operationalWeeks')
+ .replace('{stored}', String(rolling.weeks_stored))
+ .replace('{scorable}', String(rolling.weeks_scorable))}
+ {latest
+ ? ` · ${t('gtBacktest.operationalLabeled')
+ .replace('{labeled}', String(latest.labeled))
+ .replace('{pending}', String(latest.pending))}`
+ : ''}
+
+
+ {latest && !latest.scorable && (
+
+ {t('gtBacktest.operationalMinLabels').replace(
+ '{count}',
+ String(rolling.min_labeled_per_week)
+ )}
+
+ )}
+
+ {latest?.scorable && (
+
+ TP {latest.true_positives}
+ TN {latest.true_negatives}
+ FP {latest.false_positives}
+ FN {latest.false_negatives}
+
+ )}
+
+ {(rolling.accuracy_series?.length ?? 0) > 0 && (
+
+
+ {t('gtBacktest.operationalTrend')}
+
+
+ {rolling.accuracy_series.map((point) => (
+
+ {point.week_id.replace('-W', 'w')}: {pct(point.accuracy)}
+
+ ))}
+
+
+ )}
+
+ {latest?.scorable && (
+
+ {rolling.meets_target ? (
+
+ ) : (
+
+ )}
+
+ {rolling.improving_vs_prior
+ ? t('gtBacktest.operationalImproving')
+ : t('gtBacktest.operationalFlat')}
+ {' · '}
+ {rolling.meets_target
+ ? t('gtBacktest.meetsTarget')
+ : t('gtBacktest.belowTarget')}
+
+
+ )}
+ >
+ )}
+ >
+ )}
+ >
+ )}
+