/** * Bot Traffic chart header: model multi-select + time-range/date picker * (extracted unchanged from dashboard-analytics.tsx — P2-2.1). Rendered via * the BotTrafficChart renderHeader slot; all state stays in the parent. */ import type { BotFilterContext } from '../bot-traffic-chart'; import type { TimeRangeType } from './constants'; import { __, sprintf } from '../../lib/i18n'; interface TimeRangeFilterProps { filterContext: BotFilterContext; timeRange: TimeRangeType; setTimeRange: (range: TimeRangeType) => void; startDate: string; setStartDate: (date: string) => void; endDate: string; setEndDate: (date: string) => void; customStartDate: string; setCustomStartDate: (date: string) => void; customEndDate: string; setCustomEndDate: (date: string) => void; showDatePicker: boolean; setShowDatePicker: (open: boolean) => void; showModelDropdown: boolean; setShowModelDropdown: (open: boolean) => void; } export function TimeRangeFilter({ filterContext, timeRange, setTimeRange, startDate, setStartDate, endDate, setEndDate, customStartDate, setCustomStartDate, customEndDate, setCustomEndDate, showDatePicker, setShowDatePicker, showModelDropdown, setShowModelDropdown, }: TimeRangeFilterProps) { const { activeBots, allBots, botLogos, toggleBot, selectAllBots, clearAllBots } = filterContext; const isDropdownOpen = showModelDropdown; const setIsDropdownOpen = setShowModelDropdown; const availableBots = allBots; // The chart may also count bots this dropdown does not list, so both the // label and the logo strip describe the listed models only. const activeBotsArray = availableBots.filter((bot) => activeBots.has(bot)); const allListedSelected = availableBots.length > 0 && activeBotsArray.length === availableBots.length; // Get display text for the dropdown button const getDisplayText = () => { if (activeBotsArray.length === 0) return __('Select Models', 'llmagnet-llm-txt-generator'); if (allListedSelected) return __('All Models', 'llmagnet-llm-txt-generator'); if (activeBotsArray.length === 1) return activeBotsArray[0]; /* translators: %d: number of selected models. */ return sprintf(__('%d Models', 'llmagnet-llm-txt-generator'), activeBotsArray.length); }; return ( <>

{__('Bot Traffic', 'llmagnet-llm-txt-generator')}

{/* Bot Filter Multi-Select Dropdown with logos */}
{/* Selected bot logos - overlapping circles */} {activeBotsArray.length > 0 && (
{activeBotsArray.slice(0, 5).map((bot, index) => ( {bot} ))} {activeBotsArray.length > 5 && ( +{activeBotsArray.length - 5} )}
)} {/* Dropdown button */} {isDropdownOpen && (
setIsDropdownOpen(false)} > {/* All Models option */}
{ if (allListedSelected) { clearAllBots(); } else { selectAllBots(); } }} > {}} aria-label={__('All Models', 'llmagnet-llm-txt-generator')} className="w-4 h-4 text-purple-600 rounded border-gray-300 focus:ring-purple-500" /> {__('All Models', 'llmagnet-llm-txt-generator')}
{/* Individual bot options */} {allBots.map(bot => (
toggleBot(bot)} > {}} aria-label={bot} className="w-4 h-4 rounded border-gray-300 focus:ring-purple-500 text-purple-600" /> {bot} {bot}
))}
)}
{/* Time Range Button with Picker */}
{/* Display button showing selected range */} {/* Date Range Picker Popup */} {showDatePicker && (

{__('Select Date Range', 'llmagnet-llm-txt-generator')}

{/* Quick select tags */}
{/* Divider */}
{/* Custom date inputs */}

{__('Custom Range', 'llmagnet-llm-txt-generator')}

setCustomStartDate(e.target.value)} max={customEndDate || undefined} className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" style={{ border: '1px solid #d1d5db' }} />
setCustomEndDate(e.target.value)} min={customStartDate || undefined} max={new Date().toISOString().split('T')[0]} className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500" style={{ border: '1px solid #d1d5db' }} />
{/* Apply custom range button */}
)}
); }