import Card from "../UI/Card"; import CardHeader from "../UI/CardHeader"; import { useNPEDContext } from "../../context/NPEDUserContext"; import type { ReducedSightingType } from "../../types/types"; import { toast } from "sonner"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faFloppyDisk, faPause, faPlay, faStop } from "@fortawesome/free-solid-svg-icons"; const SessionCard = () => { const { sessionStarted, setSessionStarted, sessionList } = useNPEDContext(); const handleStartClick = () => { setSessionStarted(!sessionStarted); toast(`${sessionStarted ? "Vehicle tracking session Ended" : "Vehicle tracking session Started"}`); }; const handleSaveCick = () => { console.log("clicked"); }; const sightings = [...new Map(sessionList.map((vehicle) => [vehicle.vrm, vehicle]))]; const dedupedSightings = sightings.map((sighting) => sighting[1]); const vehicles = dedupedSightings.reduce>( (acc, item) => { const hotlisthit = Object.values(item.metadata?.hotlistMatches ?? {}).includes(true); if (item.metadata?.npedJSON["NPED CATEGORY"] === "A") acc.npedCatA.push(item); if (item.metadata?.npedJSON["NPED CATEGORY"] === "B") acc.npedCatB.push(item); if (item.metadata?.npedJSON["NPED CATEGORY"] === "C") acc.npedCatC.push(item); if (item.metadata?.npedJSON["NPED CATEGORY"] === "D") acc.npedCatD.push(item); if (item.metadata?.npedJSON["TAX STATUS"] === false) acc.notTaxed.push(item); if (item.metadata?.npedJSON["MOT STATUS"] === false) acc.notMOT.push(item); if (hotlisthit) acc.hotlistHit.push(item); return acc; }, { npedCatA: [], npedCatB: [], npedCatC: [], npedCatD: [], notTaxed: [], notMOT: [], hotlistHit: [], } ); return (
{sessionStarted && ( )} {sessionStarted && ( )}
  • Number of Vehicles sightings:

    {dedupedSightings.length}
  • Vehicles without Tax:

    {vehicles.notTaxed.length}
  • Vehicles without MOT:

    {" "} {vehicles.notMOT.length}
  • Vehicles on Hotlists:

    {" "} {vehicles.hotlistHit.length}
  • Vehicles with NPED Cat A:

    {vehicles.npedCatA.length}
  • Vehicles with NPED Cat B:

    {" "} {vehicles.npedCatB.length}
  • Vehicles with NPED Cat C:{" "} {vehicles.npedCatC.length}
); }; export default SessionCard;