'use client';

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Toaster } from 'sonner';
import { useState } from 'react';
import { TooltipProvider } from '@/components/ui/tooltip';
import { SWRegistration } from './SWRegistration';

export function Providers({ children }: { children: React.ReactNode }) {
  const [queryClient] = useState(
    () =>
      new QueryClient({
        defaultOptions: {
          queries: {
            staleTime: 60 * 1000, // 1 minute
            refetchOnWindowFocus: false,
          },
        },
      })
  );

  return (
    <QueryClientProvider client={queryClient}>
      <TooltipProvider>
        <SWRegistration />
        {children}
      </TooltipProvider>
      <Toaster
        theme="dark"
        position="bottom-right"
        toastOptions={{
          classNames: {
            toast:
              '!bg-[#13131f] !border !border-white/8 !text-white/85 !rounded-xl !shadow-2xl !font-sans',
            title: '!text-sm !font-medium !text-white/85',
            description: '!text-xs !text-white/45',
            icon: '!mt-px',
            success: '!border-primary/25',
            error: '!border-red-500/25',
            warning: '!border-amber-400/25',
            info: '!border-blue-400/25',
          },
        }}
      />
    </QueryClientProvider>
  );
}
