import React, { useContext, useState } from "react";
import { forwardRef, useImperativeHandle } from "react";
import { FeedbackBox } from "./../feedbackBox";
import { ResetPasswordBox } from "./../resetPassword";
import { LoaderContext } from "../../../context/loader/LoaderContext";
export const DialogBox = forwardRef((props, ref) => {
  const [open, setOpen] = useState(false);
  const [which, setWhich] = useState(null);
  const { updateLoaderStatus } = useContext(LoaderContext);

  useImperativeHandle(ref, () => ({
    handleSendFeedback() {
      setWhich(0);
      setOpen(true);
    },

    handleResetPassword() {
      setWhich(1);
      setOpen(true);
    },
  }));

  const callSetShow = () => {
    setOpen(false);
    updateLoaderStatus(false);
  };

  return (
    <>
      {which === 0 && (
        <FeedbackBox
          open={open}
          callSetShow={callSetShow}
          callOpen={setOpen}
        ></FeedbackBox>
      )}
      {which === 1 && (
        <ResetPasswordBox
          open={open}
          callSetShow={callSetShow}
          callOpen={setOpen}
        ></ResetPasswordBox>
      )}
    </>
  );
});
