/**
 * 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 InputBox = require('../InputBox.js');
var NumberInput = require('../NumberInput.js');
var DatePicker = require('../DatePicker.js');
var Select = require('../Select.js');
var Switch = require('../Switch.js');
var Picker = require('../formula/Picker.js');
var omit = require('lodash/omit');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);

var __react_jsx__ = require('react');
var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
(__react_jsx__["default"] || __react_jsx__).Fragment;
var Value = /** @class */ (function (_super) {
    tslib.__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(tslib.__assign(tslib.__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 = tslib.__assign(tslib.__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)
                ? tslib.__assign(tslib.__assign(tslib.__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 = (_J$X_(Picker.FormulaPicker, tslib.__assign({}, formula, { inputSettings: inputSettings, customInputRender: this.renderCustomValue })));
        }
        else if (field.type === 'text') {
            input = (_J$X_(InputBox["default"], { 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 = (_J$X_(NumberInput["default"], { 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 = (_J$X_(DatePicker["default"], { 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 = (_J$X_(DatePicker["default"], { 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 = (_J$X_(DatePicker["default"], { 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 = (_J$X_(Select.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 = (_J$X_("div", { className: cx("SwitchControl") },
                _J$X_(Switch["default"], { 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__default["default"](field, [
                        'label',
                        'operators',
                        'defaultOp',
                        'defaultValue'
                    ])
                }
            });
        }
        return _J$X_("div", { className: cx('CBValue') }, input);
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], Value.prototype, "renderCustomValue", null);
    return Value;
}(React__default["default"].Component));
var Value$1 = amisCore.themeable(amisCore.localeable(Value));

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