import { useState, useMemo } from 'react';

export function useLocalSearch<T>(data: T[], searchFields: (keyof T)[], _delay = 0) {
  const [searchTerm, setSearchTerm] = useState('');

  const filteredData = useMemo(() => {
    if (!searchTerm.trim()) return data;
    const lower = searchTerm.toLowerCase();
    return data.filter(item =>
      searchFields.some(field => {
        const val = item[field];
        return typeof val === 'string' && val.toLowerCase().includes(lower);
      })
    );
  }, [data, searchTerm, searchFields]);

  return { searchTerm, setSearchTerm, filteredData };
}
