/**
 * amis-ui v6.11.0-beta.8
 * Copyright 2018-2025 fex
 */

import { __extends, __rest, __assign, __decorate, __metadata } from 'tslib';
import React__default from 'react';
import { ucFirst, autobind, themeable } from 'amis-core';
import Input from './Input.js';
import { Icon } from './icons.js';

var InputBox = /** @class */ (function (_super) {
    __extends(InputBox, _super);
    function InputBox() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            isFocused: false
        };
        return _this;
    }
    InputBox.prototype.clearValue = function (e) {
        e.preventDefault();
        e.stopPropagation();
        var onClear = this.props.onClear;
        var onChange = this.props.onChange;
        onClear === null || onClear === void 0 ? void 0 : onClear(e);
        onChange === null || onChange === void 0 ? void 0 : onChange('');
    };
    InputBox.prototype.handleChange = function (e) {
        var onChange = this.props.onChange;
        onChange && onChange(e.currentTarget ? e.currentTarget.value : e);
    };
    InputBox.prototype.handleFocus = function (e) {
        var onFocus = this.props.onFocus;
        onFocus && onFocus(e);
        this.setState({
            isFocused: true
        });
    };
    InputBox.prototype.handleBlur = function (e) {
        var onBlur = this.props.onBlur;
        onBlur && onBlur(e);
        this.setState({
            isFocused: false
        });
    };
    InputBox.prototype.render = function () {
        var _a;
        var _b = this.props, className = _b.className, cx = _b.classnames; _b.classPrefix; var clearable = _b.clearable, disabled = _b.disabled, hasError = _b.hasError, value = _b.value, placeholder = _b.placeholder, result = _b.prefix, children = _b.children, borderMode = _b.borderMode, onClick = _b.onClick, mobileUI = _b.mobileUI, testIdBuilder = _b.testIdBuilder, inputRender = _b.inputRender, dataName = _b.dataName, rest = __rest(_b, ["className", "classnames", "classPrefix", "clearable", "disabled", "hasError", "value", "placeholder", "prefix", "children", "borderMode", "onClick", "mobileUI", "testIdBuilder", "inputRender", "dataName"]);
        var isFocused = this.state.isFocused;
        return (React__default.createElement("div", { className: cx('InputBox', className, (_a = {
                    'is-mobile': mobileUI,
                    'is-focused': isFocused,
                    'is-disabled': disabled,
                    'is-error': hasError,
                    'is-clickable': onClick
                },
                _a["InputBox--border".concat(ucFirst(borderMode))] = borderMode,
                _a)), onClick: onClick, "data-amis-name": dataName },
            result,
            typeof inputRender === 'function' ? (inputRender(__assign(__assign(__assign({}, rest), { value: value !== null && value !== void 0 ? value : '', onChange: this.handleChange, placeholder: placeholder, onFocus: this.handleFocus, onBlur: this.handleBlur, disabled: disabled }), testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId()))) : (React__default.createElement(Input, __assign({}, rest, { value: value !== null && value !== void 0 ? value : '', onChange: this.handleChange, placeholder: placeholder, onFocus: this.handleFocus, onBlur: this.handleBlur, size: 12, disabled: disabled }, testIdBuilder === null || testIdBuilder === void 0 ? void 0 : testIdBuilder.getTestId()))),
            clearable && !disabled && value ? (React__default.createElement("a", { onClick: this.clearValue, className: cx('InputBox-clear') },
                React__default.createElement(Icon, { icon: "input-clear", className: "icon" }))) : null,
            children));
    };
    InputBox.defaultProps = {
        clearable: true,
        placeholder: ''
    };
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputBox.prototype, "clearValue", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleChange", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleFocus", null);
    __decorate([
        autobind,
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleBlur", null);
    return InputBox;
}(React__default.Component));
var InputBox$1 = themeable(InputBox);

export { InputBox, InputBox$1 as default };
