import { lazy, Suspense, useEffect, useState } from 'react'; import { __, sprintf } from '../lib/i18n'; /** * WP dashboard (index.php) widget body (adoption plan Feature 3). * * Layout: score gauge row → 30d AI-visits trend → CTA footer. * * recharts is the heavy dependency here, so the trend chart * (BotTrafficChart) is lazy-loaded via dynamic import: the score row * paints first and the chart chunk loads afterwards, keeping the WP * dashboard's first paint light. */ const BotTrafficChart = lazy(() => import('./bot-traffic-chart').then((m) => ({ default: m.BotTrafficChart })) ); export interface WidgetData { overviewUrl: string; contentSettingsUrl: string; pluginUrl: string; restNamespace: string; llmsTxtExists: boolean; lastGenerated: string | null; } interface TimelineSummary { delta: number | null; trend: 'up' | 'down' | 'flat' | 'na' | string; } function gaugeColor(score: number): string { if (score >= 90) return '#22c55e'; if (score >= 50) return '#f97316'; return '#ef4444'; } /** Small SVG donut gauge, color-banded like ScoreBadge (red/orange/green). */ function ScoreGauge({ score }: { score: number | null }) { const size = 64; const stroke = 7; const r = (size - stroke) / 2; const circumference = 2 * Math.PI * r; const clamped = score === null ? 0 : Math.max(0, Math.min(100, Math.round(score))); const color = score === null ? '#d1d5db' : gaugeColor(clamped); return ( {score === null ? '—' : clamped} ); } function ChartSkeleton() { return