import { defineStore } from "pinia"; import type { Card } from "~/types/Card"; export const useCardStore = defineStore("cardStore", { state: () => ({ collections: [] as string[], cards: [] as Card[], }), actions: { async fetchCollections() { const { data: collections } = await useFetch("/api/collections"); this.collections = collections.value ?? []; }, async fetchCardsByCollection(collectionName: string) { const response = useFetch(`/api/cards/${collectionName}`); this.cards = response.data.value ?? []; }, removeCard(id: number) { const index = this.cards.findIndex((card) => card.id === id); if (index !== -1) { this.cards.splice(index, 1); } }, }, });