import React from "react";
import {
  View,
  Text,
  TouchableOpacity,
  TextInput,
  StyleSheet,
} from "react-native";
import { globalStyles } from "../styles/global";

const InputField = ({
  label,
  icon,
  inputType,
  keyboardType,
  filedButtonLabel,
  fieldButtonFunction,
  onChangeText,
  text,
  name,
  handleBlur
}) => {
  return (
    <View style={styles.textField}>
      {icon}
      {inputType === "password" ? (
        <TextInput
          name={name}
          placeholder={label}
          placeholderTextColor="#C6C6C6"
          keyboardType={keyboardType}
          style={styles.textInput}
          secureTextEntry={true}
          value={text}
          onChangeText={onChangeText}
          onBlur={handleBlur}
        />
      ) : (
        <TextInput
          name={name}
          placeholder={label}
          placeholderTextColor="#C6C6C6"
          keyboardType={keyboardType}
          style={styles.textInput}
          value={text}
          onChangeText={onChangeText}
          onBlur={handleBlur}
        />
      )}
      <TouchableOpacity onPress={fieldButtonFunction}>
        <Text style={globalStyles.primaryBold}>{filedButtonLabel}</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  textField: {
    flexDirection: "row",
    borderBottomColor: "#ccc",
    borderBottomWidth: 1,
    paddingBottom: 8,
    marginBottom: 25,
  },
  textInput: {
    flex: 1,
    paddingVertical: 0,
    fontFamily: "poppins-regular",
  },
});

export default InputField;
