var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { useAppSelector } from 'src/app/redux/store';
import css from './InputMasked.module.scss';
import { _cx } from 'src/utility/class';
var cx = _cx(css);
export default function InputMasked(_a) {
    var _b = _a.value, value = _b === void 0 ? '' : _b, onChange = _a.onChange, onSelect = _a.onSelect, id = _a.id, _c = _a.error, error = _c === void 0 ? false : _c, _d = _a.showError, showError = _d === void 0 ? false : _d, _e = _a.placeholder, placeholder = _e === void 0 ? '' : _e, buttonProps = _a.buttonProps, autoFocus = _a.autoFocus, wrapperStyle = _a.wrapperStyle, inputStyle = _a.inputStyle;
    var enableGoogleSearch = useAppSelector(function (store) { return store.config.config; }).enableGoogleSearch;
    var _f = __read(useState(false), 2), inFocusNotEmpty = _f[0], setInFocusNotEmptyvalue = _f[1];
    var _g = __read(useState(false), 2), errorBorder = _g[0], setErrorBorder = _g[1];
    useEffect(function () {
        if (!error)
            setErrorBorder(false);
    }, [error]);
    useEffect(function () {
        if (showError && error)
            setErrorBorder(true);
    }, [showError]);
    return (_jsxs("div", { className: cx('input-wrapper'), style: wrapperStyle, children: [!enableGoogleSearch ? (_jsx(_Fragment, {})) : (_jsx("input", { id: id, value: value, onChange: onChange, onSelect: onSelect, type: "text", placeholder: placeholder, autoFocus: autoFocus, onFocus: function () { return value && value.length > 0 && setInFocusNotEmptyvalue(true); }, onBlur: function () {
                    setErrorBorder(!!error);
                    setInFocusNotEmptyvalue(false);
                }, style: inputStyle })), buttonProps && buttonProps.button] }));
}
