import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter } from "react-router-dom";
import type { PropsWithChildren } from "react";
import { setAccessTokenGetter } from "@shared/api/client";
import { useAuthStore } from "@modules/auth/store/authStore";
import { AuthBootstrap } from "./AuthBootstrap";

const queryClient = new QueryClient();

setAccessTokenGetter(() => useAuthStore.getState().accessToken);

export function AppProviders({ children }: PropsWithChildren): JSX.Element {
  return (
    <QueryClientProvider client={queryClient}>
      <BrowserRouter>
        <AuthBootstrap>{children}</AuthBootstrap>
      </BrowserRouter>
    </QueryClientProvider>
  );
}
