import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import ReactBootstrapNavDropdown from 'react-bootstrap/lib/NavDropdown';
export var NavDropdown =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(NavDropdown, _React$Component);

  function NavDropdown() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = NavDropdown.prototype;

  _proto.componentDidMount = function componentDidMount() {
    this.addAccessibility();
  };

  _proto.componentDidUpdate = function componentDidUpdate() {
    this.addAccessibility();
  };

  _proto.addAccessibility = function addAccessibility() {
    var _this$props = this.props,
        tabIndex = _this$props.tabIndex,
        role = _this$props.role;
    var node = ReactDOM.findDOMNode(this);
    node.setAttribute('role', 'presentation');
    node.querySelector('.dropdown-toggle').setAttribute('tabindex', tabIndex);
    node.querySelector('.dropdown-toggle').setAttribute('role', role);
  };

  _proto.render = function render() {
    var _this$props2 = this.props,
        tabIndex = _this$props2.tabIndex,
        children = _this$props2.children,
        testAutomationId = _this$props2.testAutomationId,
        props = _objectWithoutPropertiesLoose(_this$props2, ["tabIndex", "children", "testAutomationId"]);

    return React.createElement(ReactBootstrapNavDropdown, _extends({
      "data-test-automation-id": testAutomationId
    }, props), children);
  };

  return NavDropdown;
}(React.Component);

_defineProperty(NavDropdown, "propTypes", {
  children: PropTypes.node.isRequired,
  testAutomationId: PropTypes.string,
  tabIndex: PropTypes.number,
  role: PropTypes.string
});

_defineProperty(NavDropdown, "defaultProps", {
  testAutomationId: null,
  tabIndex: 0,
  role: 'menuitem'
});