import type { BaseElementProps } from './types';
import type { InputProps } from 'antd';
import { Form, Input as AntInput } from 'antd';
import type { ChangeEvent, FC } from 'react';

const { Item: FormItem } = Form;

function Input({
  value,
  setValue,
  status,
  validateStatus,
  help,
  ...props
}: BaseElementProps<string>) {
  function handleChange(event: ChangeEvent<HTMLInputElement>) {
    setValue(event.target.value);
  }

  return (
    <FormItem hasFeedback help={help} validateStatus={validateStatus}>
      <AntInput disabled={status === 'Disabled'} onChange={handleChange} value={value} {...props} />
    </FormItem>
  );
}

export default Input as FC<InputProps>;
