"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.NavDropdown = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _NavDropdown = _interopRequireDefault(require("react-bootstrap/lib/NavDropdown"));

var NavDropdown =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(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.default.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 = (0, _objectWithoutPropertiesLoose2.default)(_this$props2, ["tabIndex", "children", "testAutomationId"]);
    return _react.default.createElement(_NavDropdown.default, (0, _extends2.default)({
      "data-test-automation-id": testAutomationId
    }, props), children);
  };

  return NavDropdown;
}(_react.default.Component);

exports.NavDropdown = NavDropdown;
(0, _defineProperty2.default)(NavDropdown, "propTypes", {
  children: _propTypes.default.node.isRequired,
  testAutomationId: _propTypes.default.string,
  tabIndex: _propTypes.default.number,
  role: _propTypes.default.string
});
(0, _defineProperty2.default)(NavDropdown, "defaultProps", {
  testAutomationId: null,
  tabIndex: 0,
  role: 'menuitem'
});