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 { useGetAllAbility } from "../../../api/ability";
import { translateAbilities } from "../../../utils/translateAbilities";
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 { data } = useGetAllAbility();
  const [t] = useTranslation();
  const abilities = translateAbilities(data?.data, t);
  console.log(abilities, "abilities");

  return (
    <Row className="w-100">
      <Col>
        <ValidationField placeholder="name" label="name" name="name" />
      </Col>
      <Col>
        <ValidationField
          placeholder="abilities"
          label="abilities"
          name="abilities"
          type="LocalSearch"
          option={abilities}
          isMulti
        />
      </Col>
    </Row>
  );
};

export default Form;
