/**
 * amis-ui v6.14.0-beta.1
 * 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');

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;
var InputInner = /** @class */ (function (_super) {
    tslib.__extends(InputInner, _super);
    function InputInner() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.isOnComposition = false;
        _this.state = { value: _this.props.value };
        return _this;
    }
    InputInner.prototype.componentDidUpdate = function (prevProps) {
        var props = this.props;
        if (prevProps.value !== props.value) {
            this.setState({
                value: props.value
            });
        }
    };
    InputInner.prototype.handleComposition = function (e) {
        this.isOnComposition = e.type !== 'compositionend';
        if (!this.isOnComposition) {
            this.handleChange(e);
        }
    };
    InputInner.prototype.handleChange = function (e) {
        var onChange = this.props.onChange;
        var value = e.currentTarget.value;
        this.isOnComposition || (onChange && onChange(e));
        this.setState({
            value: value
        });
    };
    InputInner.prototype.handleKeyDown = function (e) {
        var onKeyDown = this.props.onKeyDown;
        if (this.isOnComposition) {
            return;
        }
        onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
    };
    InputInner.prototype.render = function () {
        var _a = this.props, forwardedRef = _a.forwardedRef, testIdBuilder = _a.testIdBuilder, rest = tslib.__rest(_a, ["forwardedRef", "testIdBuilder"]);
        return (_J$X_("input", tslib.__assign({ type: "text" }, rest, { value: this.state.value, ref: forwardedRef, onChange: this.handleChange, onKeyDown: this.handleKeyDown, onCompositionStart: this.handleComposition, onCompositionUpdate: this.handleComposition, onCompositionEnd: this.handleComposition }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId())));
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleComposition", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleChange", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleKeyDown", null);
    return InputInner;
}(React__default["default"].Component));
var Input = React__default["default"].forwardRef(function (props, ref) {
    return _J$X_(InputInner, tslib.__assign({}, props, { forwardedRef: ref }));
});

exports["default"] = Input;
