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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var RcMenu = require('rc-menu');
var MenuContext = require('./MenuContext.js');
var icons = require('../icons.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
/**
 * 面板菜单 菜单项组件
 */
function PanelMenuItem(props) {
    var cx = props.cx, isGroupHeader = props.isGroupHeader, link = props.link, label = props.label;
    var context = React__default["default"].useContext(MenuContext.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，影响父级菜单选中状态
    _J$X_(RcMenu.Item, tslib.__assign({ key: props.id, eventKey: props.id }, props, { onClick: onMenuClick }),
        _J$X_("div", { className: cx('Nav-Menu-panel-item') },
            !!(link === null || link === void 0 ? void 0 : link.icon) && (_J$X_("span", { className: cx("Nav-Menu-panel-item__icon-wrapper") },
                _J$X_(icons.Icon, { className: cx("Nav-Menu-panel-item__icon"), icon: link === null || link === void 0 ? void 0 : link.icon }))),
            _J$X_("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 (_J$X_("div", { className: cx('Nav-Menu-panel-group') }, children.map(function (child) {
        var _a;
        return (_J$X_("div", { key: child.id, className: cx('Nav-Menu-panel-group-item') },
            _J$X_("div", { className: cx('Nav-Menu-panel-group-item__header') },
                _J$X_(PanelMenuItem, tslib.__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 (_J$X_(PanelMenuItem, tslib.__assign({ key: subChild.id, cx: cx }, subChild))); })));
    })));
}
/**
 * 面板菜单 菜单列表
 */
function PanelMenuList(props) {
    var cx = props.cx, _a = props.children, children = _a === void 0 ? [] : _a;
    return (_J$X_("div", { className: cx('Nav-Menu-panel-list') }, children.map(function (child) { return (_J$X_(PanelMenuItem, tslib.__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 (_J$X_("section", { key: props.id, className: cx('Nav-Menu-panel-wrapper') }, hasThirdLevelMenu ? (_J$X_(PanelMenuGroup, { cx: cx, children: children })) : (_J$X_(PanelMenuList, { cx: cx, children: children }))));
}
var PanelMenu$1 = amisCore.themeable(PanelMenu);

exports["default"] = PanelMenu$1;
