'use strict';

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var PropTypes = require('prop-types');
var React = require('react');
var react = require('@carbon/react');
var classnames = require('classnames');
var Settings = require('../../constants/Settings.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded = ["children", "isFiltering", "testId", "className"];
var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  children: PropTypes__default.default.node.isRequired,
  isFiltering: PropTypes__default.default.bool.isRequired,
  className: PropTypes__default.default.string
};
var defaultProps = {
  className: ''
};
var FilterableSideNavMenu = function FilterableSideNavMenu(_ref) {
  var children = _ref.children,
    isFiltering = _ref.isFiltering,
    testId = _ref.testId,
    className = _ref.className,
    myProps = _objectWithoutProperties__default.default(_ref, _excluded);
  // Unfortunately there is other way to set tabindex
  // without modifying the Carbon SideNavMenu source code.
  // TODO: create carbon issue for that
  var callbackRef = React.useCallback(function (menuElement) {
    if (menuElement !== null && isFiltering) {
      menuElement.setAttribute('tabIndex', -1);
    }
  }, [isFiltering]);
  var sideNavMenu = /*#__PURE__*/React__default.default.createElement(react.SideNavMenu, _extends__default.default({
    "data-testid": testId,
    ref: callbackRef,
    defaultExpanded: isFiltering,
    isSideNavExpanded: true,
    className: classnames__default.default(className, _defineProperty__default.default({}, "".concat(iotPrefix, "--side-nav__item--is-filtering"), isFiltering))
  }, myProps), children);
  return sideNavMenu;
};
FilterableSideNavMenu.propTypes = propTypes;
FilterableSideNavMenu.defautProps = defaultProps;
FilterableSideNavMenu.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "FilterableSideNavMenu",
  "props": {
    "children": {
      "description": "",
      "type": {
        "name": "node"
      },
      "required": true
    },
    "isFiltering": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "className": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    }
  }
};
var FilterableSideNavMenu$1 = FilterableSideNavMenu;

module.exports = FilterableSideNavMenu$1;
