import { createContext, useContext } from "solid-js";
import { createDefaultValidityData, DEFAULT_FIELD_ROOT_STATE, DEFAULT_FIELD_STATE_ATTRIBUTES } from "./field-constants.jsx";

// Re-export the shapes callers traditionally imported from this module so
// we don't break any existing barrel consumers.

export { createDefaultValidityData, DEFAULT_FIELD_ROOT_STATE, DEFAULT_FIELD_STATE_ATTRIBUTES, DEFAULT_VALIDITY_STATE, getCombinedFieldValidityData } from "./field-constants.jsx";

/**
 * Validate function signature exposed by `<Field.Root validate>`. Mirrors
 * React: the consumer receives the current value plus a snapshot of every
 * sibling field's value (keyed by field name) and returns a string / list
 * of strings / `null` synchronously, or a Promise resolving to the same.
 */

/**
 * Registration payload a control pushes into `<Field.Root>`. Mirrors React's
 * `FieldControlRegistration`.
 */

/**
 * Mutable-by-design ref the field root uses to track whether the user has
 * interacted with the control (typed, cleared, etc). Exposed so validation
 * code can suppress "required" errors until the user has actually touched
 * the field — see `useFieldValidation.getState()`. Plain mutable object; do
 * NOT put a signal in here.
 */

/**
 * Props-factory return shape produced by `useFieldValidation`. Consumers
 * splat these onto their element (the root element + the native input).
 *
 * Kept as a plain object-builder rather than a reactive memo because Solid
 * already tracks the individual accessors the builders read from.
 */

/**
 * The value handed down by `<Field.Root>` to its children.
 *
 * Every reactive entry is an `Accessor<T>` so that consumers pull the latest
 * value on demand and don't need to worry about top-level reactive reads.
 * Setters are plain functions (most of them wrapped through
 * `createStableCallback` so they're safe to capture in refs/closures).
 *
 * When `<Field.Root>` is absent, consumers receive {@link NOOP_FIELD_CONTEXT}
 * which behaves like "no field" — accessors return defaults, setters do
 * nothing.
 */

const NOOP = () => {};
const NOOP_VALIDATION = {
  getValidationProps: (props = {}) => props,
  getInputValidationProps: (props = {}) => props,
  inputRef: {
    current: null
  },
  commit: async () => {
    // Intentional no-op — without a real field root there's no validity
    // signal to commit into.
  }
};
export const NOOP_FIELD_CONTEXT = {
  invalid: () => false,
  name: () => undefined,
  disabled: () => false,
  validityData: () => createDefaultValidityData(),
  setValidityData: NOOP,
  touched: () => DEFAULT_FIELD_STATE_ATTRIBUTES.touched,
  setTouched: NOOP,
  dirty: () => DEFAULT_FIELD_STATE_ATTRIBUTES.dirty,
  setDirty: NOOP,
  filled: () => DEFAULT_FIELD_STATE_ATTRIBUTES.filled,
  setFilled: NOOP,
  focused: () => DEFAULT_FIELD_STATE_ATTRIBUTES.focused,
  setFocused: NOOP,
  state: () => DEFAULT_FIELD_ROOT_STATE,
  validate: () => undefined,
  validationMode: () => "onSubmit",
  validationDebounceTime: () => 0,
  shouldValidateOnChange: () => false,
  markedDirtyRef: {
    current: false
  },
  registerFieldControl: NOOP,
  validation: NOOP_VALIDATION,
  present: false
};

/**
 * Context carrying the field-root state. Use `<FieldContext value={...}>` to
 * provide it (Solid 2's context-as-provider pattern).
 */
export const FieldContext = createContext(NOOP_FIELD_CONTEXT);

/**
 * Read the current `<Field.Root>` context. Returns the noop context when the
 * component is not wrapped in a field — callers can branch on `.present`.
 *
 * Named after React's `useFieldRootContext`.
 */
export function useFieldRootContext() {
  return useContext(FieldContext);
}
//# sourceMappingURL=field-context.jsx.map
