/** * Component: Flag Configuration Row * Documentation: documentation/phase3/ranking-algorithm.md * * Allows configuration of indexer flag bonuses/penalties with visual slider feedback */ 'use client'; import React from 'react'; import { IndexerFlagConfig } from '@/lib/utils/ranking-algorithm'; import { TrashIcon } from '@heroicons/react/24/outline'; interface FlagConfigRowProps { config: IndexerFlagConfig; onChange: (config: IndexerFlagConfig) => void; onRemove: () => void; } export function FlagConfigRow({ config, onChange, onRemove }: FlagConfigRowProps) { const exampleBase = 85; const bonusPoints = exampleBase * (config.modifier / 100); const finalScore = exampleBase + bonusPoints; // Get color for modifier percentage display const getModifierColor = (modifier: number): string => { if (modifier < -50) return 'text-red-700 dark:text-red-400'; if (modifier < 0) return 'text-red-600 dark:text-red-500'; if (modifier === 0) return 'text-gray-600 dark:text-gray-400'; if (modifier > 50) return 'text-green-700 dark:text-green-400'; return 'text-green-600 dark:text-green-500'; }; // Get slider gradient based on current value const getSliderBackground = (modifier: number): string => { const normalizedPosition = ((modifier + 100) / 200) * 100; // -100 to 100 → 0% to 100% // Create gradient that fills from left up to current position // Red on left, yellow in middle, green on right return `linear-gradient(to right, #ef4444 0%, #ef4444 ${Math.max(0, normalizedPosition - 5)}%, #fbbf24 50%, #10b981 ${Math.min(100, normalizedPosition + 5)}%, #10b981 100%)`; }; return (
{/* Flag Name Input */}
onChange({ ...config, name: e.target.value })} placeholder="e.g. Freeleech" className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-gray-100" />
{/* Score Modifier Slider */}
-100%
onChange({ ...config, modifier: parseInt(e.target.value) })} className="w-full h-2 rounded-lg appearance-none cursor-pointer slider-custom" style={{ background: getSliderBackground(config.modifier), }} />
+100% {config.modifier > 0 ? '+' : ''}{config.modifier}%
{/* Dynamic Help Text */}

Example: Base score of {exampleBase} with "{config.name || 'this flag'}" {' → '} = 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'}> {bonusPoints >= 0 ? '+' : ''}{bonusPoints.toFixed(1)} bonus points {bonusPoints < 0 && finalScore < 50 && ( {' '}⚠️ Would disqualify (final: {finalScore.toFixed(1)} < 50) )}

{/* Remove Button */}
); }