import { toast, ToastOptions, TypeOptions } from "react-toastify";
import { checkIsMobile } from "../utils/checkIsMobile";
import { useDarkMode } from "./useDarkMode";

type ToastType = TypeOptions;

export const useToast = () => {
  const isMobile = checkIsMobile();
  const [isDark] = useDarkMode();

  return (
    text: string,
    type: ToastType = "default",
    options: ToastOptions = {
      position: "top-center",
      draggable: true,
      theme: isMobile ? (isDark ? "dark" : "light") : "colored",
      rtl: true,
      autoClose: isMobile ? 2000 : 3000,
      style: {
        width: isMobile ? "100vw" : text?.length <= 45 ? "400px" : "450px",
      },
    }
  ) => {
    toast(text, { type, ...options });
  };
};


