import { useState, useMemo } from 'react';
import type { DriverLeaderboardItemViewModel } from '@/lib/view-models/DriverLeaderboardItemViewModel';

/**
 * useDriverSearch
 * 
 * Client-side hook for UX-only search filtering.
 * This is view-only transformation, not business logic.
 */
export function useDriverSearch(drivers: DriverLeaderboardItemViewModel[]) {
  const [searchQuery, setSearchQuery] = useState('');

  const filteredDrivers = useMemo(() => {
    if (!searchQuery) return drivers;
    
    const query = searchQuery.toLowerCase();
    return drivers.filter(driver => {
      return (
        driver.name.toLowerCase().includes(query) ||
        driver.nationality.toLowerCase().includes(query)
      );
    });
  }, [drivers, searchQuery]);

  return {
    searchQuery,
    setSearchQuery,
    filteredDrivers,
  };
}