"use client";

import { onMessage } from "firebase/messaging";
import { useEffect, type PropsWithChildren } from "react";

import { messaging } from "@/services/firebase";
import { toast } from "react-toastify";

const Notification = ({ children }: PropsWithChildren) => {
  useEffect(() => {
    onMessage(messaging, (payload) => {
      console.log("Message received. ", payload);
      if (payload.notification) {
        toast.success(payload.notification.title ?? "New Notification");
      }
    });
  }, []);

  return <>{children}</>;
};

export default Notification;
