import { Col, Row } from "reactstrap";
import React, { useEffect } from "react";
import ValidationField from "../../../../../../Components/ValidationField/ValidationField";
import { useFormikContext } from "formik";
import { useModalState } from "../../../../../../zustand/Modal";
import { StudentStatusEnum } from "../../../../../../enums/Items";
import { useTranslation } from "react-i18next";

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

  useEffect(() => {
    if (isOpen === "") {
      formik.setErrors({});
    }
  }, [isOpen, formik]);
  const [t] = useTranslation();
  const Status = [
    {
      label: t("select.Student_Type.earlyDeparture"),
      value: StudentStatusEnum?.EARLY_DEPARTURE,
    },
    {
      label: t("select.Student_Type.presence"),
      value: StudentStatusEnum?.PRESENCE,
    },
  ];

  const Type = [
    { label: t("select.Student_Type.justified"), value: "justified" },
    { label: t("select.Student_Type.not_justified"), value: "not_justified" },
  ];

  // console.log(formik?.values);

  return (
    <Row className="w-100">
      <Col>
        <ValidationField
          placeholder="status"
          label="status"
          name="status"
          type="Select"
          option={Status}
        />
        {formik?.values?.status !== StudentStatusEnum?.PRESENCE && (
          <>
            <ValidationField
              placeholder="type"
              label="type"
              type="Select"
              name="type"
              option={Type}
            />
          </>
        )}

        {formik?.values?.status !== StudentStatusEnum?.PRESENCE && (
          <>
            <ValidationField
              placeholder="departure_time"
              label="departure_time"
              name="departure_time"
              type="Time"
            />
          </>
        )}
      </Col>
      <Col>
        {formik?.values?.status !== StudentStatusEnum?.PRESENCE &&
          formik?.values?.type === "justified" && (
            <ValidationField
              placeholder="justification"
              label="justification"
              name="justification"
            />
          )}
        {formik?.values?.status !== StudentStatusEnum?.PRESENCE && (
          <>
            <ValidationField
              placeholder="attachment"
              label="attachment"
              type="File"
              name="attachment"
            />
          </>
        )}
      </Col>
    </Row>
  );
};

export default Form;
