"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class AnimatedMenuContent extends _react.default.Component {
  static defaultProps = {
    useCloseTransition: true,
    setParentRef: () => {},
    wrapperContentTestId: ''
  };
  constructor(props) {
    super(props);
    this.state = {
      mounted: false
    };
    this.setWrapperRef = this.setWrapperRef.bind(this);
  }
  componentDidMount() {
    this.setState({
      mounted: true
    });
  }
  componentDidUpdate(prevProps) {
    const {
      open,
      useCloseTransition,
      onExited
    } = this.props;
    if (open || !prevProps.open) {
      return;
    }
    if (useCloseTransition) {
      this.contentRef?.addEventListener('transitionend', this.onTransitionEnd.bind(this));
    } else {
      onExited();
    }
  }
  onTransitionEnd(e) {
    if (e.target.isSameNode(this.contentRef)) {
      this.props.onExited();
    }
  }
  setWrapperRef(node) {
    this.contentRef = node;
    this.props.setParentRef(this.contentRef);
  }
  scrollBarPresent() {
    return this.contentRef && this.contentRef?.clientHeight !== this.contentRef?.scrollHeight;
  }
  render() {
    const {
      open,
      children,
      className,
      wrapperContentTestId,
      wrapperContentId
    } = this.props;
    return (
      /*#__PURE__*/
      // eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
      (0, _jsxRuntime.jsx)("div", {
        onClick: e => {
          e.stopPropagation();
        },
        ref: this.setWrapperRef,
        "test-id": wrapperContentTestId,
        id: wrapperContentId,
        className: (0, _classnames.default)('dropdown-menu-react', className, {
          'animated-in': this.state.mounted && open,
          'animated-out': this.state.mounted && !open,
          'scroll-bar-present': this.state.mounted && open && this.scrollBarPresent()
        }),
        children: children
      })
    );
  }
}
exports.default = AnimatedMenuContent;