import React, { createRef } from 'react';
import { OutsideClickListener } from '../outside-click-listener';
import { Popper } from '../react-popper';
import AnimatedMenuContent from './animated-menu-content';
import { jsx as _jsx } from "react/jsx-runtime";
export default class PopperDropdownWrapper extends React.Component {
  defaultPopperModifiers = [{
    name: 'offset',
    options: {
      offset: [0, 4]
    }
  }];
  popper = /*#__PURE__*/createRef();
  render() {
    const {
      closeDropdown,
      placement,
      anchorRef,
      open,
      openedWithKeyboard,
      modifiers = [],
      contentClassName,
      children,
      useCloseTransition,
      setParentRef,
      wrapperContentTestId,
      wrapperContentId,
      forceUpdatePopperAfterOpen = false,
      shouldCloseOnEsc = false
    } = this.props;
    return /*#__PURE__*/_jsx(Popper, {
      "test-id": "dropdown",
      placement: placement,
      anchorEl: anchorRef,
      open: open,
      transition: true,
      popperModifiers: [...this.defaultPopperModifiers, ...modifiers],
      rootEl: this.popper,
      forceUpdateAfterOpen: forceUpdatePopperAfterOpen,
      children: ({
        transitionProps
      }) => /*#__PURE__*/_jsx(OutsideClickListener, {
        onClickOutside: closeDropdown,
        ref: this.popper,
        shouldCloseOnEsc: shouldCloseOnEsc,
        children: /*#__PURE__*/_jsx(AnimatedMenuContent, {
          ...transitionProps,
          className: contentClassName,
          useCloseTransition: useCloseTransition,
          setParentRef: setParentRef,
          wrapperContentTestId: wrapperContentTestId,
          wrapperContentId: wrapperContentId,
          children: typeof children === 'function' ? children({
            closeDropdown,
            isOpen: open,
            openedWithKeyboard,
            anchorElement: anchorRef
          }) : children
        })
      })
    });
  }
}