"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var theme_1 = require("../theme");
var Input_1 = tslib_1.__importDefault(require("./Input"));
var helper_1 = require("../utils/helper");
var icons_1 = require("./icons");
var InputBox = /** @class */ (function (_super) {
    tslib_1.__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) {
        var onClear = this.props.onChange;
        var onValueChange = this.props.onValueChange;
        onClear && onClear(e);
        onValueChange && onValueChange('');
    };
    InputBox.prototype.handleChange = function (e) {
        var onChange = this.props.onChange;
        var onValueChange = this.props.onValueChange;
        onChange && onChange(e);
        onValueChange && onValueChange(e.currentTarget.value);
    };
    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 = this.props, className = _a.className, cx = _a.classnames, classPrefix = _a.classPrefix, clearable = _a.clearable, disabled = _a.disabled, hasError = _a.hasError, value = _a.value, placeholder = _a.placeholder, result = _a.prefix, children = _a.children, rest = tslib_1.__rest(_a, ["className", "classnames", "classPrefix", "clearable", "disabled", "hasError", "value", "placeholder", "prefix", "children"]);
        var isFocused = this.state.isFocused;
        return (react_1.default.createElement("div", { className: cx('InputBox', className, isFocused ? 'is-focused' : '', disabled ? 'is-disabled' : '', hasError ? 'is-error' : '') },
            result,
            react_1.default.createElement(Input_1.default, tslib_1.__assign({}, rest, { value: value || '', onChange: this.handleChange, placeholder: placeholder, onFocus: this.handleFocus, onBlur: this.handleBlur })),
            clearable && !disabled && value ? (react_1.default.createElement("a", { onClick: this.clearValue, className: cx('InputBox-clear') },
                react_1.default.createElement(icons_1.Icon, { icon: "close", className: "icon" }))) : null,
            children));
    };
    var _a;
    InputBox.defaultProps = {
        clearable: true,
        placeholder: ''
    };
    tslib_1.__decorate([
        helper_1.autobind,
        tslib_1.__metadata("design:type", Function),
        tslib_1.__metadata("design:paramtypes", [Object]),
        tslib_1.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "clearValue", null);
    tslib_1.__decorate([
        helper_1.autobind,
        tslib_1.__metadata("design:type", Function),
        tslib_1.__metadata("design:paramtypes", [typeof (_a = typeof react_1.default !== "undefined" && react_1.default.ChangeEvent) === "function" ? _a : Object]),
        tslib_1.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleChange", null);
    tslib_1.__decorate([
        helper_1.autobind,
        tslib_1.__metadata("design:type", Function),
        tslib_1.__metadata("design:paramtypes", [Object]),
        tslib_1.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleFocus", null);
    tslib_1.__decorate([
        helper_1.autobind,
        tslib_1.__metadata("design:type", Function),
        tslib_1.__metadata("design:paramtypes", [Object]),
        tslib_1.__metadata("design:returntype", void 0)
    ], InputBox.prototype, "handleBlur", null);
    return InputBox;
}(react_1.default.Component));
exports.InputBox = InputBox;
exports.default = theme_1.themeable(InputBox);
//# sourceMappingURL=./components/InputBox.js.map
