import { cn } from '@/lib/utils'; import { __, sprintf } from '../lib/i18n'; /** * Shared color-coded AI visibility score badge (adoption plan Phase 0.4). * * Used by the list-table column, Gutenberg panel, dashboard widget and * Elementor surfaces. Color bands are Lighthouse-style: * 0-49 red, 50-89 orange, 90-100 green; `null` renders a gray em dash * (score never computed yet). */ export interface ScoreBadgeProps { score: number | null; size?: 'sm' | 'md'; showFixButton?: boolean; /** Drawer deep-link (Admin_WP_Helper::drawer_url). Renders the Fix button as a link. */ fixUrl?: string; /** Alternative click handler when no URL navigation is wanted. */ onFixClick?: () => void; className?: string; } interface BandStyle { pill: string; dot: string; } function getBand(score: number): BandStyle { if (score >= 90) { return { pill: 'bg-green-50 text-green-700 border-green-200', dot: 'bg-green-500' }; } if (score >= 50) { return { pill: 'bg-orange-50 text-orange-700 border-orange-200', dot: 'bg-orange-500' }; } return { pill: 'bg-red-50 text-red-700 border-red-200', dot: 'bg-red-500' }; } export function ScoreBadge({ score, size = 'md', showFixButton = false, fixUrl, onFixClick, className, }: ScoreBadgeProps) { const sizeClasses = size === 'sm' ? 'h-5 px-1.5 text-xs gap-1' : 'h-6 px-2 text-sm gap-1.5'; const dotSize = size === 'sm' ? 'h-1.5 w-1.5' : 'h-2 w-2'; if (score === null) { return ( — ); } const clamped = Math.max(0, Math.min(100, Math.round(score))); const band = getBand(clamped); const fixVisible = showFixButton && clamped < 100 && (fixUrl || onFixClick); return ( {fixVisible && (fixUrl ? ( {__('Fix', 'llmagnet-llm-txt-generator')} ) : ( ))} ); }