2025-09-16 11:07:35 +01:00
|
|
|
import type { SightingType } from "../../types/types";
|
|
|
|
|
import NumberPlate from "../PlateStack/NumberPlate";
|
|
|
|
|
import SightingModal from "../SightingModal/SightingModal";
|
|
|
|
|
import InfoBar from "../SightingsWidget/InfoBar";
|
|
|
|
|
import { useState } from "react";
|
2025-09-19 11:22:09 +01:00
|
|
|
import HotListImg from "/Hotlist_Hit.svg";
|
2025-09-23 16:02:14 +01:00
|
|
|
import { useAlertHitContext } from "../../context/AlertHitContext";
|
2025-10-13 11:48:10 +01:00
|
|
|
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
|
2025-09-23 16:02:14 +01:00
|
|
|
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";
|
2025-10-14 08:50:06 +01:00
|
|
|
import { checkIsHotListHit, getNPEDCategory } from "../../utils/utils";
|
2025-10-15 15:15:04 +01:00
|
|
|
import { faTrash } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2025-09-16 11:07:35 +01:00
|
|
|
|
|
|
|
|
type AlertItemProps = {
|
|
|
|
|
item: SightingType;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AlertItem = ({ item }: AlertItemProps) => {
|
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2025-10-07 15:58:16 +01:00
|
|
|
const { dispatch } = useAlertHitContext();
|
2025-10-13 11:48:10 +01:00
|
|
|
const { mutation } = useCameraBlackboard();
|
2025-09-25 10:38:49 +01:00
|
|
|
|
2025-09-24 12:28:14 +01:00
|
|
|
// const {d} = useCameraBlackboard();
|
2025-09-16 11:07:35 +01:00
|
|
|
const motionAway = (item?.motion ?? "").toUpperCase() === "AWAY";
|
2025-10-09 14:11:58 +01:00
|
|
|
|
|
|
|
|
const isHotListHit = checkIsHotListHit(item);
|
2025-10-14 08:50:06 +01:00
|
|
|
const cat = getNPEDCategory(item);
|
|
|
|
|
const isNPEDHitA = cat === "A";
|
|
|
|
|
const isNPEDHitB = cat === "B";
|
|
|
|
|
const isNPEDHitC = cat === "C";
|
2025-09-16 11:07:35 +01:00
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
|
setIsModalOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const closeModal = () => {
|
|
|
|
|
setIsModalOpen(false);
|
|
|
|
|
};
|
2025-09-23 16:02:14 +01:00
|
|
|
|
2025-10-13 11:48:10 +01:00
|
|
|
const handleDelete = async (deletedItem: SightingType | null) => {
|
|
|
|
|
const res = await mutation.mutateAsync({
|
|
|
|
|
operation: "VIEW",
|
|
|
|
|
path: "alertHistory",
|
|
|
|
|
});
|
|
|
|
|
const oldArray = res?.result;
|
2025-10-15 12:24:28 +01:00
|
|
|
const updatedArray = oldArray?.filter((item: SightingType) => item?.ref !== deletedItem?.ref);
|
2025-10-13 11:48:10 +01:00
|
|
|
|
|
|
|
|
mutation.mutate({
|
|
|
|
|
operation: "INSERT",
|
|
|
|
|
path: "alertHistory",
|
|
|
|
|
value: updatedArray,
|
|
|
|
|
});
|
2025-09-23 16:02:14 +01:00
|
|
|
dispatch({ type: "REMOVE", payload: item });
|
|
|
|
|
};
|
2025-09-16 11:07:35 +01:00
|
|
|
return (
|
2025-10-15 15:15:04 +01:00
|
|
|
<div className="flex flex-col w-full relative">
|
2025-10-13 11:48:10 +01:00
|
|
|
<div className="border border-gray-600 rounded-lg items-center py-1">
|
2025-09-23 16:02:14 +01:00
|
|
|
<InfoBar obj={item} />
|
2025-10-15 15:15:04 +01:00
|
|
|
<button onClick={() => handleDelete(item)} className="absolute right-2 top-1">
|
|
|
|
|
<FontAwesomeIcon icon={faTrash} size="xl" />
|
|
|
|
|
</button>
|
2025-10-15 12:24:28 +01:00
|
|
|
<div className="flex flex-row p-4 w-full mx-auto justify-between" onClick={handleClick}>
|
|
|
|
|
{isHotListHit && <img src={HotListImg} alt="hotlistHit" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitA && <img src={NPED_CAT_A} alt="NPEDHITicon" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitB && <img src={NPED_CAT_B} alt="NPEDHITicon" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
{isNPEDHitC && <img src={NPED_CAT_C} alt="NPEDHITicon" className="h-20 object-contain rounded-md" />}
|
|
|
|
|
<div className={`border p-1 hidden md:block`}>
|
|
|
|
|
<img src={item?.plateUrlColour} height={48} width={200} alt="colour patch" />
|
2025-09-23 16:02:14 +01:00
|
|
|
</div>
|
2025-10-15 15:15:04 +01:00
|
|
|
<div className="h-20">
|
|
|
|
|
<NumberPlate vrm={item.vrm} motion={motionAway} />
|
|
|
|
|
</div>
|
2025-09-23 16:02:14 +01:00
|
|
|
</div>
|
|
|
|
|
<SightingModal
|
|
|
|
|
isSightingModalOpen={isModalOpen}
|
|
|
|
|
handleClose={closeModal}
|
|
|
|
|
sighting={item}
|
|
|
|
|
onDelete={handleDelete}
|
|
|
|
|
/>
|
2025-09-16 11:07:35 +01:00
|
|
|
</div>
|
2025-09-23 16:02:14 +01:00
|
|
|
</div>
|
2025-09-16 11:07:35 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AlertItem;
|