import { defineStore } from 'pinia' import { ref } from 'vue' import { api } from '@/services/api' import type { CreditBill } from './accounts' export interface CategoryTotal { category_id: number | null category_name: string color: string total: number } export interface MonthEvolution { month: string income: number expenses: number saved: number } export interface RecentTransaction { id: number date: string description: string category_name: string amount: number type: 'income' | 'expense' } export interface PendingIncome { id: number name: string expected_amount: number day_of_month: number late: boolean } export interface PendingBillImport { id: number filename: string payment_date: string total: number created_at: string } export interface DashboardData { month: string total_income: number total_expenses: number savings_pct: number total_patrimony: number by_category: CategoryTotal[] monthly_evolution: MonthEvolution[] recent_transactions: RecentTransaction[] pending_recurring: number pending_income_recurrings: PendingIncome[] current_bills: CreditBill[] pending_bill_imports: PendingBillImport[] } export const useDashboardStore = defineStore('dashboard', () => { const data = ref(null) const loading = ref(false) const error = ref(null) async function fetch(month: string) { loading.value = true error.value = null try { data.value = await api.get(`/dashboard?month=${month}`) } catch (e: any) { error.value = e.message } finally { loading.value = false } } return { data, loading, error, fetch } })