import { createContext, useContext } from "solid-js";
import { createPopupCore } from "../internals/create-popup-core.jsx";
import { SNAPSHOT_KEYS, snapshotKeys } from "../internals/observability/snapshot.jsx";

/**
 * Why the alert dialog's open state changed.
 *
 * Alert dialogs cannot be dismissed by an outside press or Escape without
 * an explicit action, so those reasons are excluded from the public surface.
 *
 * - `"trigger-press"` — trigger was clicked or keyboard-activated.
 * - `"close-button"` — `<AlertDialog.Close>` / an action button was pressed.
 * - `"imperative"` — `ad.setOpen()` called programmatically.
 */

/**
 * Options for {@link createAlertDialog}.
 */

/**
 * Public API returned by {@link createAlertDialog}.
 */

const AlertDialogContext = createContext(null);

/**
 * Read the nearest {@link AlertDialogApi}. Throws unless `optional` is true.
 */

export function useAlertDialog(optional) {
  const ctx = useContext(AlertDialogContext);
  if (ctx == null && !optional) {
    throw new Error("Base UI: useAlertDialog() must be called inside an <ad.Provider>.");
  }
  return ctx;
}

/**
 * Headless primitive for an alert-dialog compound. Always modal, always
 * disables outside-press dismissal — both are fixed invariants of the
 * ARIA `alertdialog` role. DOM machinery lives in `<AlertDialog.Root>`.
 */
export function createAlertDialog(options) {
  const core = createPopupCore({
    open: options.open,
    disabled: options.disabled,
    onOpenChange: options.onOpenChange
  });
  const api = {
    open: core.open,
    disabled: core.disabled,
    modal: true,
    disablePointerDismissal: true,
    setOpen: core.setOpen,
    toggle: core.toggle,
    Provider: props => <AlertDialogContext value={api}>{props.children}</AlertDialogContext>
  };
  api[SNAPSHOT_KEYS] = ALERT_DIALOG_SNAPSHOT_KEYS;
  return api;
}
const ALERT_DIALOG_SNAPSHOT_KEYS = snapshotKeys("open", "disabled");
//# sourceMappingURL=create-alert-dialog.jsx.map
