"use client";
import * as React from "react";
import { useRefWithInit } from "../../../../utils/esm/useRefWithInit.js";
import { useDialogRoot } from "../../dialog/root/useDialogRoot.js";
import { useDialogRootContext, DialogRootContext } from "../../dialog/root/DialogRootContext.js";
import { DialogStore } from "../../dialog/store/DialogStore.js";
import { jsx } from "react/jsx-runtime";
function AlertDialogRoot(props) {
  const {
    children,
    open: openProp,
    defaultOpen = false,
    onOpenChange,
    onOpenChangeComplete,
    actionsRef,
    handle,
    triggerId: triggerIdProp,
    defaultTriggerId: defaultTriggerIdProp = null
  } = props;
  const parentDialogRootContext = useDialogRootContext();
  const nested = Boolean(parentDialogRootContext);
  const store = useRefWithInit(() => {
    return handle?.store ?? new DialogStore({
      open: openProp ?? defaultOpen,
      activeTriggerId: triggerIdProp !== void 0 ? triggerIdProp : defaultTriggerIdProp,
      modal: true,
      disablePointerDismissal: true,
      nested,
      role: "alertdialog"
    });
  }).current;
  store.useControlledProp("open", openProp, defaultOpen);
  store.useControlledProp("activeTriggerId", triggerIdProp, defaultTriggerIdProp);
  store.useSyncedValue("nested", nested);
  store.useContextCallback("onOpenChange", onOpenChange);
  store.useContextCallback("onOpenChangeComplete", onOpenChangeComplete);
  const payload = store.useState("payload");
  useDialogRoot({
    store,
    actionsRef,
    parentContext: parentDialogRootContext?.store.context
  });
  const contextValue = React.useMemo(() => ({
    store
  }), [store]);
  return /* @__PURE__ */ jsx(DialogRootContext.Provider, {
    value: contextValue,
    children: typeof children === "function" ? children({
      payload
    }) : children
  });
}
export {
  AlertDialogRoot
};
//# sourceMappingURL=AlertDialogRoot.js.map
