import { defineStore } from 'pinia'; import { ref } from 'vue'; import http from '@/lib/http'; import HistoryData = App.Features.History.Data.HistoryData; export const useHistoryStore = defineStore('history', () => { const isLoading = ref(false); const error = ref(); const historyData = ref(); const selectedDate = ref(new Date().toISOString().split('T')[0]); async function fetchHistoryData(date: string) { isLoading.value = true; error.value = undefined; selectedDate.value = date; try { const { data } = await http.get('/api/history', { params: { date }, }); historyData.value = data; } catch (err: unknown) { const axiosError = err as { response?: { data?: { message?: string } }; }; error.value = axiosError.response?.data?.message || 'Kon prijshistorie niet ophalen'; } finally { isLoading.value = false; } } return { isLoading, error, historyData, selectedDate, fetchHistoryData, }; });