import type { Station } from '@/apis';
import { NDM_STATION_STORE_ID } from '@/constants';
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';

export const useStationStore = defineStore(
  NDM_STATION_STORE_ID,
  () => {
    const stations = ref<Station[]>([]);
    const onlineStations = computed(() => {
      return stations.value.filter((station) => station.online);
    });

    const setStations = (newStations: Station[]) => {
      stations.value = newStations;
    };

    return {
      stations,
      onlineStations,

      setStations,
    };
  },
  {
    persistToIndexedDB: true,
  },
);
