import { View, Input } from "@tarojs/components";
import "./index.less";

interface FormInputProps {
  placeholder?: string;
  type?: any;
  value?: string;
  onChange?: (value: string) => void;
  prefix?: string;
  suffix?: string;
}

const FormInput = (props: FormInputProps) => {
  const { placeholder, type, value, onChange, prefix, suffix } = props;

  return (
    <View className="input-container">
      {prefix && <View className="prefix">{prefix}</View>}
      <Input
        placeholder={placeholder ?? "请输入"}
        value={value}
        type={type}
        onInput={(e) => {
          const value = e.detail.value;
          if (onChange) {
            onChange(value);
          }
        }}
      />
      {suffix && <View>{suffix}</View>}
    </View>
  );
};

export default FormInput;
