"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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.InputPure = void 0;
var react_1 = __importStar(require("react"));
var react_native_1 = require("react-native");
var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var react_native_fontawesome_1 = require("@fortawesome/react-native-fontawesome");
var mask_utils_1 = require("../../MaskText/mask.utils");
var Input_style_1 = require("./Input.style");
exports.InputPure = function InputPure(props) {
    var title = props.title, _a = props.textRight, textRight = _a === void 0 ? false : _a, _b = props.textCenter, textCenter = _b === void 0 ? false : _b, prefix = props.prefix, suffix = props.suffix, _c = props.loading, loading = _c === void 0 ? false : _c, _d = props.error, error = _d === void 0 ? false : _d, _e = props.defaultValueInput, defaultValueInput = _e === void 0 ? '' : _e, _f = props.inputRef, inputRef = _f === void 0 ? '' : _f, hidePassword = props.hidePassword, value = props.value, setValue = props.setValue, focus = props.focus, setFocus = props.setFocus, clearError = props.clearError, _g = props.as, as = _g === void 0 ? InputPure : _g, setHidePassword = props.setHidePassword, _h = props.number, number = _h === void 0 ? false : _h, _j = props.password, password = _j === void 0 ? false : _j, rest = __rest(props, ["title", "textRight", "textCenter", "prefix", "suffix", "loading", "error", "defaultValueInput", "inputRef", "hidePassword", "value", "setValue", "focus", "setFocus", "clearError", "as", "setHidePassword", "number", "password"]);
    var forceShowTitle = false;
    var _k = react_1.useState(defaultValueInput != ''), hasText = _k[0], setHasText = _k[1];
    var animateTitle = react_1.useRef(new react_native_1.Animated.Value(forceShowTitle || defaultValueInput != '' ? 1 : 0)).current;
    react_1.useEffect(function () {
        if (!forceShowTitle) {
            if (focus || hasText) {
                react_native_1.Animated.timing(animateTitle, {
                    toValue: 1,
                    duration: 150,
                    useNativeDriver: true,
                }).start();
            }
            else if (!hasText) {
                react_native_1.Animated.timing(animateTitle, {
                    toValue: 0,
                    duration: 150,
                    useNativeDriver: true,
                }).start();
            }
        }
    }, [focus, hasText]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        title && react_1.default.createElement(Input_style_1.TitleText, null, title),
        react_1.default.createElement(Input_style_1.InputContainer, { focus: focus, error: !!error },
            prefix && react_1.default.createElement(Input_style_1.Prefix, null, prefix),
            react_1.default.createElement(Input_style_1.InputStyle, __assign({ ref: inputRef, keyboardAppearance: "dark", defaultValue: defaultValueInput, keyboardType: number ? 'numeric' : 'default', secureTextEntry: password && hidePassword, onChangeText: function (_value) {
                    setHasText(!!_value);
                    if (inputRef.current) {
                        inputRef.current.value = mask_utils_1.maskValue(_value, props);
                    }
                    setValue(mask_utils_1.maskValue(_value, props));
                    clearError();
                }, onFocus: function () { return setFocus(true); }, onBlur: function () { return setFocus(false); }, prefix: !!prefix, suffix: !!suffix, textRight: textRight, textCenter: textCenter, value: value }, rest)),
            suffix && react_1.default.createElement(Input_style_1.Suffix, null, suffix)),
        password && react_1.default.createElement(ViewPasswordToggle, { hidePassword: hidePassword, setHidePassword: setHidePassword }),
        !!error && react_1.default.createElement(Input_style_1.TextError, { testID: "input-error" }, error)));
};
function ViewPasswordToggle(_a) {
    var hidePassword = _a.hidePassword, setHidePassword = _a.setHidePassword;
    return (react_1.default.createElement(Input_style_1.ViewPassword, { activeOpacity: 0.8, onPress: function () { return setHidePassword(!hidePassword); } },
        hidePassword && react_1.default.createElement(react_native_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faEyeSlash, size: 20 }),
        !hidePassword && react_1.default.createElement(react_native_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faEye, size: 20 })));
}
//# sourceMappingURL=InputPure.js.map