/**
 * `<AlertDialog.Root>` — Solid 2 port of Base UI React's `AlertDialogRoot`
 * (`packages/react/src/alert-dialog/root/AlertDialogRoot.tsx`). Shares the
 * shared `useDialogRootInternal` helper with `<Dialog.Root>`; pins
 * `modal: true`, `disablePointerDismissal: true`, and `role:
 * "alertdialog"`.
 */

import { useDialogRootContext } from "../../dialog/dialog-root-context.jsx";
import { useDialogRootInternal } from "../../dialog/root/use-dialog-root-internal.jsx";
import { createControlledState } from "../../internals/create-controlled-state.jsx";
import { FloatingTree, useFloatingParentNodeId } from "../../internals/floating-ui/components/floating-tree.jsx";
import { readOption } from "../../internals/maybe-accessor.jsx";
import { createAlertDialog } from "../create-alert-dialog.jsx";

/** Imperative actions surface written into `actionsRef`. */

function AlertDialogRootComponent(props) {
  // Compose the headless AlertDialog primitive — pins `modal: true` and
  // `disablePointerDismissal: true` as fixed invariants of the
  // `alertdialog` role. The wrapper layers floating-UI, focus trap,
  // scroll lock, portal, and animation on top. `onOpenChange` is NOT
  // wired into the primitive — the wrapper's own `setOpen` is the sole
  // writer so it can thread reason/event details through the full
  // floating-UI pipeline.
  // Controlled / uncontrolled open state (Base UI `open` / `defaultOpen`
  // contract) — see `<Dialog.Root>` for the reference wiring.
  const [resolvedOpen, setUncontrolledOpen] = createControlledState({
    controlled: () => {
      const controlled = readOption(props.open);
      return controlled === undefined ? undefined : Boolean(controlled);
    },
    default: () => readOption(props.defaultOpen),
    fallback: false,
    name: "<AlertDialog.Root>",
    state: "open"
  });
  const alertDialogPrimitive = createAlertDialog({
    open: resolvedOpen
  });
  return useDialogRootInternal(props, {
    role: "alertdialog",
    // AlertDialog's primitive surfaces `modal` and
    // `disablePointerDismissal` as literal `true` (fixed invariants).
    // Adapt to `DialogRootInternalApi`'s accessor shape.
    api: {
      open: alertDialogPrimitive.open,
      modal: () => alertDialogPrimitive.modal,
      disablePointerDismissal: () => alertDialogPrimitive.disablePointerDismissal
    },
    setUncontrolledOpen
  });
}

/**
 * Groups all parts of the alert dialog. Doesn't render its own HTML
 * element.
 */
export function AlertDialogRoot(props) {
  if (useDialogRootContext(true) != null || useFloatingParentNodeId() != null) {
    return <AlertDialogRootComponent {...props} />;
  }
  return <FloatingTree>
			<AlertDialogRootComponent {...props} />
		</FloatingTree>;
}
//# sourceMappingURL=alert-dialog-root.jsx.map
