import { createContext, useContext } from "solid-js";

/**
 * Image-loading status reported by `<Avatar.Image>` into the root context so
 * that `<Avatar.Fallback>` can decide whether to render.
 *
 * - `idle`     — no image mounted yet (or src is absent)
 * - `loading`  — a real image has been attached and is fetching
 * - `loaded`   — the image's `onload` fired; the image is visible
 * - `error`    — the image's `onerror` fired (or src was empty)
 */

/**
 * Avatar root context. `createContext<T | null>(null)` + `== null` sentinel
 * — Solid 2's `useContext` throws `ContextNotFoundError` when
 * the default is `undefined`, which would shadow the intended Base UI error
 * message below.
 */
export const AvatarRootContext = createContext(null);

/**
 * Read the `<Avatar.Root>` context. Throws a descriptive error if the caller
 * forgot to wrap their subtree in `<Avatar.Root>` — matches Base UI React.
 */
export function useAvatarRootContext() {
  const context = useContext(AvatarRootContext);
  if (context == null) {
    throw new Error("Base UI: AvatarRootContext is missing. Avatar parts must be placed within <Avatar.Root>.");
  }
  return context;
}
//# sourceMappingURL=avatar-root-context.jsx.map
