import { faCheck, faTrash, faX } from "@fortawesome/free-solid-svg-icons"; import type { SightingType } from "../../types/types"; import NumberPlate from "../PlateStack/NumberPlate"; import ModalComponent from "../UI/ModalComponent"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useAlertHitContext } from "../../context/AlertHitContext"; import { toast, Toaster } from "sonner"; import { useCameraBlackboard } from "../../hooks/useCameraBlackboard"; import HotListImg from "/Hotlist_Hit.svg"; import NPED_CAT_A from "/NPED_Cat_A.svg"; import NPED_CAT_B from "/NPED_Cat_B.svg"; import NPED_CAT_C from "/NPED_Cat_C.svg"; import { checkIsHotListHit } from "../../utils/utils"; type SightingModalProps = { isSightingModalOpen: boolean; handleClose: () => void; sighting: SightingType | null; onDelete?: (deletedItem: SightingType | null) => void; }; const SightingModal = ({ isSightingModalOpen, handleClose, sighting, onDelete, }: SightingModalProps) => { const { dispatch } = useAlertHitContext(); const { query, mutation } = useCameraBlackboard(); const handleAcknowledgeButton = () => { try { if (!sighting) { toast.error("Cannot add sighting to alert list"); handleClose(); return; } if (!query.data.alertHistory) { mutation.mutate({ operation: "INSERT", path: "alertHistory", value: [sighting], }); } else { mutation.mutate({ operation: "APPEND", path: "alertHistory", value: sighting, }); toast.success("Sighting Successfully added to alert list"); } dispatch({ type: "ADD", payload: sighting }); handleClose(); } catch (error) { console.error(error); toast.error("Failed to add sighting to alert list"); handleClose(); } }; const handleDeleteClick = (deletedItem: SightingType | null) => { if (!onDelete) return; onDelete(deletedItem); handleClose(); toast.success("Sighting removed from alert list"); }; const motionAway = (sighting?.motion ?? "").toUpperCase() === "AWAY"; const isHotListHit = checkIsHotListHit(sighting); const isNPEDHitA = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "A"; const isNPEDHitB = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "B"; const isNPEDHitC = sighting?.metadata?.npedJSON?.["NPED CATEGORY"] === "C"; return ( <> Sighting Details {onDelete ? ( handleDeleteClick(sighting)} > Delete ) : ( Deny )} {onDelete ? ( Close ) : ( Accept )} {isHotListHit && ( )} {isNPEDHitA && ( )} {isNPEDHitB && ( )} {isNPEDHitC && ( )} {onDelete ? ( Close ) : ( Accept )} {onDelete ? ( handleDeleteClick(sighting)} > Delete ) : ( Deny )} > ); }; export default SightingModal;