"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");
var _usePopoverNextContext = require("../../hooks/usePopoverNextContext");
var _TriggerSt = require("./Trigger.st.css.js");
var _react2 = require("@floating-ui/react");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Trigger = /*#__PURE__*/(0, _react.forwardRef)(function Trigger(_ref, propRef) {
  var {
    children: triggerElement,
    className
  } = _ref;
  var {
    dataHook,
    context,
    interactions
  } = (0, _usePopoverNextContext.usePopoverNextContext)();
  if (! /*#__PURE__*/(0, _react.isValidElement)(triggerElement)) {
    throw new Error('<PopoverNext.Trigger /> children must be a valid React element');
  }
  var ref = (0, _react2.useMergeRefs)([context == null ? void 0 : context.refs.setReference, propRef, triggerElement.ref]);
  var referenceProps = interactions.getReferenceProps(_objectSpread(_objectSpread({}, triggerElement.props), {}, {
    ref,
    'data-hook': "".concat(dataHook, "-trigger"),
    className: (0, _TriggerSt.st)(_TriggerSt.classes.root, triggerElement.props.className, className)
  }));
  return /*#__PURE__*/(0, _react.cloneElement)(triggerElement, _objectSpread(_objectSpread({}, referenceProps), {}, {
    // @ts-ignore FIXME: this overrides onKeyDown for DatePicker to allow entering white space inside input
    onKeyDown: undefined
  }));
});
var _default = exports.default = Trigger;
//# sourceMappingURL=Trigger.js.map