/**
 * amis-ui v6.12.0-beta.0
 * Copyright 2018-2025 fex
 */

'use strict';

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

var tslib = require('tslib');
var amisCore = require('amis-core');
var React = require('react');

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;
var ListMenu = /** @class */ (function (_super) {
    tslib.__extends(ListMenu, _super);
    function ListMenu() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ListMenu.prototype.renderItem = function (result, option, optionIndex) {
        var _this = this;
        var _a = this.props, cx = _a.classnames, itemRender = _a.itemRender, disabled = _a.disabled, getItemProps = _a.getItemProps, highlightIndex = _a.highlightIndex, selectedOptions = _a.selectedOptions; _a.mobileUI; var onSelect = _a.onSelect, testIdBuilder = _a.testIdBuilder;
        if (Array.isArray(option.children) && option.children.length) {
            var stackResult = {
                items: [],
                index: result.index
            };
            result.items.push(_J$X_("div", { className: cx('ListMenu-group'), key: optionIndex },
                _J$X_("div", { className: cx('ListMenu-groupLabel') }, itemRender(option)),
                option.children.reduce(function (result, option, index) {
                    return _this.renderItem(result, option, index);
                }, stackResult).items));
            result.index = stackResult.index;
            return result;
        }
        var index = result.index++;
        result.items.push(_J$X_("div", tslib.__assign({ className: cx('ListMenu-item', option.className, disabled || option.disabled ? 'is-disabled' : '', index === highlightIndex ? 'is-highlight' : '', ~(selectedOptions || []).indexOf(option) ? 'is-active' : ''), key: index, onClick: onSelect ? function (e) { return onSelect(e, option); } : undefined }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild(option.value || index).getTestId(), getItemProps({
            item: option,
            index: index
        })),
            _J$X_("div", { className: cx('ListMenu-itemLabel') }, itemRender(option))));
        return result;
    };
    ListMenu.prototype.render = function () {
        var _this = this;
        var _a = this.props, cx = _a.classnames, options = _a.options, placeholder = _a.placeholder, prefix = _a.prefix, children = _a.children, mobileUI = _a.mobileUI; _a.selectedOptions;
        var __ = this.props.translate;
        return (_J$X_("div", { className: cx('ListMenu', { 'is-mobile': mobileUI }) },
            prefix,
            Array.isArray(options) && options.length ? (options.reduce(function (result, option, index) {
                return _this.renderItem(result, option, index);
            }, {
                items: [],
                index: 0
            }).items) : (_J$X_("span", { className: cx('ListMenu-placeholder') }, __(placeholder))),
            children));
    };
    ListMenu.defaultProps = {
        placeholder: 'placeholder.noOption',
        itemRender: function (option) { return _J$X_(React__default["default"].Fragment, null, option.label); },
        getItemProps: function (props) { return null; }
    };
    return ListMenu;
}(React__default["default"].Component));
var ListMenu$1 = amisCore.themeable(amisCore.localeable(ListMenu));

exports.ListMenu = ListMenu;
exports["default"] = ListMenu$1;
