import * as React from 'react';
import { FastInput, FastTextArea, FastInputNumber } from "components/ui";
import { FormTypes } from "../../types";

function Input(props: FormTypes.FormItem.FormAtomicInputProps) {
  const { values, config, validateTrigger } = props;
  const { key, type, placeholder, inputType, notModify, rows } = config;

  if (type === "multinput") {
    return (
      <FastTextArea
        rows={rows}
        value={values[key]}
        allowClear={!notModify}
        disabled={notModify}
        placeholder={placeholder}
        // eslint-disable-next-line react/destructuring-assignment
        onChange={props[validateTrigger]}
      />
    );
  }
  if (type === "inputnumber") {
    return (
      <FastInputNumber
        style={{ width: "100%" }}
        value={values[key]}
        disabled={notModify}
        placeholder={placeholder}
        // eslint-disable-next-line react/destructuring-assignment
        onChange={props[validateTrigger]}
      />
    );
  }
  return (
    <FastInput
      value={values[key]}
      allowClear={!notModify}
      type={inputType || "text"}
      disabled={notModify}
      placeholder={placeholder}
      // eslint-disable-next-line react/destructuring-assignment
      onChange={props[validateTrigger]}
    />
  );
}

export default Input;
