export function useDebouncedSearch(onSearch: (value: string) => void, delay = 300) {
  let timeout: ReturnType<typeof setTimeout> | null = null

  const debouncedSearch = (value: string | number) => {
    const searchValue = typeof value === 'string' ? value : String(value)
    if (timeout) clearTimeout(timeout)
    timeout = setTimeout(() => onSearch(searchValue), delay)
  }

  return { debouncedSearch }
}
