import { useCardStore } from "@/lib/store/useCardStore"; import { useForm } from "@tanstack/react-form"; import { Label } from "../ui/label"; import { Checkbox } from "../ui/checkbox"; import { Input } from "../ui/input"; // import { // Select, // SelectContent, // SelectGroup, // SelectItem, // SelectLabel, // SelectTrigger, // SelectValue, // } from "../ui/select"; import { Button } from "../ui/button"; export default function Cards(card: any) { const { addCard, removeCard, cards } = useCardStore(); let existing: any = cards.filter((n: any) => n.name === card.name); //console.log(existing); const form = useForm({ defaultValues: { name: existing[0]?.name || card.name, rowType: existing[0]?.type ?? card.rowType, age: existing[0]?.age ?? 90, active: existing[0]?.active ?? false, }, onSubmit: async ({ value }) => { console.log(value); const testCard: any = cards.filter( (i: any) => i.name === value.name ); if (value.active) { const newCard = { name: `${value.name}`, rowType: value.rowType, age: value.age ?? 90, active: value.active, }; if (testCard.length > 0) { removeCard(value.name); addCard(newCard); return; } // change the name for a type card addCard(newCard); } else { removeCard(value.name); } }, }); return (
{card.name}