var _excluded = ["children"];

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { useContext } from 'react';
import cls from 'clsx';
import Badge from '../badge';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var SidebarItem = function SidebarItem(_ref) {
  var children = _ref.children,
      props = _objectWithoutPropertiesLoose(_ref, _excluded);

  var parent = props.parent,
      index = props.index;

  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('sidebar-item', prefixCls),
      bem = _createNamespace[0];

  var onClick = function onClick() {
    if (props.disabled) {
      return;
    }

    props.onClick == null ? void 0 : props.onClick(index);
    parent.setActive(index);
  };

  var dot = props.dot,
      badge = props.badge,
      title = props.title,
      disabled = props.disabled;
  var selected = index === parent.getActive();
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("a", {
    className: cls(bem({
      select: selected,
      disabled: disabled
    })),
    onClick: onClick
  }, /*#__PURE__*/React.createElement(Badge, {
    dot: dot,
    content: badge,
    className: cls(bem('text'))
  }, title)));
};

export default SidebarItem;