"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const react_native_1 = require("react-native");
const styles_1 = require("./styles");
const SearchInput = ({ onChange, onClear = () => null, onFocus = () => null, onBlur = () => null, onSubmit = () => null, onIconPress, id, accessibility, iconColor, placeholder, wrapperHeight, inputPadding, iconSize, hasShadow = false, inputStyle, containerStyle, placeholderTextColor, textStyle, autoFocus = false, rightIconName, leftIconName, inputRef, ...rest }) => {
    const [searchText, setSearchText] = (0, react_1.useState)('');
    const [autoCompleteType] = (0, react_1.useState)('off'); // ['off', 'username', 'password', 'email', 'name', 'tel', 'street-address', 'postal-code'
    const [isSearching, setSearching] = (0, react_1.useState)(false);
    const [isFocused, setFocused] = (0, react_1.useState)(false);
    const ref = inputRef || (0, react_1.useRef)(null);
    const onPressIcon = () => {
        if (onIconPress) {
            onIconPress();
        }
        setSearchText('');
        onClear();
        setSearching(false);
        react_native_1.Keyboard.dismiss();
    };
    // @TODO: AutocompleteType de acordo com o tipo de máscara
    return (<styles_1.Wrapper height={wrapperHeight} inputPadding={inputPadding} hasShadow={hasShadow} style={containerStyle}>
      <styles_1.Input textStyle={textStyle} placeholderTextColor={placeholderTextColor} style={inputStyle} inputRef={ref} large={false} id={id || accessibility} accessibility={accessibility} autoFocus={autoFocus} autoCapitalize="none" autoCorrect={false} iconName={isFocused || !!searchText ? 'times' : 'search'} autoComplete={autoCompleteType} placeholder={isSearching ? '' : placeholder || 'Pesquise aqui'} onChangeText={(value) => {
            setSearchText(value);
            onChange(value);
        }} onPressIcon={onPressIcon} value={searchText} onFocus={() => {
            setFocused(true);
            if (!autoFocus)
                onFocus();
        }} onBlur={() => {
            onBlur();
            setFocused(false);
            if (!searchText) {
                setSearching(false);
            }
        }} leftIconName={leftIconName} iconColor={iconColor} iconSize={iconSize} inputPadding={inputPadding} rightIconName={rightIconName} onSubmitEditing={onSubmit} {...rest}/>
    </styles_1.Wrapper>);
};
exports.default = SearchInput;
//# sourceMappingURL=index.js.map