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

/**
 * Change-event details handed to `setGroupValue` by child `<Toggle>` elements.
 * Mirrors `ToggleGroup.ChangeEventDetails` from the React port.
 */

/**
 * The value handed down by `<ToggleGroup>` to descendant `<Toggle>` elements.
 *
 * Solid 2 adaptations from Base UI React's `ToggleGroupContext`:
 *
 * - Reactive slots (`value`, `disabled`) are `Accessor<T>` so toggles pull on
 *   demand without tripping the top-level-reactive-read rule (RFC 01).
 * - `setGroupValue` is wrapped in `createStableCallback` by the group root so
 *   toggles can capture it into closures without re-wiring across renders.
 * - `orientation` is a plain value (not an accessor) — it feeds both the
 *   composite root's keyboard dispatcher and the data-orientation projection,
 *   and changing it mid-lifetime is not supported by Base UI React either.
 * - `present` is true when a real `<ToggleGroup>` is an ancestor; child
 *   toggles branch on it to decide whether to override their own
 *   `pressed`/`onPressedChange` behaviour.
 */

/**
 * No-op sentinel for when no `<ToggleGroup>` ancestor exists. Solid 2's
 * `useContext` throws `ContextNotFoundError` when the default is literal
 * `undefined` — same trap the checkbox-group and radio-group ports sidestep
 * via sentinel. Children branch on `.present` to decide whether to defer to
 * the group.
 */
const NOOP_TOGGLE_GROUP_CONTEXT = {
  value: () => [],
  setGroupValue: () => {},
  disabled: () => false,
  orientation: "horizontal",
  multiple: () => false,
  isValueInitialized: () => false,
  present: false
};

/**
 * Toggle-group context. Default is the NOOP sentinel so `useContext` never
 * throws. Children branch on `.present` to stay single-path.
 */
export const ToggleGroupContext = createContext(NOOP_TOGGLE_GROUP_CONTEXT);

/**
 * Read the surrounding `<ToggleGroup>` context. Always non-undefined — the
 * sentinel's `.present === false` signals no group. Child toggle branches on
 * `context.present` to decide behaviour.
 */
export function useToggleGroupContext() {
  return useContext(ToggleGroupContext);
}
//# sourceMappingURL=toggle-group-context.jsx.map
