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 { Payments } from "../../../../../../types/App";
import { useGetAllRegistrationRecord } from "../../../../../../api/registrationRecord";
import registration_recordSelect from "../../../../../../utils/registration_recordSelect";
import { useParams } from "react-router-dom";
import useSearchQuery from "../../../../../../api/utils/useSearchQuery";
const Form = () => {
  const formik = useFormikContext();
  const { isOpen } = useModalState((state) => state);
  const [searchQuery] = useSearchQuery("student_name");

  useEffect(() => {
    if (isOpen === "") {
      formik.setErrors({});
      // formik.resetForm();
    }
    if (isOpen === "isSuccess") {
      formik.setErrors({});
      formik.resetForm();
    }
  }, [isOpen]);
  const { edu_class_id } = useParams();

  const { data: registration_record,isLoading } = useGetAllRegistrationRecord({
    edu_class_id: edu_class_id,
    status: "active",
    name: searchQuery,
  });
  // console.log(registration_record,"registration_record");

  const recordSelect = registration_recordSelect(registration_record?.data);

  return (
    <Row className="w-100">
      <Col>
        <ValidationField placeholder="details" label="details" name="details" />

        <ValidationField
          placeholder="date"
          label="date"
          type="Date"
          name="date"
        />
        <ValidationField
          placeholder="receipt_number"
          label="receipt_number"
          name="receipt_number"
        />
      </Col>

      <Col>
        <ValidationField
          placeholder="payment_type"
          label="payment_type"
          type="Select"
          option={Payments}
          name="type"
        />

        <ValidationField
          placeholder="value"
          label="value"
          type="NumberFormate"
          name="value"
        />

        <ValidationField
          placeholder="student_name"
          label="student_name"
          type="Search"
          option={recordSelect}
          name="registration_record_id"
          searchBy="student_name"
          isLoading={isLoading}
        />
      </Col>
    </Row>
  );
};

export default Form;
