"use client";

import { useEffect } from "react";

type PopupNotificationProps = {
  message: string;
  type: "success" | "error";
  onClose: () => void;
};

export default function PopupNotification({
  message,
  type,
  onClose,
}: PopupNotificationProps) {
  useEffect(() => {
    const timer = setTimeout(() => {
      onClose();
    }, 4000); // Auto-close after 60 seconds
    return () => clearTimeout(timer);
  }, [onClose]);

  return (
    <div
      className={`fixed overflow-hidden bottom-5 right-5 rounded-lg shadow-lg text-white text-sm flex flex-col gap-3 justify-between ${
        type === "success" ? "bg-green-800" : "bg-red-800"
      }`}
    >
      <div className="flex px-4 pt-4 pb-0 gap-4 justify-between items-center font-bold">
        <span>{message}</span>
        <button
          onClick={onClose}
          className="text-white font-bold hover:text-gray-200 cursor-pointer"
        >
          &#x2715;
        </button>
      </div>
      <div className="w-full h-1">
        <div className="h-full bg-white animate-loadingBar"></div>
      </div>
    </div>
  );
}
