import { NotificationResult, NotificationType, Notification } from "../../../shared/models/notification/notification.model"; import { motion, PanInfo } from "framer-motion"; import { BsmImage } from "../shared/bsm-image.component"; import BeatRunningImg from "../../../../assets/images/apngs/beat-running.png"; import BeatConflictImg from "../../../../assets/images/apngs/beat-conflict.png"; import BeatWaitingImg from "../../../../assets/images/apngs/beat-waiting.png"; import BeatImpatientImg from "../../../../assets/images/apngs/beat-impatient.png"; import { BsmButton } from "../shared/bsm-button.component"; import { useTranslation } from "renderer/hooks/use-translation.hook"; import { ForwardedRef, forwardRef } from "react"; export const NotificationItem = forwardRef(({ resolver, notification }: { resolver?: (value: NotificationResult | string) => void; notification: Notification }, fwdRef: ForwardedRef) => { const t = useTranslation(); const renderImage = (() => { if (notification.type === NotificationType.SUCCESS) { return BeatRunningImg; } if (notification.type === NotificationType.WARNING) { return BeatWaitingImg; } if (notification.type === NotificationType.INFO) { return BeatWaitingImg; } if (notification.type === NotificationType.ERROR) { return BeatConflictImg; } return BeatImpatientImg; })(); const renderNeonColors = (() => { if (notification.type === NotificationType.SUCCESS) { return "bg-green-400 shadow-green-400"; } if (notification.type === NotificationType.WARNING) { return "bg-yellow-400 shadow-yellow-400"; } if (notification.type === NotificationType.INFO) { return "bg-blue-500 shadow-blue-500"; } if (notification.type === NotificationType.ERROR) { return "bg-red-500 shadow-red-500"; } return "bg-gray-800 shadow-gray-800 dark:bg-white dark:shadow-white"; })(); const handleDragEnd = (e: MouseEvent, info: PanInfo) => { const offset = info.offset.x; const velocity = info.velocity.x; if (offset > 30 && velocity > 300) { resolver(NotificationResult.CLOSE); } }; return (

{t(notification.title)}

{notification.desc &&

{t(notification.desc)}

}
{notification.actions && (
{notification.actions.map(a => ( resolver(a.id)} className={`px-1 cursor-pointer flex-1 grow rounded-md text-center bg-blue-500 hover:brightness-110 transition-all text-gray-200 whitespace-nowrap m-[3px] ${a.cancel && "!bg-gray-500"}`}> {t(a.title)} ))}
)}
resolver(NotificationResult.CLOSE)} />
); });