"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseInput = void 0;
const react_1 = __importStar(require("react"));
const styles_1 = require("./styles");
exports.BaseInput = (props) => {
    const { icon, unit, onFocus, onBlur, readOnly, disabled, invalid, className, inputRef: inputRefFromProps, blurOnEnterKeyPress } = props, restProps = __rest(props, ["icon", "unit", "onFocus", "onBlur", "readOnly", "disabled", "invalid", "className", "inputRef", "blurOnEnterKeyPress"]);
    const inputRefInternal = react_1.useRef(null);
    const inputRef = inputRefFromProps || inputRefInternal;
    const [focused, setFocusedState] = react_1.useState(false);
    const handleBlur = react_1.useCallback((e) => {
        if (onBlur)
            onBlur(e);
        setFocusedState(false);
    }, [onBlur, setFocusedState]);
    const handleFocus = react_1.useCallback((e) => {
        if (onFocus)
            onFocus(e);
        setFocusedState(true);
    }, [onFocus, setFocusedState]);
    const handleKeyPress = blurOnEnterKeyPress
        ? (e) => {
            if (e.key === 'Enter') {
                e.preventDefault();
                if (typeof inputRef === 'object' && inputRef && inputRef.current) {
                    inputRef.current.blur();
                }
            }
        }
        : undefined;
    return (react_1.default.createElement(styles_1.Wrapper, Object.assign({}, { focused, disabled, invalid, readOnly, className }),
        icon && react_1.default.createElement(styles_1.Icon, null, icon),
        react_1.default.createElement(styles_1.Input, Object.assign({ ref: inputRef, onFocus: handleFocus, onBlur: handleBlur, disabled: disabled, readOnly: readOnly, onKeyPress: handleKeyPress, "data-testid": "base-input" }, restProps)),
        unit && react_1.default.createElement(styles_1.Unit, null, unit)));
};
//# sourceMappingURL=BaseInput.js.map