import { createContext, useContext, type ReactNode } from 'react';

export interface AuthConfigValue {
  appName: string;
  storagePrefix: string;
  loginRedirectPath: string;
  enableSignup: boolean;
  enableForgotPassword: boolean;
  logoUrl: string;
}

const defaultConfig: AuthConfigValue = {
  appName: 'Portal',
  storagePrefix: 'ema-auth',
  loginRedirectPath: '/dashboard',
  enableSignup: true,
  enableForgotPassword: true,
  logoUrl: '/brand/ema-white.png',
};

const AuthConfigContext = createContext<AuthConfigValue>(defaultConfig);

export function AuthConfigProvider({
  children,
  value,
}: {
  children: ReactNode;
  value: Partial<AuthConfigValue>;
}) {
  const merged = { ...defaultConfig, ...value };
  return (
    <AuthConfigContext.Provider value={merged}>
      {children}
    </AuthConfigContext.Provider>
  );
}

export function useAuthConfig() {
  return useContext(AuthConfigContext);
}
