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

import { __extends, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { DataSchema, autobind, localeable, themeable } from 'amis-core';
import VariableList from '../formula/VariableList.js';
import TooltipWrapper from '../TooltipWrapper.js';

var SchemaVariableList = /** @class */ (function (_super) {
    __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 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 (React__default.createElement("span", { className: cx("FormulaEditor-VariableList-item") },
            React__default.createElement("label", null, option.label),
            React__default.createElement(TooltipWrapper, { tooltip: option.description, tooltipTheme: "dark" },
                React__default.createElement("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 (React__default.createElement(VariableList, { data: this.state.variables, value: value, onSelect: this.handleSelect, selectMode: selectMode || 'tree', itemRender: this.itemRender, placeholderRender: placeholderRender }));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], SchemaVariableList.prototype, "handleSelect", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], SchemaVariableList.prototype, "itemRender", null);
    return SchemaVariableList;
}(React__default.Component));
var SchemaVariableList$1 = localeable(themeable(SchemaVariableList));

export { SchemaVariableList, SchemaVariableList$1 as default };
