import { forwardRef, isValidElement, cloneElement } from 'react';
import { usePopoverNextContext } from '../../hooks/usePopoverNextContext';
import { st, classes } from './Trigger.st.css.js';
import { useMergeRefs } from '@floating-ui/react';
const Trigger = forwardRef(function Trigger({ children: triggerElement, className }, propRef) {
    const { dataHook, context, interactions } = usePopoverNextContext();
    if (!isValidElement(triggerElement)) {
        throw new Error('<PopoverNext.Trigger /> children must be a valid React element');
    }
    const ref = useMergeRefs([
        context?.refs.setReference,
        propRef,
        triggerElement.ref,
    ]);
    const referenceProps = interactions.getReferenceProps({
        ...triggerElement.props,
        ref,
        'data-hook': `${dataHook}-trigger`,
        className: st(classes.root, triggerElement.props.className, className),
    });
    return cloneElement(triggerElement, {
        ...referenceProps,
        // @ts-ignore FIXME: this overrides onKeyDown for DatePicker to allow entering white space inside input
        onKeyDown: undefined,
    });
});
export default Trigger;
//# sourceMappingURL=Trigger.js.map