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, getHotlistName, getNPEDCategory } 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 hotlistName = getHotlistName(sighting?.metadata?.hotlistMatches); 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 cat = getNPEDCategory(sighting); const isNPEDHitA = cat === "A"; const isNPEDHitB = cat === "B"; const isNPEDHitC = cat === "C"; return ( <>

Sighting Details

{onDelete ? ( ) : ( )} {onDelete ? ( ) : ( )}
plate patch {hotlistName && (

Hotlist

{hotlistName ? hotlistName[0].replace(/\.csv$/i, "") : "-"}

)}
{isHotListHit && hotlistHit} {isNPEDHitA && hotlistHit} {isNPEDHitB && hotlistHit} {isNPEDHitC && hotlistHit}
overview patch
{onDelete ? ( ) : ( )} {onDelete ? ( ) : ( )}
); }; export default SightingModal;