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

/**
 * The value handed down by `<CSPProvider>` to its descendants.
 *
 * `nonce` is an accessor so a parent that updates `props.nonce` is observed
 * by consumers without them needing to subscribe to an outer signal — this
 * keeps the shape consistent with the other Base UI internal contexts (see
 * `field-context.ts`) and avoids the top-level reactive-read warning in
 * Solid 2.
 *
 * `disableStyleElements` mirrors React Base UI's CSP context flag: when
 * `true`, components skip injecting inline `<style>` tags (e.g. the
 * scroll-area's disable-scrollbar stylesheet). Callers opt in when their
 * CSP forbids inline style elements even with a nonce, and provide the
 * styles through an external stylesheet instead.
 */

const NOOP_NONCE = () => undefined;
const NOOP_DISABLE_STYLE = () => false;
export const NOOP_CSP_CONTEXT = {
  nonce: NOOP_NONCE,
  disableStyleElements: NOOP_DISABLE_STYLE
};

/**
 * Context carrying the CSP nonce. Provide it with `<CSPContext value={...}>`
 * (Solid 2's context-as-provider pattern — there is no `.Provider`).
 */
export const CSPContext = createContext(NOOP_CSP_CONTEXT);

/**
 * Read the current CSP context. When no `<CSPProvider>` is above, returns
 * the noop context whose accessors yield sensible defaults (`undefined`
 * nonce, `false` disable-style-elements).
 */
export function useCSPContext() {
  return useContext(CSPContext);
}

/**
 * Convenience helper — read the nonce as an accessor, decoupled from the
 * shape of the context value. Consumers that only need the nonce should
 * prefer this so they aren't re-subscribed when unrelated CSP fields are
 * added to the context in the future.
 */
export function useCspNonce() {
  return useCSPContext().nonce;
}

/**
 * Convenience helper — read the `disableStyleElements` flag as an accessor.
 */
export function useCspDisableStyleElements() {
  return useCSPContext().disableStyleElements;
}
//# sourceMappingURL=csp-context.jsx.map
