import { defineStore } from "pinia";
import { areasApi } from "../api/modules/areas";
export const useAreasStore = defineStore("areas", {
state: () => ({
areas: [],
isLoading: false,
error: null,
}),
getters: {
areasById(state) {
return Object.fromEntries(state.areas.map((area) => [String(area.id), area]));
},
},
actions: {
async loadAreas() {
this.isLoading = true;
this.error = null;
const result = await areasApi.list();
this.isLoading = false;
if (!result.ok) {
this.error = result.error;
return result;
}
this.areas = result.data?.data?.areas || [];
return result;
},
},
});