import { createContext, useContext } from 'react';

import type { RuntimeConfig, User } from './types';

export interface AppContextValue {
  user: User | null;
  config: RuntimeConfig | null;
  refreshBootstrap: () => Promise<void>;
  logout: () => Promise<void>;
}

export const AppContext = createContext<AppContextValue | null>(null);

export function useAppContext() {
  const context = useContext(AppContext);
  if (!context) throw new Error('useAppContext must be used inside AppContext.Provider');
  return context;
}
