'use client';

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

export interface AuthBranding {
  logoUrl: string | null;
  backgroundUrl: string | null;
  appName: string | null;
}

const AuthBrandingContext = createContext<AuthBranding | null>(null);

/**
 * Server-resolved branding injected at the auth route-group layout so
 * every BrandedAuthShell (no matter how nested) can pick it up without
 * each page re-fetching from system_settings. See `(auth)/layout.tsx`
 * and `(portal)/layout.tsx`.
 */
export function AuthBrandingProvider({
  branding,
  children,
}: {
  branding: AuthBranding | null;
  children: ReactNode;
}) {
  return <AuthBrandingContext.Provider value={branding}>{children}</AuthBrandingContext.Provider>;
}

export function useAuthBranding(): AuthBranding | null {
  return useContext(AuthBrandingContext);
}
