"use client";

import { createContext, useContext } from "react";
import type { Brand } from "@/lib/brand";
import { getBrand } from "@/lib/brand";

const BrandContext = createContext<Brand | null>(null);

export function BrandProvider({
  brand,
  children,
}: {
  brand: Brand;
  children: React.ReactNode;
}) {
  return <BrandContext.Provider value={brand}>{children}</BrandContext.Provider>;
}

/** Resolved brand from provider (DB + env). Falls back to sync env brand outside provider. */
export function useBrand(): Brand {
  return useContext(BrandContext) ?? getBrand();
}
