import type { AppRouter } from "@nontara/server/shared";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createTRPCClient, httpBatchLink } from "@trpc/client";
import type React from "react";
import { TRPCProvider } from "@/lib/trpc";
import { ThemeProvider } from "./providers/ThemeProvider";

const queryClient = new QueryClient();
const trpcClient = createTRPCClient<AppRouter>({
	links: [
		httpBatchLink({
			url: `${import.meta.env.VITE_SERVER_URL}/trpc`,
		}),
	],
});

export default function Providers({ children }: { children: React.ReactNode }) {
	return (
		<ThemeProvider storageKey="theme-mode">
			<QueryClientProvider client={queryClient}>
				<TRPCProvider trpcClient={trpcClient} queryClient={queryClient}>
					{children}
				</TRPCProvider>
			</QueryClientProvider>
		</ThemeProvider>
	);
}
