import React from "react";
import { TextInput, TextInputProps, View } from "react-native";
import { AntDesignIconNames } from "../Icons";
import { AntDesign } from "@expo/vector-icons";
import Text from "../ui/Text";
export interface FormInputProps extends TextInputProps {
  afterIcon?: AntDesignIconNames;
  label: string;
}
interface Props extends FormInputProps {
  beforeIcon: AntDesignIconNames;
}

export default React.forwardRef<any, Props>(
  (props, ref): React.ReactElement => {
    const {
      onBlur,
      onChangeText,
      value,
      beforeIcon,
      afterIcon,
      label,
      placeholder,
      onPress,
      ...rest
    } = props;

    return (
      <View className="gap-2">
        <Text weight="bold">{label}</Text>
        <View className="flex-row items-center gap-2 px-4 py-2 bg-gray-200 rounded-3xl">
          <AntDesign name={beforeIcon} size={24} />
          <TextInput
            className="grow"
            placeholder={placeholder}
            onBlur={onBlur}
            onChangeText={onChangeText}
            value={value}
            {...ref}
            {...rest}
          />
          {afterIcon != null ? (
            <AntDesign name={afterIcon} size={24} onPress={onPress} />
          ) : null}
        </View>
      </View>
    );
  }
);
