import { View, Text, TextInput } from 'react-native';
import React, { useContext, useEffect, useState } from 'react';
import { CometChatContext } from '../../CometChatContext';
import { TextInputStyle } from './TextInputStyle';
const CometChatTextInput = (props) => {
    const { onChange, data, showError, style, defaultValue } = props;
    const { theme } = useContext(CometChatContext);
    const [value, setValue] = useState(defaultValue);
    const _style = new TextInputStyle({
        border: { borderWidth: 1, borderColor: theme.palette.getAccent200() },
        titleFont: theme.typography.subtitle1,
        titleColor: theme.palette.getAccent(),
        placeholderColor: theme.palette.getAccent600(),
        ...style,
    });
    const { titleFont, titleColor, placeholderColor, borderColor, borderWidth, } = _style;
    useEffect(() => {
        setValue(defaultValue);
    }, [defaultValue]);
    const _onChange = (text) => {
        setValue(text);
        if (onChange) {
            onChange(text);
        }
    };
    return (<View style={{ marginBottom: 12 }}>
            <Text style={[titleFont, { color: titleColor, marginBottom: 4 }]}>{data.getLabel()}{!data.getOptional() && "*"}</Text>
            <TextInput 
    // autoFocus={true}
    value={value} autoCorrect={false} onChangeText={_onChange} style={{
            borderColor: showError ? theme.palette.getError() : borderColor, paddingHorizontal: 8, paddingVertical: 4.8,
            borderWidth: borderWidth, borderRadius: 5
        }} placeholder={data.getPlaceholder()} placeholderTextColor={placeholderColor}/>
        </View>);
};
export default CometChatTextInput;
//# sourceMappingURL=CometChatTextInput.js.map