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 Default = ({
  name,
  label,
  placeholder,
  isDisabled,
  onChange,
  type,
  no_label,
  label_icon,
  ...props
}: any) => {
  const { errorMsg, isError, t } = useFormField(name, props);

  return (
    <div className="ValidationField w-100">
      {no_label ? (
        <label htmlFor={name} className="text">
          <span>empty</span>
        </label>
      ) : label_icon ? (
        <div className="LabelWithIcon">
          <label htmlFor={name} className="text">
            {t(`${label ? label : name}`)}
          </label>
          <MdOutlineEdit size={22} style={{ color: "#A098AE" }} />
        </div>
      ) : (
        <label htmlFor={name} className="text">
          {t(`${label ? label : placeholder ? placeholder : name}`)}
        </label>
      )}

      <Form.Item
        hasFeedback
        validateStatus={isError ? "error" : ""}
        help={isError ? errorMsg : ""}
      >
        <Field
          as={Input}
          type={type ?? "text"}
          placeholder={t(
            `${placeholder ? placeholder : label ? label : name}`,
          )}
          name={name}
          disabled={isDisabled}
          size="large"
          {...props}
          //  onChange={onChange ? onChange : handleChange}
          {...(type === "number" && { min: 0 })}
        />
      </Form.Item>
    </div>
  );
};

export default React.memo(Default);
