import { useGlobalFilters } from '@cameleer/design-system';

/**
 * Returns the given interval when auto-refresh is enabled, or `false` when paused.
 * Use as `refetchInterval` in React Query hooks.
 */
export function useRefreshInterval(intervalMs: number): number | false {
  const { autoRefresh } = useGlobalFilters();
  return autoRefresh ? intervalMs : false;
}

/**
 * Returns `enabled` and `refetchInterval` tied to the AUTO/MANUAL toggle.
 * - AUTO: enabled=true, refetchInterval=intervalMs (fetch + poll)
 * - MANUAL: enabled=true, refetchInterval=false (fetch once, no polling)
 */
export function useLiveQuery(intervalMs: number) {
  const { autoRefresh } = useGlobalFilters();
  return {
    enabled: true,
    refetchInterval: autoRefresh ? intervalMs : false as number | false,
  };
}
