import type { Feature, FeatureCollection, LineString, MultiLineString, Point, } from "geojson"; export const useMresoStore = defineStore("mresoStore", { state: () => ({ routes: [] as Route[], lines: {} as FeatureCollection, clusters: {} as FeatureCollection, stops: {} as FeatureCollection, selectedRouteIds: [] as string[], selectedTrips: [] as Feature[], }), actions: { async fetchData(options: { signal?: AbortSignal } = {}) { [this.routes, this.lines, this.clusters, this.stops] = await Promise.all([ $fetch("/routes.json", options), $fetch>("/lines.json", options), // $fetch>( // "/trajets presque clean.geojson", // options, // ), $fetch>("/clusters.json", options), $fetch>("/stops.json", options), ]); }, }, getters: { routesById(state): { [id: string]: Route } { return Object.fromEntries(state.routes.map((r) => [r.id, r])); }, linesById(state): { [id: string]: Feature } { if (!("features" in state.lines)) { return {}; } return Object.fromEntries( state.lines.features.map((l) => [l.properties!.id, l]), ); }, clustersByCode(state): { [id: string]: Feature } { if (!("features" in state.clusters)) { return {}; } return Object.fromEntries( state.clusters.features.map((l) => [l.properties!.code, l]), ); }, }, });