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

/**
 * Reason string attached to every `onValueChange` event details object.
 * Matches Base UI React's `RadioGroup.ChangeEventReason`.
 */

/**
 * Shape of the details bag handed to `onValueChange`. The consumer may call
 * `details.cancel()` on the uncontrolled branch to veto the internal write.
 */

/**
 * State exposed by `<RadioGroup>`. Inherits the surrounding `<Field.Root>`
 * state so the shared `data-valid` / `data-touched` / `data-dirty` /
 * `data-filled` / `data-focused` / `data-invalid` projection flows through.
 */

/**
 * Context value consumed by child `<Radio.Root>` elements. Every reactive
 * slot is exposed as an `Accessor<T>` so descendants pull the latest value
 * on demand — keeps Solid 2's no-top-level-reactive-reads rule (RFC 01)
 * satisfied.
 *
 * Shape diverges from the React port: React stores a plain object + triggers
 * re-renders; Solid needs live accessors per slot so child radios stay
 * reactive without a memo ping-pong.
 */

const NOOP = () => {};

/**
 * Sentinel returned when a `<Radio.Root>` renders outside a `<RadioGroup>`.
 * Every setter is a no-op and every accessor returns "nothing". Callers
 * branch on `.present` to decide whether to fall back to their standalone
 * path (e.g. the radio's own consumer-owned signal for checked state).
 */
export const NOOP_RADIO_GROUP_CONTEXT = {
  checkedValue: () => undefined,
  setCheckedValue: NOOP,
  disabled: () => false,
  readOnly: () => false,
  required: () => false,
  name: () => undefined,
  form: () => undefined,
  touched: () => false,
  setTouched: NOOP,
  present: false
};

/**
 * Context carrying the current `<RadioGroup>` state. Provided via Solid 2's
 * context-as-provider pattern (`<RadioGroupContext value={...}>`).
 */
export const RadioGroupContext = createContext(NOOP_RADIO_GROUP_CONTEXT);

/**
 * Read the nearest `<RadioGroup>` context. Returns {@link NOOP_RADIO_GROUP_CONTEXT}
 * when there is no group ancestor — callers can branch on `.present` to
 * decide between "group owns the state" and standalone fallback paths.
 */
export function useRadioGroupContext() {
  return useContext(RadioGroupContext);
}
//# sourceMappingURL=radio-group-context.jsx.map
