/**
 * hooks.ts — Re-Export Hub (Company hooks removed in Phase 1C)
 *
 * This file re-exports all hooks from their dedicated modules so that
 * existing imports `from '@/api/hooks'` continue to work without change.
 */

import { useQuery } from '@tanstack/react-query';

// ── Re-exports from dedicated modules ──
export * from './types';
export * from './auth';
export * from './users';
export * from './contacts';
export * from './roles';
export * from './groups';
export * from './audit';
export * from './notifications';
export * from './plugins';
export * from './settings';
export * from './attachments';
export * from './unifiedContacts';
export * from './automation';

// ── Search hook (uses dynamic import, kept inline) ──

export interface SearchResult {
  type: 'company' | 'contact' | 'mail' | 'file' | 'event';
  id: string;
  name: string;
  description?: string;
  url: string;
}

export function useGlobalSearch(query: string, entityTypes?: string[]) {
  return useQuery({
    queryKey: ['globalSearch', query, entityTypes],
    queryFn: async (): Promise<SearchResult[]> => {
      if (!query.trim()) return [];
      const { search } = await import('@/api/search');
      const response = await search(query, entityTypes, 20);
      return response.results || [];
    },
    enabled: query.trim().length > 0,
    staleTime: 30 * 1000,
  });
}
