import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext } from 'react';
import cls from 'clsx';
import Badge from '../badge';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

const SidebarItem = _a => {
  var {
    children
  } = _a,
      props = __rest(_a, ["children"]);

  const {
    parent,
    index
  } = props;
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('sidebar-item', prefixCls);

  const onClick = () => {
    var _a;

    if (props.disabled) {
      return;
    }

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

  const {
    dot,
    badge,
    title,
    disabled
  } = props;
  const selected = index === parent.getActive();
  return _jsx("div", {
    children: _jsx("a", Object.assign({
      className: cls(bem({
        select: selected,
        disabled
      })),
      onClick: onClick
    }, {
      children: _jsx(Badge, Object.assign({
        dot: dot,
        content: badge,
        className: cls(bem('text'))
      }, {
        children: title
      }))
    }))
  });
};

export default SidebarItem;