"use client";

import { createContext, useContext } from "react";
import useAuth from "@/hooks/use-auth";

const AuthContext = createContext<ReturnType<typeof useAuth> | null>(null);

type AuthProviderProps = {
    children: React.ReactNode;
};

export function AuthProvider({ children }: AuthProviderProps) {
    const auth = useAuth();
    return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
}

export function useAuthContext() {
    const ctx = useContext(AuthContext);
    if (!ctx) throw new Error("AuthProvider is missing");
    return ctx;
}
