import { create } from "zustand"; export interface Aircraft { id: string; bosName: string; bosNameShort: string; bosNutzung: string; fmsStatus: string; fmsLog: { status: string; timestamp: string; user: string; }[]; location: { lat: number; lon: number; altitude: number; speed: number; }; locationHistory: { lat: number; lon: number; altitude: number; speed: number; timestamp: string; }[]; } interface AircraftStore { aircrafts: Aircraft[]; setAircrafts: (aircrafts: Aircraft[]) => void; setAircraft: (aircraft: Aircraft) => void; } export const useAircraftsStore = create((set) => ({ aircrafts: [ { id: "1", bosName: "Christoph 31", bosNameShort: "CHX31", bosNutzung: "RTH", fmsStatus: "1", fmsLog: [], location: { lat: 52.546781040592776, lon: 13.369535209542219, altitude: 0, speed: 0, }, locationHistory: [], }, { id: "2", bosName: "Christoph Berlin", bosNameShort: "CHX83", bosNutzung: "ITH", fmsStatus: "2", fmsLog: [], location: { lat: 52.54588546048977, lon: 13.46470691054384, altitude: 0, speed: 0, }, locationHistory: [], }, { id: "3", bosName: "Christoph 100", bosNameShort: "CHX100", bosNutzung: "RTH", fmsStatus: "7", fmsLog: [], location: { lat: 52.497519717230155, lon: 13.342040806552554, altitude: 0, speed: 0, }, locationHistory: [], }, { id: "4", bosName: "Christophorus 1", bosNameShort: "A4", bosNutzung: "RTH", fmsStatus: "6", fmsLog: [], location: { lat: 52.50175041192073, lon: 13.478628701227349, altitude: 0, speed: 0, }, locationHistory: [], }, ], setAircrafts: (aircrafts) => set({ aircrafts }), setAircraft: (aircraft) => set((state) => { const existingAircraftIndex = state.aircrafts.findIndex( (a) => a.id === aircraft.id, ); if (existingAircraftIndex !== -1) { const updatedAircrafts = [...state.aircrafts]; updatedAircrafts[existingAircraftIndex] = aircraft; return { aircrafts: updatedAircrafts }; } else { return { aircrafts: [...state.aircrafts, aircraft] }; } }), }));