import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { MenuContext } from './menu-context';
import { SubMenuContext } from './sub-menu-context';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var MenuItem = function (props) {
    var _a;
    var _b = props.disabled, disabled = _b === void 0 ? false : _b, index = props.index, className = props.className, style = props.style, children = props.children, onClick = props.onClick, customisedCls = props.prefixCls, otherProps = __rest(props, ["disabled", "index", "className", "style", "children", "onClick", "prefixCls"]);
    var menuContext = useContext(MenuContext);
    var subMenuContext = useContext(SubMenuContext);
    var inlineIndent = menuContext.inlineIndent, mode = menuContext.mode;
    var _c = subMenuContext.level, level = _c === void 0 ? 1 : _c, onMenuItemClick = subMenuContext.onMenuItemClick;
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('menu-item', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, (_a = {},
        _a[prefixCls + "_disabled"] = disabled,
        _a[prefixCls + "_active"] = menuContext.index === index,
        _a));
    var onItemClick = function (e) {
        if (disabled) {
            return;
        }
        onClick && onClick(e);
        onMenuItemClick && onMenuItemClick();
        if (menuContext.onSelect && typeof index === 'string') {
            menuContext.onSelect(index);
        }
    };
    return (React.createElement("li", __assign({}, otherProps, { key: index, role: "menuitem", className: cls, style: __assign({ paddingLeft: mode === 'inline' ? level * inlineIndent : undefined }, style), onClick: onItemClick }), children));
};
MenuItem.displayName = 'MenuItem';
export default MenuItem;
//# sourceMappingURL=menu-item.js.map