import { useSession } from "next-auth/react"; import { usePilotConnectionStore } from "_store/pilot/connectionStore"; import { useMrtStore } from "_store/pilot/MrtStore"; import { editConnectedAircraftAPI } from "querys/aircrafts"; import { Station } from "@repo/db"; import { DisplayLineProps } from "pilot/_components/mrt/Mrt"; export const fmsStatusDescription: { [key: string]: string } = { NaN: "Keine Daten", "0": "Prio. Sprechwunsch", "1": "Frei auf Funk", "2": "Einsatzbereit am LRZ", "3": "Auf dem Weg", "4": "Am Einsatzort", "5": "Sprechwunsch", "6": "Nicht einsatzbereit", "7": "Patient aufgenommen", "8": "Am Transportziel", "9": "Fremdanmeldung", E: "Indent/Abbruch/Einsatzbefehl abgebrochen", C: "Anmelden zur Übernahme des Einsatzes", F: "Kommen über Draht", H: "Fahren auf Wache", J: "Sprechaufforderung", L: "Lagebericht abgeben", P: "Einsatz mit Polizei/Pause machen", U: "Ungültiger Status", c: "Status korrigieren", d: "Transportziel angeben", h: "Zielklinik verständigt", o: "Warten, alle Abfrageplätze belegt", u: "Verstanden", }; export const getSendingLines = (station: Station): DisplayLineProps[] => { return [ { textLeft: `VAR#.${station?.bosCallsign}123`, style: { fontWeight: "bold" }, textSize: "2", }, { textLeft: "ILS VAR#", textSize: "3" }, { textMid: "sending...", style: { fontWeight: "bold" }, textSize: "4", }, { textLeft: "Status wird gesendet...", textSize: "1", }, ]; }; export const getHomeLines = ( station: Station, fmsStatus: string, ): DisplayLineProps[] => { return [ { textLeft: `VAR#.${station?.bosCallsign}`, style: { fontWeight: "bold" }, textSize: "2", }, { textLeft: "ILS VAR#", textSize: "3" }, { textLeft: fmsStatus, style: { fontWeight: "extrabold" }, textSize: "4", }, { textLeft: fmsStatusDescription[fmsStatus], textSize: "1", }, ]; }; export const getNewStatusLines = ( station: Station, fmsStatus: string, ): DisplayLineProps[] => { return [ { textLeft: `VAR#.${station?.bosCallsign}`, style: { fontWeight: "bold" }, textSize: "2", }, { textLeft: "ILS VAR#", textSize: "3" }, { textLeft: fmsStatus, style: { fontWeight: "extrabold" }, textSize: "4", }, { textLeft: fmsStatusDescription[fmsStatus], textSize: "1", }, ]; }; export const useButtons = () => { const user = useSession().data?.user; const station = usePilotConnectionStore((state) => state.selectedStation); const connectedAircraft = usePilotConnectionStore( (state) => state.connectedAircraft, ); const { page, setLines } = useMrtStore((state) => state); const handleButton = (button: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0") => () => { if (!station) return; if (!connectedAircraft?.id) return; if ( button === "1" || button === "2" || button === "3" || button === "4" || button === "5" || button === "6" || button === "7" || button === "8" || button === "9" || button === "0" ) { if (page !== "home") return; setLines(getSendingLines(station)); setTimeout(async () => { await editConnectedAircraftAPI(connectedAircraft!.id, { fmsStatus: button, }); setLines(getNewStatusLines(station, button)); }, 1000); } }; return { handleButton }; };