import { create } from "zustand";
import { devtools, persist } from "zustand/middleware";

// interface CardSettings {
//     daysSinceLast?: number;
//     rowType?: string;
// }

export interface Card {
	name: string;
	rowType: string;
	age: string;
	active: boolean;
}

interface CardStore {
	cards: Card[]; // Array of card objects
	addCard: (card: Card) => void;
	updateCard: (name: string, updatedCard: Partial<Card>) => void;
	removeCard: (name: string) => void;
}

export const useCardStore = create<CardStore>()(
	devtools(
		persist<CardStore>(
			(set) => ({
				cards: [],

				addCard: (card) => set((state) => ({ cards: [...state.cards, card] })),

				updateCard: (name, updatedCard) =>
					set((state) => ({
						cards: state.cards.map((card) =>
							card.name === name ? { ...card, ...updatedCard } : card,
						),
					})),

				removeCard: (name) =>
					set((state) => ({
						cards: state.cards.filter((card) => card.name !== name),
					})),
			}),
			{ name: "cards" },
		),
	),
);
