2025-09-08 15:21:17 +01:00
|
|
|
import Card from "../UI/Card";
|
|
|
|
|
import CardHeader from "../UI/CardHeader";
|
2025-09-25 10:38:49 +01:00
|
|
|
import { useNPEDContext } from "../../context/NPEDUserContext";
|
2025-10-08 15:46:54 +01:00
|
|
|
import type { ReducedSightingType } from "../../types/types";
|
|
|
|
|
import { toast } from "sonner";
|
2025-09-08 15:21:17 +01:00
|
|
|
|
|
|
|
|
const SessionCard = () => {
|
2025-09-25 10:38:49 +01:00
|
|
|
const { sessionStarted, setSessionStarted, sessionList } = useNPEDContext();
|
|
|
|
|
|
|
|
|
|
const handleStartClick = () => {
|
|
|
|
|
setSessionStarted(!sessionStarted);
|
2025-10-08 15:46:54 +01:00
|
|
|
toast(
|
|
|
|
|
`${
|
|
|
|
|
sessionStarted
|
|
|
|
|
? "Vehicle tracking session Ended"
|
|
|
|
|
: "Vehicle tracking session Started"
|
|
|
|
|
}`
|
|
|
|
|
);
|
2025-09-25 10:38:49 +01:00
|
|
|
};
|
2025-09-16 14:20:38 +01:00
|
|
|
|
2025-10-08 15:46:54 +01:00
|
|
|
const sightings = [
|
|
|
|
|
...new Map(sessionList.map((vehicle) => [vehicle.vrm, vehicle])),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const dedupedSightings = sightings.map((sighting) => sighting[1]);
|
|
|
|
|
|
|
|
|
|
const vehicles = dedupedSightings.reduce<
|
|
|
|
|
Record<string, ReducedSightingType[]>
|
|
|
|
|
>(
|
|
|
|
|
(acc, item) => {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
npedCatA: [],
|
|
|
|
|
npedCatB: [],
|
|
|
|
|
npedCatC: [],
|
|
|
|
|
npedCatD: [],
|
|
|
|
|
notTaxed: [],
|
|
|
|
|
notMOT: [],
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-08 15:21:17 +01:00
|
|
|
return (
|
2025-09-26 13:58:14 +01:00
|
|
|
<Card className="p-4">
|
2025-09-16 14:20:38 +01:00
|
|
|
<CardHeader title="Session" />
|
2025-09-26 13:58:14 +01:00
|
|
|
<div className="flex flex-col gap-4 px-2">
|
2025-09-08 15:21:17 +01:00
|
|
|
<button
|
2025-10-08 15:46:54 +01:00
|
|
|
className={`${
|
|
|
|
|
sessionStarted ? "bg-red-600" : "bg-[#26B170]"
|
|
|
|
|
} text-white px-4 py-2 rounded ${
|
|
|
|
|
sessionStarted ? "hover:bg-red-700" : "hover:bg-green-700"
|
|
|
|
|
} transition w-full`}
|
2025-09-25 10:38:49 +01:00
|
|
|
onClick={handleStartClick}
|
2025-09-08 15:21:17 +01:00
|
|
|
>
|
2025-10-08 15:46:54 +01:00
|
|
|
{sessionStarted ? "End Session" : "Start Session"}
|
2025-09-08 15:21:17 +01:00
|
|
|
</button>
|
2025-09-16 14:20:38 +01:00
|
|
|
|
|
|
|
|
<ul className="text-white space-y-2">
|
2025-10-08 15:46:54 +01:00
|
|
|
<li>Number of Vehicles: {dedupedSightings.length} </li>
|
|
|
|
|
<li>Vehicles without Tax: {vehicles.notTaxed.length}</li>
|
|
|
|
|
<li>Vehicles without MOT: {vehicles.notMOT.length}</li>
|
|
|
|
|
<li>Vehicles with NPED Cat A: {vehicles.npedCatA.length}</li>
|
|
|
|
|
<li>Vehicles with NPED Cat B: {vehicles.npedCatB.length}</li>
|
|
|
|
|
<li>Vehicles with NPED Cat C: {vehicles.npedCatC.length}</li>
|
2025-09-16 14:20:38 +01:00
|
|
|
</ul>
|
2025-09-08 15:21:17 +01:00
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SessionCard;
|