import { toast } from "react-toastify";
import ErrorNotification from "./ErrorNotification";
import SuccessNotification from "./SuccessNotification";
import WarningNotification from "./WarningNotification";

const Notifications = async (directionApp, t, response) => {
  console.log(directionApp, t, response);
  const { status, data } = response != undefined ? response : ""
  toast.dismiss();
  switch (status) {
    case 200:
      SuccessNotification(directionApp, t, status);
      break;
    case 400:
      ErrorNotification(directionApp, t,status);
      break;
    case 401:
      ErrorNotification(directionApp, t, status);
      break;
    case 403:
      ErrorNotification(directionApp, t, status);
      break;
    case 422:
      ErrorNotification(directionApp, t, status, data.message);
      break;
    case 500:
      WarningNotification(directionApp, t, status);
      break;
    case 503:
      WarningNotification(directionApp, t, status);
      break;
    case 504:
      WarningNotification(directionApp, t, status);
      break;
    default:
      toast(t("pending"), {
        position: directionApp === "ltr" ? "top-left" : "top-right",
        autoClose: false,
        closeOnClick: false,
        draggable: false,
      });
      break;
  }
};

export default Notifications;

/* 
usage document

** for pending use ( Notifications(directionApp, t, undefined) ) this before your request.
** for success use ( Notifications(directionApp, t, response) ) this inside .then() of your request.
** for Error and Warning use ( Notifications(directionApp, t, error.response) ) this inside .catche() of your request.

end usage document
*/
