/**
 * 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 VariableList = require('../formula/VariableList.js');
var TooltipWrapper = require('../TooltipWrapper.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;
var SchemaVariableList = /** @class */ (function (_super) {
    tslib.__extends(SchemaVariableList, _super);
    function SchemaVariableList() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            variables: _this.schemasToVaraibles(_this.props)
        };
        return _this;
    }
    SchemaVariableList.prototype.componentDidUpdate = function (prevProps) {
        var props = this.props;
        if (props.schemas !== prevProps.schemas) {
            this.setState({
                variables: this.schemasToVaraibles(props)
            });
        }
    };
    SchemaVariableList.prototype.schemasToVaraibles = function (props) {
        var _a, _b;
        var schemas = Array.isArray(props.schemas)
            ? props.schemas.concat()
            : props.schemas
                ? [props.schemas]
                : [];
        var dataSchema = new amisCore.DataSchema(schemas);
        this.dataSchema = dataSchema;
        (_b = (_a = this.props).beforeBuildVariables) === null || _b === void 0 ? void 0 : _b.call(_a, dataSchema);
        return dataSchema.getDataPropsAsOptions();
    };
    SchemaVariableList.prototype.handleSelect = function (item) {
        var _a;
        var onSelect = this.props.onSelect;
        var schema = (_a = this.dataSchema) === null || _a === void 0 ? void 0 : _a.getSchemaByPath(item.value);
        onSelect === null || onSelect === void 0 ? void 0 : onSelect(item.value, schema);
    };
    SchemaVariableList.prototype.itemRender = function (option) {
        var _a = this.props, cx = _a.classnames, __ = _a.translate;
        return (_J$X_("span", { className: cx("FormulaEditor-VariableList-item") },
            _J$X_("label", null, option.label),
            _J$X_(TooltipWrapper["default"], { tooltip: option.description, tooltipTheme: "dark" },
                _J$X_("span", { className: cx("FormulaEditor-VariableList-item-tag") }, __("SchemaType.".concat(option.type || 'any'))))));
    };
    SchemaVariableList.prototype.render = function () {
        var _a = this.props, selectMode = _a.selectMode, value = _a.value, placeholderRender = _a.placeholderRender;
        return (_J$X_(VariableList["default"], { data: this.state.variables, value: value, onSelect: this.handleSelect, selectMode: selectMode || 'tree', itemRender: this.itemRender, placeholderRender: placeholderRender }));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], SchemaVariableList.prototype, "handleSelect", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], SchemaVariableList.prototype, "itemRender", null);
    return SchemaVariableList;
}(React__default["default"].Component));
var SchemaVariableList$1 = amisCore.localeable(amisCore.themeable(SchemaVariableList));

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