"use client";
import * as x from "react";
import { a as h } from "./useRenderElement-DNB2vtF1.js";
import { u as P } from "./useOnFirstRender-B4aruaIA.js";
import { u as R, g as D, h as I, i as O } from "./DialogTrigger-C5WbKc3Z.js";
import { jsx as v } from "react/jsx-runtime";
function k(u) {
  const {
    children: o,
    open: t,
    defaultOpen: n = !1,
    onOpenChange: d,
    onOpenChangeComplete: g,
    disablePointerDismissal: r = !1,
    modal: a = !0,
    actionsRef: c,
    handle: f,
    triggerId: s,
    defaultTriggerId: i = null
  } = u, l = R(!0), p = !!l, e = h(() => f?.store ?? new D({
    open: n,
    openProp: t,
    activeTriggerId: i,
    triggerIdProp: s,
    modal: a,
    disablePointerDismissal: r,
    nested: p
  })).current;
  P(() => {
    t === void 0 && e.state.open === !1 && n === !0 && e.update({
      open: !0,
      activeTriggerId: i
    });
  }), e.useControlledProp("openProp", t), e.useControlledProp("triggerIdProp", s), e.useSyncedValues({
    disablePointerDismissal: r,
    nested: p,
    modal: a
  }), e.useContextCallback("onOpenChange", d), e.useContextCallback("onOpenChangeComplete", g);
  const C = e.useState("payload");
  I({
    store: e,
    actionsRef: c,
    parentContext: l?.store.context
  });
  const m = x.useMemo(() => ({
    store: e
  }), [e]);
  return /* @__PURE__ */ v(O.Provider, {
    value: m,
    children: typeof o == "function" ? o({
      payload: C
    }) : o
  });
}
export {
  k as D
};
