/**
 * `<Dialog.Root>` — Solid 2 port of Base UI React's `DialogRoot`
 * (`packages/react/src/dialog/root/DialogRoot.tsx`). A thin wrapper
 * around `useDialogRootInternal` (shared with `<AlertDialog.Root>`).
 */

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 { createDialog } from "../create-dialog.jsx";
import { useDialogRootContext } from "../dialog-root-context.jsx";
import { useDialogRootInternal } from "./use-dialog-root-internal.jsx";

/**
 * Imperative actions surface written into `actionsRef` on `<Dialog.Root>`.
 * Mirrors React's `DialogRoot.Actions`.
 */

function DialogRootComponent(props) {
  // Controlled / uncontrolled open state (Base UI `open` / `defaultOpen`
  // contract): the `open` prop wins while its resolved value is defined;
  // otherwise an internal signal (seeded once from `defaultOpen`) backs
  // the state and the root's `setOpen` writes it.
  const [resolvedOpen, setUncontrolledOpen] = createControlledState({
    controlled: () => {
      const controlled = readOption(props.open);
      return controlled === undefined ? undefined : Boolean(controlled);
    },
    default: () => readOption(props.defaultOpen),
    fallback: false,
    name: "<Dialog.Root>",
    state: "open"
  });

  // Compose the headless Dialog primitive — owns `open`, `modal`, and
  // `disablePointerDismissal`. 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.
  const dialogPrimitive = createDialog({
    open: resolvedOpen,
    modal: () => readOption(props.modal) ?? true,
    disablePointerDismissal: () => readOption(props.disablePointerDismissal) ?? false
  });
  return useDialogRootInternal(props, {
    role: "dialog",
    api: dialogPrimitive,
    setUncontrolledOpen
  });
}

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