import React, { useRef, useState } from 'react';
import { Keyboard } from 'react-native';
import { Input, Wrapper } from './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] = useState('');
    const [isSearching, setSearching] = useState(false);
    const [isFocused, setFocused] = useState(false);
    const ref = inputRef || useRef(null);
    const onPressIcon = () => {
        if (onIconPress) {
            onIconPress();
        }
        setSearchText('');
        onClear();
        setSearching(false);
        Keyboard.dismiss();
    };
    return (<Wrapper height={wrapperHeight} inputPadding={inputPadding} hasShadow={hasShadow} style={containerStyle}>
      <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 ? 'close' : 'magnify'} autoCompleteType="off" 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}/>
    </Wrapper>);
};
export default SearchInput;
//# sourceMappingURL=index.js.map