import { Col, Row } from "reactstrap";
import ValidationField from "../../../../Components/ValidationField/ValidationField";
import { useFormikContext } from "formik";
import { useModalState } from "../../../../zustand/Modal";
import { useEffect } from "react";
import { translateOptions } from "../../../../utils/translatedOptions";
import { Sex_Select_options } from "../../../../types/App";
import { useTranslation } from "react-i18next";

const Form = () => {
  const formik = useFormikContext();
  const { isOpen } = useModalState((state) => state);

  useEffect(() => {
    if (isOpen === "") {
      formik.setErrors({});
    }
    if (isOpen === "isSuccess") {
      formik.setErrors({});
      formik.resetForm();
    }
  }, [isOpen]);
  const [t] = useTranslation();
  return (
    <Row className="w-100">
      <Col>
        <ValidationField placeholder="name" label="name" name="name" />
      </Col>
      <Col>
        <ValidationField
          placeholder="sex"
          label="sex"
          type="Select"
          option={translateOptions(Sex_Select_options, t)}
          name="sex"
        />
      </Col>
    </Row>
  );
};

export default Form;
