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

import { __extends, __rest, __assign, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { autobind } from 'amis-core';

var InputInner = /** @class */ (function (_super) {
    __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 = __rest(_a, ["forwardedRef", "testIdBuilder"]);
        return (React__default.createElement("input", __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())));
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleComposition", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleChange", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputInner.prototype, "handleKeyDown", null);
    return InputInner;
}(React__default.Component));
var Input = React__default.forwardRef(function (props, ref) {
    return React__default.createElement(InputInner, __assign({}, props, { forwardedRef: ref }));
});

export { Input as default };
