"use client";

import { createContext, useContext } from "react";

export interface SiteBranding {
  site_title: string;
  site_logo: string | null;
  /** True while the fixed sample content is switched on (Settings > Extra). */
  demo_mode?: boolean;
}

const BrandingContext = createContext<SiteBranding | null>(null);

/**
 * Site title/logo, fetched server-side in the root layout alongside theme
 * settings - separate context from ThemeProvider since it's a different
 * concern (branding text/image, not appearance tokens), consumed by both
 * the login page and the dashboard sidebar so a Settings > General change
 * actually shows up somewhere besides the browser tab title.
 */
export function useSiteBranding(): SiteBranding {
  const context = useContext(BrandingContext);
  if (!context) {
    throw new Error("useSiteBranding must be used within a BrandingProvider");
  }
  return context;
}

export function BrandingProvider({
  branding,
  children,
}: {
  branding: SiteBranding;
  children: React.ReactNode;
}) {
  return <BrandingContext.Provider value={branding}>{children}</BrandingContext.Provider>;
}
