import React, { useContext } from "react";
import classnames from "classnames";
import { Badge } from "../badge";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
import SidebarContext from "./SidebarContext";
const SidebarItem = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("sidebar-item", prefixCls);
  const parent = useContext(SidebarContext);
  if (!Object.prototype.hasOwnProperty.call(parent, "getActive")) {
    if (process.env.NODE_ENV !== "production") {
      console.error("[rc-ui-lib] <SidebarItem> must be a child component of <Sidebar>.");
    }
    return null;
  }
  const {
    dot,
    badge,
    title,
    disabled,
    index
  } = props;
  const selected = index === parent.getActive();
  const onClick = () => {
    var _a;
    if (props.disabled) {
      return;
    }
    (_a = props.onClick) == null ? void 0 : _a.call(props, index);
    parent.setActive(index);
  };
  return /* @__PURE__ */ React.createElement("div", {
    role: "tab",
    tabIndex: disabled ? void 0 : 0,
    className: classnames(bem({
      select: selected,
      disabled
    })),
    "aria-selected": selected,
    onClick
  }, /* @__PURE__ */ React.createElement(Badge, {
    dot,
    content: badge,
    className: classnames(bem("text"))
  }, props.children ? props.children : title));
};
var stdin_default = SidebarItem;
export {
  stdin_default as default
};
