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

import { __extends, __assign, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { autobind, themeable, localeable } from 'amis-core';
import InputBox from '../InputBox.js';
import NumberInput from '../NumberInput.js';
import DatePicker from '../DatePicker.js';
import { SelectWithRemoteOptions } from '../Select.js';
import Switch from '../Switch.js';
import { FormulaPicker } from '../formula/Picker.js';
import omit from 'lodash/omit';

var Value = /** @class */ (function (_super) {
    __extends(Value, _super);
    function Value() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Value.prototype.renderCustomValue = function (props) {
        var _a = this.props, renderEtrValue = _a.renderEtrValue, data = _a.data, cx = _a.classnames;
        var field = props.inputSettings;
        return renderEtrValue
            ? renderEtrValue(__assign(__assign({}, field.value), { name: 'TMP_WHATEVER_NAME' }), // name 随便输入，应该是 value 传入的为主，目前表单项内部逻辑还有问题先传一个 name
            {
                data: data,
                onChange: props.onChange,
                value: props.value,
                inputClassName: cx(field.className, props.className)
            })
            : null;
    };
    Value.prototype.render = function () {
        var _a;
        var _b = this.props, cx = _b.classnames, field = _b.field, value = _b.value, onChange = _b.onChange, op = _b.op, __ = _b.translate, data = _b.data, disabled = _b.disabled, formula = _b.formula, popOverContainer = _b.popOverContainer, mobileUI = _b.mobileUI, testIdBuilder = _b.testIdBuilder;
        var input = undefined;
        if (formula) {
            // 如果配置了 formula 字段，则所有的输入变为 formula 形式
            formula = __assign(__assign({}, formula), { translate: __, classnames: cx, data: data, value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, disabled: disabled });
            var inputSettings = (formula === null || formula === void 0 ? void 0 : formula.inputSettings)
                ? __assign(__assign(__assign({}, formula === null || formula === void 0 ? void 0 : formula.inputSettings), field), { multiple: field.type === 'select' &&
                        op &&
                        typeof op === 'string' &&
                        ['select_any_in', 'select_not_any_in'].includes(op) }) : undefined;
            input = (React__default.createElement(FormulaPicker, __assign({}, formula, { inputSettings: inputSettings, customInputRender: this.renderCustomValue })));
        }
        else if (field.type === 'text') {
            input = (React__default.createElement(InputBox, { value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, placeholder: __(field.placeholder), disabled: disabled, mobileUI: mobileUI, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('text') }));
        }
        else if (field.type === 'number') {
            input = (React__default.createElement(NumberInput, { placeholder: __(field.placeholder) || __('NumberInput.placeholder'), step: field.step, min: field.minimum, max: field.maximum, precision: field.precision, value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, disabled: disabled, mobileUI: mobileUI, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('number') }));
        }
        else if (field.type === 'date') {
            input = (React__default.createElement(DatePicker, { placeholder: __(field.placeholder) || __('Date.placeholder'), format: field.format || 'YYYY-MM-DD', inputFormat: field.inputFormat || 'YYYY-MM-DD', value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, timeFormat: "", disabled: disabled, popOverContainer: popOverContainer, mobileUI: mobileUI, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('date') }));
        }
        else if (field.type === 'time') {
            input = (React__default.createElement(DatePicker, { viewMode: "time", placeholder: __(field.placeholder) || __('Time.placeholder'), format: field.format || 'HH:mm', inputFormat: field.inputFormat || 'HH:mm', value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, dateFormat: "", timeFormat: field.format || 'HH:mm', disabled: disabled, popOverContainer: popOverContainer, mobileUI: mobileUI, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('time') }));
        }
        else if (field.type === 'datetime') {
            input = (React__default.createElement(DatePicker, { placeholder: __(field.placeholder) || __('Time.placeholder'), format: field.format || '', inputFormat: field.inputFormat || 'YYYY-MM-DD HH:mm', value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, timeFormat: field.timeFormat || 'HH:mm', disabled: disabled, popOverContainer: popOverContainer, mobileUI: mobileUI, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('datetime') }));
        }
        else if (field.type === 'select') {
            var autoComplete = field.autoComplete;
            input = (React__default.createElement(SelectWithRemoteOptions, { simpleValue: true, options: field.options, placeholder: __(field.placeholder) || 'Select.placeholder', source: field.source, autoComplete: autoComplete, searchable: field.searchable, value: (_a = value !== null && value !== void 0 ? value : field.defaultValue) !== null && _a !== void 0 ? _a : '', data: data, onChange: onChange, multiple: op === 'select_any_in' || op === 'select_not_any_in', disabled: disabled, popOverContainer: popOverContainer, mobileUI: mobileUI, maxTagCount: field.maxTagCount, overflowTagPopover: field.overflowTagPopover, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('select') }));
        }
        else if (field.type === 'boolean') {
            input = (React__default.createElement("div", { className: cx("SwitchControl") },
                React__default.createElement(Switch, { value: value !== null && value !== void 0 ? value : field.defaultValue, onChange: onChange, disabled: disabled, testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('switch') })));
        }
        else if (field.type === 'custom') {
            input = this.renderCustomValue({
                value: value !== null && value !== void 0 ? value : field.defaultValue,
                onChange: onChange,
                inputSettings: field,
                testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('custom')
            });
        }
        else {
            // 不支持的也转给自定义组件处理
            input = this.renderCustomValue({
                value: value !== null && value !== void 0 ? value : field.defaultValue,
                onChange: onChange,
                testIdBuilder: testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getChild('custom'),
                inputSettings: {
                    value: omit(field, [
                        'label',
                        'operators',
                        'defaultOp',
                        'defaultValue'
                    ])
                }
            });
        }
        return React__default.createElement("div", { className: cx('CBValue') }, input);
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], Value.prototype, "renderCustomValue", null);
    return Value;
}(React__default.Component));
var Value$1 = themeable(localeable(Value));

export { Value, Value$1 as default };
