var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef } from "react";
import { Slot } from "../../utils/components/slot/Slot.js";
import { composeEventHandlers } from "../../utils/helpers/index.js";
import { useMergeRefs } from "../../utils/hooks/index.js";
import { useDialogContext } from "../root/DialogRoot.context.js";
/**
 * @see 🏷️ {@link DialogTriggerProps}
 * @example
 * ```jsx
 *  <Dialog>
 *    <Dialog.Trigger>
 *      <Button>Open dialog</Button>
 *    </Dialog.Trigger>
 *  </Dialog>
 * ```
 */
const DialogTrigger = forwardRef((_a, forwardedRef) => {
    var { children, onClick } = _a, restProps = __rest(_a, ["children", "onClick"]);
    const { open, setOpen, setTriggerElement, popupId } = useDialogContext();
    const mergedRefs = useMergeRefs(forwardedRef, setTriggerElement);
    return (React.createElement(Slot, Object.assign({ type: "button" }, restProps, { ref: mergedRefs, onClick: composeEventHandlers(onClick, (event) => setOpen(!open, event.nativeEvent)), "aria-haspopup": "dialog", "aria-controls": open ? popupId : undefined }), children));
});
export { DialogTrigger };
//# sourceMappingURL=DialogTrigger.js.map