/**
 * amis-ui v6.12.0-beta.0
 * 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 Collapse = require('../Collapse.js');
var CollapseGroup = require('../CollapseGroup.js');
var SearchBox = require('../SearchBox.js');
var TooltipWrapper = require('../TooltipWrapper.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 FuncList(props) {
    var _a;
    var title = props.title, className = props.className, cx = props.classnames, bodyClassName = props.bodyClassName, descClassName = props.descClassName, mobileUI = props.mobileUI;
    var _b = tslib.__read(React__default["default"].useState(''), 2), term = _b[0], setTerm = _b[1];
    var _c = tslib.__read(React__default["default"].useState(props.data), 2), filteredFuncs = _c[0], setFiteredFuncs = _c[1];
    var _d = tslib.__read(React__default["default"].useState(null), 2), activeFunc = _d[0], setActiveFunc = _d[1];
    var onSearch = React__default["default"].useCallback(function (term) {
        var filtered = props.data
            .map(function (item) {
            return tslib.__assign(tslib.__assign({}, item), { items: term
                    ? item.items.filter(function (item) { return ~item.name.indexOf(term.toUpperCase()); })
                    : item.items });
        })
            .filter(function (item) { return item.items.length; });
        setFiteredFuncs(filtered);
    }, [props.data]);
    React__default["default"].useEffect(function () {
        onSearch(term);
    }, [props.data]);
    return (_J$X_("div", { className: cx('FormulaEditor-panel', 'left', className) },
        _J$X_("div", { className: cx('FormulaEditor-FuncList', (activeFunc === null || activeFunc === void 0 ? void 0 : activeFunc.name) ? 'withDoc' : '') },
            _J$X_("div", { className: cx('FormulaEditor-panel-header') }, title),
            _J$X_("div", { className: cx('FormulaEditor-panel-body') },
                _J$X_("div", { className: cx('FormulaEditor-FuncList-searchBox') },
                    _J$X_(SearchBox["default"], { value: term, onChange: setTerm, mini: false, onSearch: onSearch, mobileUI: mobileUI })),
                _J$X_("div", { className: cx('FormulaEditor-FuncList-body', bodyClassName) },
                    _J$X_(CollapseGroup["default"], { className: cx('FormulaEditor-FuncList-collapseGroup'), defaultActiveKey: (_a = filteredFuncs[0]) === null || _a === void 0 ? void 0 : _a.groupName, expandIcon: _J$X_(icons.Icon, { cx: cx, icon: "fa fa-chevron-right FormulaEditor-FuncList-expandIcon", className: "Icon" }), accordion: true }, filteredFuncs.map(function (item) { return (_J$X_(Collapse["default"], { className: cx('FormulaEditor-FuncList-collapse'), headingClassName: cx('FormulaEditor-FuncList-groupTitle'), bodyClassName: cx('FormulaEditor-FuncList-groupBody'), propKey: item.groupName, header: item.groupName, key: item.groupName }, item.items.map(function (item) { return (_J$X_("div", { className: cx('FormulaEditor-FuncList-item', {
                            'is-active': item.name === (activeFunc === null || activeFunc === void 0 ? void 0 : activeFunc.name)
                        }), onMouseEnter: function () { return setActiveFunc(item); }, onClick: function () { var _a; return (_a = props.onSelect) === null || _a === void 0 ? void 0 : _a.call(props, item); }, key: item.name }, item.name)); }))); }))))),
        (activeFunc === null || activeFunc === void 0 ? void 0 : activeFunc.name) ? (_J$X_("div", { className: cx('FormulaEditor-FuncDoc') },
            _J$X_("div", { className: cx('FormulaEditor-panel-header') }, (activeFunc === null || activeFunc === void 0 ? void 0 : activeFunc.name) || ''),
            _J$X_("div", { className: cx('FormulaEditor-panel-body') },
                _J$X_("div", { className: cx('FormulaEditor-FuncList-doc', descClassName) }, activeFunc ? (_J$X_(React__default["default"].Fragment, null,
                    Array.isArray(activeFunc.params) ? (_J$X_("pre", null,
                        _J$X_(TooltipWrapper["default"], { placement: "top", tooltip: {
                                children: function () { return (_J$X_("table", { className: cx('FormulaEditor-FuncList-doc-example', 'Table-table') },
                                    _J$X_("thead", null,
                                        _J$X_("tr", null, ['参数名称', '类型', '描述'].map(function (name, index) { return (_J$X_("th", { key: index }, name)); }))),
                                    _J$X_("tbody", null, activeFunc.params.map(function (param, index) { return (_J$X_("tr", { key: index },
                                        _J$X_("td", null, param.name),
                                        _J$X_("td", null, param.type),
                                        _J$X_("td", null, param.description))); })))); }
                            }, trigger: "hover" },
                            _J$X_("code", null, activeFunc.example)))) : null,
                    _J$X_("div", { className: cx('FormulaEditor-FuncList-doc-desc') }, activeFunc.description))) : null)))) : null));
}
var FuncList$1 = amisCore.themeable(FuncList);

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