/**
 * 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 InputBox = require('../InputBox.js');
var NumberInput = require('../NumberInput.js');
var Switch = require('../Switch.js');
var Array = require('./Array.js');
var Object$1 = require('./Object.js');
var Picker = require('../formula/Picker.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 InputJSONSchemaItem(props, ref) {
    var _a, _b, _c, _d, _e;
    var childRef = React__default["default"].useRef();
    React__default["default"].useImperativeHandle(ref, function () {
        return {
            validate: function () {
                var _a;
                return (_a = childRef.current) === null || _a === void 0 ? void 0 : _a.validate();
            }
        };
    });
    var schema = props.schema;
    var formua = props.formula;
    if (schema.type === 'object') {
        return _J$X_(Object$1["default"], tslib.__assign({}, props, { ref: childRef }));
    }
    else if (schema.type === 'array') {
        return _J$X_(Array.InputJSONSchemaArray, tslib.__assign({}, props));
    }
    else if (props.renderValue) {
        return props.renderValue(props.value, props.onChange, schema, props);
    }
    else if (formua) {
        var inputSettings = React__default["default"].useMemo(function () {
            var inputSettings = tslib.__assign({}, formua.inputSettings);
            if (schema.type === 'number' || schema.type === 'integer') {
                inputSettings.type = 'number';
            }
            else if (schema.type === 'boolean') {
                inputSettings.type = 'boolean';
            }
            return inputSettings;
        }, [formua.inputSettings, schema.type]);
        return (_J$X_(Picker.FormulaPicker, tslib.__assign({ mode: "input-group", mixedMode: true }, formua, { inputSettings: inputSettings, value: (_a = props.value) !== null && _a !== void 0 ? _a : schema.default, onChange: props.onChange, className: props.className, disabled: props.disabled, placeholder: props.placeholder, theme: props.theme, classPrefix: props.classPrefix, classnames: props.classnames, translate: props.translate, locale: props.locale })));
    }
    else if (schema.type == 'number') {
        return (_J$X_(NumberInput["default"], { className: props.className, value: (_b = props.value) !== null && _b !== void 0 ? _b : schema.default, onChange: props.onChange, placeholder: props.placeholder, mobileUI: props.mobileUI }));
    }
    else if (schema.type == 'integer') {
        return (_J$X_(NumberInput["default"], { className: props.className, value: (_c = props.value) !== null && _c !== void 0 ? _c : schema.default, onChange: props.onChange, precision: 0, placeholder: props.placeholder, mobileUI: props.mobileUI }));
    }
    else if (schema.type == 'boolean') {
        return (_J$X_(Switch["default"], { value: (_d = props.value) !== null && _d !== void 0 ? _d : schema.default, onChange: props.onChange, className: "mt-2" }));
    }
    return (_J$X_(InputBox["default"], { className: props.className, value: (_e = props.value) !== null && _e !== void 0 ? _e : schema.default, onChange: props.onChange, placeholder: props.placeholder, mobileUI: props.mobileUI }));
}
var InputJSONSchemaItem$1 = React__default["default"].forwardRef(InputJSONSchemaItem);

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