'use client';

import React, { createContext, useContext } from 'react';
import { SessionProvider } from 'next-auth/react';
import { useAuth } from '@/hooks/useAuth';
import { ThemeProvider } from './ThemeProvider';

const AuthContext = createContext<any>(null);

function AuthInner({ children }: { children: React.ReactNode }) {
    const auth = useAuth();
    return (
        <AuthContext.Provider value={auth}>
            <ThemeProvider>{children}</ThemeProvider>
        </AuthContext.Provider>
    );
}

export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
    return (
        <SessionProvider>
            <AuthInner>{children}</AuthInner>
        </SessionProvider>
    );
};

export function useAuthContext() {
    return useContext(AuthContext);
}
