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

/**
 * Shape of the state surface exposed by `<Switch.Root>` to its compound parts
 * (currently just `<Switch.Thumb>`). Mirrors Base UI React's
 * `SwitchRootState` — it extends the shared `FieldRootState` (valid / touched
 * / dirty / filled / focused / disabled) with the switch-specific flags.
 */

/**
 * The value handed down by `<Switch.Root>` to its descendants.
 *
 * Solid 2 adaptations vs. React:
 *
 * - Reactive reads are exposed as `Accessor<T>` so descendants never perform a
 *   top-level reactive read on the context object itself (RFC 01).
 * - `state` is also an accessor so `<Switch.Thumb>` can drive its own
 *   `data-*` projection through `renderElement` without re-deriving.
 */

/**
 * Switch 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 SwitchRootContext = createContext(null);

/**
 * Read the `<Switch.Root>` context. Throws when the caller forgot to wrap
 * the subtree in `<Switch.Root>`.
 */
export function useSwitchRootContext() {
  const context = useContext(SwitchRootContext);
  if (context == null) {
    throw new Error("Base UI: SwitchRootContext is missing. Switch parts must be placed within <Switch.Root>.");
  }
  return context;
}
//# sourceMappingURL=switch-root-context.jsx.map
