import React, { createContext, useContext } from "react";
import { useSessionManager } from "./session";

const SessionContext = createContext<ReturnType<typeof useSessionManager> | null>(null);

export function SessionProvider({ children }: { children: React.ReactNode }) {
  const manager = useSessionManager();
  return <SessionContext.Provider value={manager}>{children}</SessionContext.Provider>;
}

export function useSession() {
  const context = useContext(SessionContext);
  if (!context) {
    throw new Error("useSession must be used within SessionProvider");
  }
  return context;
}
