// [nexus] Hook for reading the current Nexus mode from settings
import { useQuery } from "@tanstack/react-query";
import { fetchNexusSettings, type NexusMode } from "../api/hardware";
import { queryKeys } from "../lib/queryKeys";

export interface UseNexusModeResult {
  mode: NexusMode;
  isLoading: boolean;
  isAssistantEnabled: boolean;
}

export function useNexusMode(): UseNexusModeResult {
  const { data, isLoading } = useQuery({
    queryKey: queryKeys.nexus.settings,
    queryFn: () => fetchNexusSettings(),
    staleTime: 5 * 60 * 1000,
    retry: 1,
  });

  const mode: NexusMode = data?.mode ?? "both";
  const isAssistantEnabled = mode !== "project_builder";

  return { mode, isLoading, isAssistantEnabled };
}
