import { Form, Input } from "antd";
import React from "react";
import useFormField from "../../../../../Hooks/useFormField";
import { MdOutlineEdit } from "react-icons/md";
import { Field } from "formik";

const HintField = ({
  name,
  label,
  label2,
  placeholder,
  isDisabled,
  onChange,
  props,
  parent_index,
  id,
  className,
}: any) => {
  const newName = `Questions[${parent_index}].QuestionOptions[${name}].hint`;

  const { formik, isError, errorMsg, t } = useFormField(newName, props);
  const TextFilehandleChange = (
    e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
  ) => {
    // console.log('Change:', e.target.value);
    formik.setFieldValue(newName, e.target.value);
  };

  return (
    <div className={`ValidationField w-100 ${className ?? ""} `}>
       <label htmlFor={name} className="text">
          {label2 ? label2 : t(`input.${label ? label : name}`)}
        </label>
      <Form.Item
        hasFeedback
        validateStatus={isError ? "error" : ""}
        help={isError ? errorMsg : ""}
      >
        <Field
          as={Input}
          placeholder={t(`input.${placeholder ? placeholder : name}`)}
          name={newName}
          disabled={isDisabled}
          size="large"
          onChange={onChange || TextFilehandleChange}
          style={{ width: 200 }}
          id={id}
        />
      </Form.Item>
    </div>
  );
};

export default React.memo(HintField);
