/**
 * 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');
var Input = require('./Input.js');
var icons = require('./icons.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;
var InputBox = /** @class */ (function (_super) {
    tslib.__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, _c;
        var _d = this.props, className = _d.className, cx = _d.classnames; _d.classPrefix; var clearable = _d.clearable, disabled = _d.disabled, hasError = _d.hasError, value = _d.value, blurValue = _d.blurValue, placeholder = _d.placeholder, result = _d.prefix, children = _d.children, borderMode = _d.borderMode, onClick = _d.onClick, mobileUI = _d.mobileUI, testIdBuilder = _d.testIdBuilder, inputRender = _d.inputRender, dataName = _d.dataName, rest = tslib.__rest(_d, ["className", "classnames", "classPrefix", "clearable", "disabled", "hasError", "value", "blurValue", "placeholder", "prefix", "children", "borderMode", "onClick", "mobileUI", "testIdBuilder", "inputRender", "dataName"]);
        var isFocused = this.state.isFocused;
        return (_J$X_("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(amisCore.ucFirst(borderMode))] = borderMode,
                _a)), onClick: onClick, "data-amis-name": dataName },
            result,
            typeof inputRender === 'function' ? (inputRender(tslib.__assign(tslib.__assign(tslib.__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()))) : (_J$X_(Input["default"], tslib.__assign({}, rest, { value: (_c = (_b = (isFocused ? undefined : blurValue)) !== null && _b !== void 0 ? _b : value) !== null && _c !== void 0 ? _c : '', 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 ? (_J$X_("a", { onClick: this.clearValue, className: cx('InputBox-clear') },
                _J$X_(icons.Icon, { icon: "input-clear", className: "icon" }))) : null,
            children));
    };
    InputBox.defaultProps = {
        clearable: true,
        placeholder: ''
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "clearValue", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleChange", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleFocus", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", [Object]),
        tslib.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleBlur", null);
    return InputBox;
}(React__default["default"].Component));
var InputBox$1 = amisCore.themeable(InputBox);

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