/**
 * amis-ui v6.14.0-beta.1
 * Copyright 2018-2025 fex
 */

import { __assign } from 'tslib';
import React__default from 'react';
import { themeable } from 'amis-core';
import { Item } from 'rc-menu';
import { MenuContext } from './MenuContext.js';
import { Icon } from '../icons.js';

/**
 * @file PanelMenu
 * @description 导航子菜单
 * @author fex
 */
/**
 * 面板菜单 菜单项组件
 */
function PanelMenuItem(props) {
    var cx = props.cx, isGroupHeader = props.isGroupHeader, link = props.link, label = props.label;
    var context = React__default.useContext(MenuContext);
    var onPanelMenuClick = context.onPanelMenuClick;
    function onMenuClick(_a) {
        var domEvent = _a.domEvent, keyPath = _a.keyPath;
        onPanelMenuClick === null || onPanelMenuClick === void 0 ? void 0 : onPanelMenuClick({ key: props.id || '', domEvent: domEvent, props: props, keyPath: keyPath });
    }
    return (
    // eventKey不传会影响rc-menu构建keyPath，影响父级菜单选中状态
    React__default.createElement(Item, __assign({ key: props.id, eventKey: props.id }, props, { onClick: onMenuClick }),
        React__default.createElement("div", { className: cx('Nav-Menu-panel-item') },
            !!(link === null || link === void 0 ? void 0 : link.icon) && (React__default.createElement("span", { className: cx("Nav-Menu-panel-item__icon-wrapper") },
                React__default.createElement(Icon, { className: cx("Nav-Menu-panel-item__icon"), icon: link === null || link === void 0 ? void 0 : link.icon }))),
            React__default.createElement("span", { className: cx('Nav-Menu-panel-item__label', isGroupHeader ? 'is-group-header' : '') }, label))));
}
/**
 * 面板菜单 菜单分组
 */
function PanelMenuGroup(props) {
    var cx = props.cx, _a = props.children, children = _a === void 0 ? [] : _a;
    return (React__default.createElement("div", { className: cx('Nav-Menu-panel-group') }, children.map(function (child) {
        var _a;
        return (React__default.createElement("div", { key: child.id, className: cx('Nav-Menu-panel-group-item') },
            React__default.createElement("div", { className: cx('Nav-Menu-panel-group-item__header') },
                React__default.createElement(PanelMenuItem, __assign({ cx: cx }, child, { isGroupHeader: true }))), (_a = child === null || child === void 0 ? void 0 : child.children) === null || _a === void 0 ? void 0 :
            _a.map(function (subChild) { return (React__default.createElement(PanelMenuItem, __assign({ key: subChild.id, cx: cx }, subChild))); })));
    })));
}
/**
 * 面板菜单 菜单列表
 */
function PanelMenuList(props) {
    var cx = props.cx, _a = props.children, children = _a === void 0 ? [] : _a;
    return (React__default.createElement("div", { className: cx('Nav-Menu-panel-list') }, children.map(function (child) { return (React__default.createElement(PanelMenuItem, __assign({ key: child.id, cx: cx }, child))); })));
}
/**
 * 面板菜单
 */
function PanelMenu(props) {
    var cx = props.classnames, _a = props.children, children = _a === void 0 ? [] : _a;
    // 是否有三级菜单
    var hasThirdLevelMenu = children === null || children === void 0 ? void 0 : children.some(function (child) { var _a; return (_a = child === null || child === void 0 ? void 0 : child.children) === null || _a === void 0 ? void 0 : _a.length; });
    return (React__default.createElement("section", { key: props.id, className: cx('Nav-Menu-panel-wrapper') }, hasThirdLevelMenu ? (React__default.createElement(PanelMenuGroup, { cx: cx, children: children })) : (React__default.createElement(PanelMenuList, { cx: cx, children: children }))));
}
var PanelMenu$1 = themeable(PanelMenu);

export { PanelMenu$1 as default };
