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

import { __assign } from 'tslib';
import React__default from 'react';
import InputBox from '../InputBox.js';
import NumberInput from '../NumberInput.js';
import Switch from '../Switch.js';
import { InputJSONSchemaArray } from './Array.js';
import InputJSONSchemaObject from './Object.js';
import { FormulaPicker } from '../formula/Picker.js';

function InputJSONSchemaItem(props, ref) {
    var _a, _b, _c, _d, _e;
    var childRef = React__default.useRef();
    React__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 React__default.createElement(InputJSONSchemaObject, __assign({}, props, { ref: childRef }));
    }
    else if (schema.type === 'array') {
        return React__default.createElement(InputJSONSchemaArray, __assign({}, props));
    }
    else if (props.renderValue) {
        return props.renderValue(props.value, props.onChange, schema, props);
    }
    else if (formua) {
        var inputSettings = React__default.useMemo(function () {
            var inputSettings = __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 (React__default.createElement(FormulaPicker, __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 (React__default.createElement(NumberInput, { 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 (React__default.createElement(NumberInput, { 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 (React__default.createElement(Switch, { value: (_d = props.value) !== null && _d !== void 0 ? _d : schema.default, onChange: props.onChange, className: "mt-2" }));
    }
    return (React__default.createElement(InputBox, { 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.forwardRef(InputJSONSchemaItem);

export { InputJSONSchemaItem, InputJSONSchemaItem$1 as default };
