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
}) => {
  return (
    <View style={styles.textField}>
      {icon}
      {inputType === "password" ? (
        <TextInput
          placeholder={label}
          keyboardType={keyboardType}
          style={styles.textInput}
          secureTextEntry={true}
          value={text}
          onChangeText={inputText => {
            if (onChangeText) {
                onChangeText(inputText);
            }
          }}
        />
      ) : (
        <TextInput
          placeholder={label}
          keyboardType={keyboardType}
          style={styles.textInput}
          value={text}
          onChangeText={inputText => {
            if (onChangeText) {
                onChangeText(inputText);
            }
          }}
        />
      )}
      <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;
