"use client"

import * as React from "react"
import { Provider as JotaiProvider } from "jotai"
import { ThemeProvider as NextThemesProvider } from "next-themes"
import { NuqsAdapter } from "nuqs/adapters/next/app"
import { SessionProvider } from "next-auth/react";
import { CacheProvider } from '@emotion/react';

import { TooltipProvider } from "@/components/ui/tooltip"
import createEmotionCache from './createEmotionCashe';


const cache = createEmotionCache();


export function ThemeProvider({
  children,
  ...props
}: React.ComponentProps<typeof NextThemesProvider>) {
  return (
    <JotaiProvider>
      <CacheProvider value={cache}>

        <NextThemesProvider {...props}>
          <TooltipProvider delayDuration={0}>
            <NuqsAdapter>
              <SessionProvider>
                {children}
              </SessionProvider>
            </NuqsAdapter>
          </TooltipProvider>
        </NextThemesProvider>
      </CacheProvider>

    </JotaiProvider>
  )
}
