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

/**
 * Reasons a preview card's open state can change. Mirrors Base UI React's
 * `PreviewCardRoot.ChangeEventReason` union.
 */

/** Public projected state — surfaces via `data-*` attrs on the root/parts. */

/**
 * `instant` is the string flag that Base UI emits as `data-instant` on the
 * popup / arrow / positioner so CSS can disable animations for specific
 * programmatic transitions.
 *
 * Only `"dismiss"` and `"focus"` are emitted on preview cards (no delay-group
 * instant-phase, since preview-card has no delay-group integration).
 */

/**
 * Context shape shared between `<PreviewCard.Root>` and every preview-card
 * sub-part. Every reactive field is an `Accessor<T>` so consumers don't need
 * to guard against top-level reactive reads.
 */

/**
 * Solid 2's `useContext` throws `ContextNotFoundError` when the resolved
 * value is `undefined`, so the "no provider" sentinel is `null` here — the
 * helper below turns that into the Base UI error.
 */
export const PreviewCardRootContext = createContext(null);

/**
 * Read the current `<PreviewCard.Root>` context. Throws unless `optional` is
 * `true`.
 */

export function usePreviewCardRootContext(optional) {
  const context = useContext(PreviewCardRootContext);
  if (context == null && !optional) {
    throw new Error("Base UI: PreviewCardRootContext is missing. PreviewCard parts must be placed within <PreviewCard.Root>.");
  }
  return context;
}
//# sourceMappingURL=preview-card-root-context.jsx.map
