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

/**
 * Change-event details handed to `setValue` by child checkboxes / the
 * parent-indicator helper. Mirrors
 * `CheckboxGroup.ChangeEventDetails` from the React port.
 */

/**
 * The value handed down by `<CheckboxGroup>` to its descendant
 * `<Checkbox.Root>` elements.
 *
 * Solid 2 adaptations from Base UI React's `CheckboxGroupContext`:
 *
 * - Every reactive slot is an `Accessor<T>` so child checkboxes pull on
 *   demand without tripping the top-level-reactive-read rule (RFC 01).
 * - `setValue` is wrapped in `createStableCallback` by the group root so
 *   children can capture it into closures / refs without re-wiring.
 * - `parent` carries the `useCheckboxGroupParent` return value. Its own
 *   callbacks are stable too (wrapped inside the helper).
 * - `present` is true when a real `<CheckboxGroup>` is an ancestor; child
 *   checkboxes branch on it to decide whether to override their internal
 *   `checked`/`onClick` behaviour.
 */

/**
 * Sentinel used as the context's default so `useContext` returns a real
 * value instead of throwing a `ContextNotFoundError` (Solid 2 beta throws
 * when the default is literal `undefined`). Callers branch on `.present`
 * rather than the identity of this value.
 */
const NOOP_CHECKBOX_GROUP_CONTEXT = Object.freeze({
  present: false
});

/**
 * Checkbox-group context. The default is a frozen sentinel whose `.present`
 * is false, so `useCheckboxGroupContext` can always return a safe value and
 * children branch on `present` to decide whether to override their internal
 * behaviour.
 */
export const CheckboxGroupContext = createContext(NOOP_CHECKBOX_GROUP_CONTEXT);

/**
 * Read the surrounding `<CheckboxGroup>` context. Returns a noop (with
 * `present: false`) when no group is an ancestor — the child checkbox-root
 * branches on `.present` rather than nullishness.
 */
export function useCheckboxGroupContext() {
  return useContext(CheckboxGroupContext);
}
//# sourceMappingURL=checkbox-group-context.jsx.map
