import { defineStore } from "pinia"; /** Cart badge state; mirrors the (mock or live) cart item count. */ export const useCartStore = defineStore("mallCart", { state: () => ({ count: 0 }), actions: { async refresh(): Promise { const { $api } = useNuxtApp(); try { const cart = await $api.getCart(); this.count = cart.items.reduce((sum, i) => sum + i.qty, 0); } catch { this.count = 0; } }, setCount(n: number): void { this.count = n; }, }, });