"use client";
import { Provider } from "react-redux";
import { ModalProvider } from "../lib/modal-system/ModalContext";
import { store } from "./store";
import { Toaster } from "react-hot-toast";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { injectStore } from "../utils/tokenService";

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 2 * 60 * 1000,
      gcTime: 10 * 60 * 1000,
      retry: 1,
      refetchOnWindowFocus: false,
      refetchOnReconnect: true,
    },
  },
});

export default function Providers({ children }: { children: React.ReactNode }) {
  injectStore(store);
  return (
    <Provider store={store}>
      <QueryClientProvider client={queryClient}>
        <ModalProvider>{children}</ModalProvider>
        <Toaster position="top-right" />
      </QueryClientProvider>
    </Provider>
  );
}
